Skip to content

Support $ref with sibling keywords (OpenAPI 3.1)#12

Closed
nolannbiron wants to merge 5 commits intomainfrom
nolann/add-support-for-openapi-3.1-ref-siblings
Closed

Support $ref with sibling keywords (OpenAPI 3.1)#12
nolannbiron wants to merge 5 commits intomainfrom
nolann/add-support-for-openapi-3.1-ref-siblings

Conversation

@nolannbiron
Copy link
Copy Markdown
Member

In OpenAPI 3.1, $ref can have sibling keywords like maxLength, minLength, pattern, etc. Merge sibling constraints into the resolved schema so they are compiled into the generated validator.

In OpenAPI 3.1, $ref can have sibling keywords like maxLength, minLength,
pattern, etc. Merge sibling constraints into the resolved schema so they
are compiled into the generated validator.
@nolannbiron nolannbiron force-pushed the nolann/add-support-for-openapi-3.1-ref-siblings branch from c9581a2 to 98b0605 Compare March 24, 2026 14:07
@nolannbiron nolannbiron requested a review from gregberge March 24, 2026 14:49
Comment thread src/compileValueSchema.ts
Comment on lines +46 to +60
// 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 },
});
}
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants