-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix recursive SchemaObject in typescript 2
BREAKING CHANGE: SchemaObject codec was renamed to SchemaObjectCodec
- Loading branch information
1 parent
e95c7fd
commit 8ab9fc0
Showing
9 changed files
with
217 additions
and
118 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/language/typescript/2.0/serializers/__tests__/schema-object.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { assert, property } from 'fast-check'; | ||
import { $refArbitrary } from '../../../../../utils/__tests__/ref.spec'; | ||
import { | ||
getSerializedObjectType, | ||
getSerializedPropertyType, | ||
getSerializedRecursiveType, | ||
getSerializedRefType, | ||
} from '../../../common/data/serialized-type'; | ||
import { pipe } from 'fp-ts/lib/pipeable'; | ||
import { serializeSchemaObject } from '../schema-object'; | ||
import { SchemaObjectCodec } from '../../../../../schema/2.0/schema-object/schema-object'; | ||
import { right } from 'fp-ts/lib/Either'; | ||
import { either } from 'fp-ts'; | ||
import { reportIfFailed } from '../../../../../utils/io-ts'; | ||
|
||
describe('SchemaObject serializer', () => { | ||
describe('recursive', () => { | ||
it('level 1', () => { | ||
assert( | ||
property($refArbitrary, ref => { | ||
const schema = SchemaObjectCodec.decode({ | ||
type: 'object', | ||
required: ['recursive'], | ||
properties: { | ||
recursive: { | ||
$ref: ref.$ref, | ||
}, | ||
}, | ||
}); | ||
const expected = pipe( | ||
ref, | ||
getSerializedRefType(ref), | ||
getSerializedPropertyType('recursive', true), | ||
getSerializedObjectType(), | ||
getSerializedRecursiveType(ref, true), | ||
); | ||
const serialized = pipe( | ||
schema, | ||
reportIfFailed, | ||
either.chain(schema => serializeSchemaObject(ref, schema)), | ||
); | ||
expect(serialized).toEqual(right(expected)); | ||
}), | ||
); | ||
}); | ||
it('level 2', () => { | ||
assert( | ||
property($refArbitrary, ref => { | ||
const schema = SchemaObjectCodec.decode({ | ||
type: 'object', | ||
required: ['children'], | ||
properties: { | ||
children: { | ||
type: 'object', | ||
required: ['recursive'], | ||
properties: { | ||
recursive: { | ||
$ref: ref.$ref, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
const expected = pipe( | ||
ref, | ||
getSerializedRefType(ref), | ||
getSerializedPropertyType('recursive', true), | ||
getSerializedObjectType(), | ||
getSerializedPropertyType('children', true), | ||
getSerializedObjectType(), | ||
getSerializedRecursiveType(ref, true), | ||
); | ||
const serialized = pipe( | ||
schema, | ||
reportIfFailed, | ||
either.chain(schema => serializeSchemaObject(ref, schema)), | ||
); | ||
expect(serialized).toEqual(right(expected)); | ||
}), | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { Dictionary } from '../../utils/types'; | ||
import { SchemaObject } from './schema-object/schema-object'; | ||
import { SchemaObject, SchemaObjectCodec } from './schema-object/schema-object'; | ||
import { dictionary } from '../../utils/io-ts'; | ||
|
||
export interface DefinitionsObject extends Dictionary<SchemaObject> {} | ||
|
||
export const DefinitionsObject = dictionary(SchemaObject, 'DefinitionsObject'); | ||
export const DefinitionsObject = dictionary(SchemaObjectCodec, 'DefinitionsObject'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.