Skip to content

fix: correct wrong behavior of the key property named deprecated (#626) #651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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