Skip to content

Commit 7975181

Browse files
ghdoergelohclaude
andcommitted
fix(openapi): suppress application/json entry when all non-file schema branches are empty
When a schema union has file branches (e.g. contentMediaType: application/zip) and all remaining branches resolve to nothing (empty anyOf/oneOf), the generator was emitting a spurious 'application/json: { schema: { anyOf: [] } }' entry. Skip the application/json content entry when the rest schema is empty. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 03c5dff commit 7975181

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

packages/openapi/src/openapi-utils.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ describe('toOpenAPIContent', () => {
6969
})
7070
})
7171

72+
it('omits application/json when all non-file branches resolve to false (not: {})', () => {
73+
expect(toOpenAPIContent({
74+
anyOf: [
75+
fileSchema,
76+
false,
77+
],
78+
})).toEqual({
79+
'image/png': {
80+
schema: fileSchema,
81+
},
82+
})
83+
})
84+
7285
it('body contain file schema', () => {
7386
const schema: JSONSchema = {
7487
type: 'object',

packages/openapi/src/openapi-utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ export function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPI.Med
3333
}
3434
}
3535

36-
if (restSchema !== undefined) {
36+
const isEmptyRest = restSchema === false
37+
|| (isObject(restSchema) && (
38+
(Array.isArray(restSchema.anyOf) && restSchema.anyOf.length === 0)
39+
|| (Array.isArray(restSchema.oneOf) && restSchema.oneOf.length === 0)
40+
))
41+
42+
if (restSchema !== undefined && !isEmptyRest) {
3743
content['application/json'] = {
3844
schema: toOpenAPISchema(restSchema),
3945
}

0 commit comments

Comments
 (0)