Skip to content
Merged
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
8 changes: 6 additions & 2 deletions packages/downgrader/src/v3.1-to-v3.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ function losesRestriction(
return !(
names === true ||
(isRecord(names) &&
Object.entries(names).every(([name, item]) => name === 'type' && item === 'string'))
Object.entries(names).every(
([name, item]) => item === undefined || (name === 'type' && item === 'string'),
))
)
}
case 'unevaluatedProperties':
Expand Down Expand Up @@ -486,7 +488,9 @@ function valueType(value: unknown): string | undefined {

function isMediaTypeOnly(value: unknown): boolean {
return (
isRecord(value) && Object.keys(value).length === 1 && typeof value.contentMediaType === 'string'
isRecord(value) &&
typeof value.contentMediaType === 'string' &&
Object.entries(value).every(([key, item]) => key === 'contentMediaType' || item === undefined)
)
}

Expand Down
17 changes: 17 additions & 0 deletions packages/downgrader/tests/v3.1-to-v3.0.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,23 @@ describe('unusual input', () => {
])
})

it('treats keys holding undefined as missing when deciding what to drop or loosen', () => {
expect(
downgradeSchemaV31ToV30({
type: 'string',
anyOf: [{ contentMediaType: 'image/png', description: undefined }],
}),
).toEqual({ type: 'string' })
expect(
downgradeSchemaV31ToV30({
oneOf: [
{ type: 'object', propertyNames: { type: 'string', description: undefined } },
{ type: 'string' },
],
}),
).toEqual({ oneOf: [{ type: 'object' }, { type: 'string' }] })
})

it('tolerates malformed input without throwing', () => {
const doc = {
openapi: '3.1.2',
Expand Down
Loading