kin-openapi icon indicating copy to clipboard operation
kin-openapi copied to clipboard

v3: allow extensions next to $ref in SchemaRef

Open paulmach opened this issue 1 year ago • 3 comments

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.

paulmach avatar Jan 29 '24 01:01 paulmach

Oh my, thanks for noticing and reporting! This is definitely a bug / not wanted! Looking forward to your PR.

fenollp avatar Jan 29 '24 09:01 fenollp

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

paulmach avatar Jan 30 '24 00:01 paulmach

I have verified that https://github.com/getkin/kin-openapi/pull/901 adds the support needed to fix my use-case in oapi-codegen

paulmach avatar Feb 01 '24 18:02 paulmach