Skip to content
Closed
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
25 changes: 24 additions & 1 deletion src/compileValueSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,30 @@ export function compileValueSchema(
schema: OpenAPIValueSchema,
): namedTypes.Identifier {
if ('$ref' in schema) {
return compileValueSchema(compiler, compiler.resolveRef(schema));
const resolved = compiler.resolveRef(schema);
const { $ref, ...siblings } = schema;
if (Object.keys(siblings).length > 0) {
// Apply the siblings to the additionalProperties schema if it exists
if (resolved.type === 'object' && typeof resolved.additionalProperties === 'object') {
return compileValueSchema(compiler, {
...resolved,
additionalProperties: { ...resolved.additionalProperties, ...siblings },
});
}

// Apply the siblings to the items schema if it exists
if (resolved.type === 'array' && typeof resolved.items === 'object') {
return compileValueSchema(compiler, {
...resolved,
items: { ...resolved.items, ...siblings },
});
}
Comment on lines +46 to +60
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this? it looks like an odd case for the spec.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean adding the constraints to additionalProperties and items ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's valid in OpenAPI 3.1 also

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SamyPesse ok I see I thought the standard was $ref + siblings applies to items/additionalProperties since they're the descriptor for an object/array, closing the PR we don't need it


// Otherwise merge directly into the resolved schema
return compileValueSchema(compiler, { ...resolved, ...siblings });
}

return compileValueSchema(compiler, resolved);
}

if ('anyOf' in schema) {
Expand Down
Loading
Loading