Skip to content

Commit

Permalink
fix: correct wrong behavior of the key property named deprecated (bch…
Browse files Browse the repository at this point in the history
  • Loading branch information
BatLeDev committed Feb 11, 2025
1 parent a5834aa commit f6ed6a1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ rules.set('When minItems exists, minItems >= 0', schema => {

rules.set('deprecated must be a boolean', schema => {
const typeOfDeprecated = typeof schema.deprecated
if (schema.properties && 'deprecated' in schema.properties) {
return true
}
return typeOfDeprecated === 'boolean' || typeOfDeprecated === 'undefined'
})

Expand Down
1 change: 1 addition & 0 deletions test/__snapshots__/test/test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ Generated by [AVA](https://avajs.dev).
*/␊
lastName?: string;␊
description?: string;␊
deprecated?: boolean;␊
}␊
`

Expand Down
Binary file modified test/__snapshots__/test/test.ts.snap
Binary file not shown.
5 changes: 5 additions & 0 deletions test/e2e/deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export const input = {
description: {
type: 'string',
},
// https://github.com/bcherny/json-schema-to-typescript/issues/626
deprecated: {
default: false,
type: 'boolean',
},
},
additionalProperties: false,
required: ['firstName'],
Expand Down

0 comments on commit f6ed6a1

Please sign in to comment.