Skip to content

Commit f6ed6a1

Browse files
committed
fix: correct wrong behavior of the key property named deprecated (#626)
1 parent a5834aa commit f6ed6a1

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed

src/validator.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ rules.set('When minItems exists, minItems >= 0', schema => {
3939

4040
rules.set('deprecated must be a boolean', schema => {
4141
const typeOfDeprecated = typeof schema.deprecated
42+
if (schema.properties && 'deprecated' in schema.properties) {
43+
return true
44+
}
4245
return typeOfDeprecated === 'boolean' || typeOfDeprecated === 'undefined'
4346
})
4447

test/__snapshots__/test/test.ts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ Generated by [AVA](https://avajs.dev).
863863
*/␊
864864
lastName?: string;␊
865865
description?: string;␊
866+
deprecated?: boolean;␊
866867
}␊
867868
`
868869

test/__snapshots__/test/test.ts.snap

6 Bytes
Binary file not shown.

test/e2e/deprecated.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export const input = {
2424
description: {
2525
type: 'string',
2626
},
27+
// https://github.com/bcherny/json-schema-to-typescript/issues/626
28+
deprecated: {
29+
default: false,
30+
type: 'boolean',
31+
},
2732
},
2833
additionalProperties: false,
2934
required: ['firstName'],

0 commit comments

Comments
 (0)