From f04c47180ba3bbe6dc715fef55d07208af2723f2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 24 Oct 2026 09:49:51 +0000 Subject: [PATCH] test(downgrader): cover rejectsNull and null branch checks in 3.1 to 3.0 nullable merge Stryker left these checks from #87/#88 untested: a `$ref` to a `type: "null"` target or an array `type`, a typed branch with `oneOf`, and a null branch with extra keys. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01KnRgKQZ6Maz5HiVMYr9twz --- packages/downgrader/tests/v3.1-to-v3.0.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/downgrader/tests/v3.1-to-v3.0.test.ts b/packages/downgrader/tests/v3.1-to-v3.0.test.ts index 7185a90..c895db6 100644 --- a/packages/downgrader/tests/v3.1-to-v3.0.test.ts +++ b/packages/downgrader/tests/v3.1-to-v3.0.test.ts @@ -500,6 +500,7 @@ describe('downgradeSchemaV31ToV30', () => { { type: 'string', enum: ['a', 'b'] }, { type: 'object', allOf: [{ required: ['a'] }] }, { type: 'integer', not: { const: 0 } }, + { type: 'string', oneOf: [{ minLength: 1 }, { maxLength: 0 }] }, ] for (const branch of typed) { expect(downgradeSchemaV31ToV30({ anyOf: [branch, { type: 'null' }] })).toEqual({ @@ -536,6 +537,12 @@ describe('downgradeSchemaV31ToV30', () => { anyOf: [{ type: 'string' }, { type: 'null' }, { type: 'null' }], }), ).toEqual({ anyOf: [{ type: 'string' }, onlyNull, onlyNull] }) + // A null branch with more than its type is not only null. + expect( + downgradeSchemaV31ToV30({ + anyOf: [{ type: 'object' }, { type: 'null', description: 'd' }], + }), + ).toEqual({ anyOf: [{ type: 'object' }, { ...onlyNull, description: 'd' }] }) }) it('makes an anyOf of a $ref and null a oneOf when the target rejects null', () => { @@ -552,9 +559,15 @@ describe('downgradeSchemaV31ToV30', () => { expect(pet({ type: 'object' })).toEqual({ oneOf: [{ $ref: '#/components/schemas/Pet' }, onlyNull], }) + expect(pet({ type: ['object', 'string'] })).toEqual({ + oneOf: [{ $ref: '#/components/schemas/Pet' }, onlyNull], + }) expect(pet({ type: ['object', 'null'] })).toEqual({ anyOf: [{ $ref: '#/components/schemas/Pet' }, onlyNull], }) + expect(pet({ type: 'null' })).toEqual({ + anyOf: [{ $ref: '#/components/schemas/Pet' }, onlyNull], + }) expect(pet({ type: 'object', nullable: true } as OpenAPIV3_1.SchemaObject)).toEqual({ anyOf: [{ $ref: '#/components/schemas/Pet' }, onlyNull], })