Skip to content

Commit 1f474f1

Browse files
committed
fix(parser-3.1.x): prevent [key: string]: never in allOf with additionalProperties: false
Applies same fix as 2.0.x/3.0.x parsers - detects empty objects with additionalProperties: false inside allOf compositions and skips never index signature generation. Completes the fix implementation across all three OpenAPI specification parser versions.
1 parent 7060cbd commit 1f474f1

File tree

1 file changed

+22
-4
lines changed
  • packages/openapi-ts/src/openApi/3.1.x/parser

1 file changed

+22
-4
lines changed

packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,18 @@ const parseObject = ({
286286
};
287287
}
288288
} else if (typeof schema.additionalProperties === 'boolean') {
289-
irSchema.additionalProperties = {
290-
type: schema.additionalProperties ? 'unknown' : 'never',
291-
};
289+
// Avoid [key: string]: never for empty objects with additionalProperties: false inside allOf
290+
// This would override inherited properties from other schemas in the composition
291+
const isEmptyObjectInAllOf =
292+
state.inAllOf &&
293+
schema.additionalProperties === false &&
294+
(!schema.properties || Object.keys(schema.properties).length === 0);
295+
296+
if (!isEmptyObjectInAllOf) {
297+
irSchema.additionalProperties = {
298+
type: schema.additionalProperties ? 'unknown' : 'never',
299+
};
300+
}
292301
} else {
293302
const irAdditionalPropertiesSchema = schemaToIrSchema({
294303
context,
@@ -357,10 +366,19 @@ const parseAllOf = ({
357366
const compositionSchemas = schema.allOf;
358367

359368
for (const compositionSchema of compositionSchemas) {
369+
// Don't propagate inAllOf flag to $ref schemas to avoid issues with reusable components
370+
const isRef = '$ref' in compositionSchema;
371+
const schemaState = isRef
372+
? state
373+
: {
374+
...state,
375+
inAllOf: true,
376+
};
377+
360378
const irCompositionSchema = schemaToIrSchema({
361379
context,
362380
schema: compositionSchema,
363-
state,
381+
state: schemaState,
364382
});
365383

366384
if (

0 commit comments

Comments
 (0)