kin-openapi
kin-openapi copied to clipboard
v3: allow extensions next to $ref in SchemaRef
I would like to extent SchemaRef to have a Extensions or RefExtensions to capture extensions next to $ref.
For example, if I have:
type: object
properties:
id:
$ref: "#/components/schemas/id"
x-order: 1
name:
type: string
I would like to capture the x-order: 1 within SchemaRef.Extensions["x-order"]
Looking at the code it looks like it's "if $ref only capture $ref"
I don't think the openapi v3 spec official supports this but it would be very helpful.
My use-case is specifying the x-order, a new feature added to oapi-codegen. For example:
type: object
properties:
start_port:
$ref: "#/components/schemas/port"
x-order: 0
end_port:
$ref: "#/components/schemas/port"
x-order: 1
It works if you specify the x-order in the referenced object, but in the above it needs to be context dependent. A change would need to be made to oapi-codegen but it looks to be blocked by this issue.
If this change is okay, I can work on the PR.
Oh my, thanks for noticing and reporting! This is definitely a bug / not wanted! Looking forward to your PR.
I created a pr to add Extension to SchemaRef. If this approach is agreed I can expand to all *Refs.
https://github.com/getkin/kin-openapi/pull/901
I have verified that https://github.com/getkin/kin-openapi/pull/901 adds the support needed to fix my use-case in oapi-codegen