diff --git a/src/validator.ts b/src/validator.ts index 69fb390d..d330ef67 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -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' }) diff --git a/test/__snapshots__/test/test.ts.md b/test/__snapshots__/test/test.ts.md index 0d8b981b..c08ae578 100644 --- a/test/__snapshots__/test/test.ts.md +++ b/test/__snapshots__/test/test.ts.md @@ -863,6 +863,7 @@ Generated by [AVA](https://avajs.dev). */␊ lastName?: string;␊ description?: string;␊ + deprecated?: boolean;␊ }␊ ` diff --git a/test/__snapshots__/test/test.ts.snap b/test/__snapshots__/test/test.ts.snap index 79cd4741..c61a6116 100644 Binary files a/test/__snapshots__/test/test.ts.snap and b/test/__snapshots__/test/test.ts.snap differ diff --git a/test/e2e/deprecated.ts b/test/e2e/deprecated.ts index 6d8716f4..5e24999e 100644 --- a/test/e2e/deprecated.ts +++ b/test/e2e/deprecated.ts @@ -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'],