You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
1.12.2 x-go-type extension and ref don't work together #863
I'm not sure if there is a specific reason for how it works at current, but what I would like to do is externally reference say the kubernetes API spec, but also provide the go type instead of generating it.
At current I'm referencing say v1.Taint in an object, but I also want to reference it's openapi spec so that its rendered in the swagger/openapi docs:
It seems to be impossible to use any extension fields with a reference
For example x-oapi-codegen-extra-tags together with a $ref, which would be really useful together with an ORM like bun.
// Child defines model for Child.typeChildstruct {
Id*int`json:"id,omitempty"`
}
// Parent defines model for Parent.typeParentstruct {
Child*Child`bun:"rel:has-one,join:child_id=id" json:"child,omitempty"`ChildId*int`json:"child_id,omitempty"`Id*int`json:"id,omitempty"`
}
Actual
// Child defines model for Child.typeChildstruct {
Id*int`json:"id,omitempty"`
}
// Parent defines model for Parent.typeParentstruct {
Child*Child`json:"child,omitempty"`ChildId*int`json:"child_id,omitempty"`Id*int`json:"id,omitempty"`
}
Reacted by Ryan Hartje, Nelo-T. Wallus, SimonAM, metinatakli and Philip Kristen
It seems support for sibling properties with $ref got added with openapi 3.1, which updated to JSON schema 2020-12, so i assume this won't get fixed until #373 is resolved.
cc @daveshanley sorry for the ping, but do you have any thoughts here as you've likely been thinking about this a bit more than me recently?
I'm considering that the way oapi-codegen (and tools generally should work) is that:
When using OpenAPI 3.0, $refs should not be allowed with siblings
And instead using the allOf workaround is best
When using OpenAPI 3.1 $refs can be used with siblings
However, this doesn't quite match up with how Vacuum (v0.12.0) reports that this is an ERROR in both 3.0 and 3.1 - do you think that we should never allow siblings with $refs?
@jamietanna
i personally think it should be possible with oapi-codegen to define additional tags with the ref because there are certain use cases as @vennekilde pointed out. Loading the spec sheet does not give me any errors with things besides the refs maybe i am missing here something but using allOf as workaround feels like a hack to me!
cc @daveshanley sorry for the ping, but do you have any thoughts here as you've likely been thinking about this a bit more than me recently?
I'm considering that the way oapi-codegen (and tools generally should work) is that:
When using OpenAPI 3.0, $refs should not be allowed with siblings
And instead using the allOf workaround is best
When using OpenAPI 3.1 $refs can be used with siblings
However, this doesn't quite match up with how Vacuum (v0.12.0) reports that this is an ERROR in both 3.0 and 3.1 - do you think that we should never allow siblings with $refs?
Activity
vennekilde commentedon Aug 30, 2023
It seems to be impossible to use any extension fields with a reference
For example
x-oapi-codegen-extra-tagstogether with a $ref, which would be really useful together with an ORM like bun.Example
Expected
Actual
vennekilde commentedon Aug 31, 2023
It seems support for sibling properties with $ref got added with openapi 3.1, which updated to JSON schema 2020-12, so i assume this won't get fixed until #373 is resolved.
tigerinus commentedon Mar 13, 2024
as a workaround:
jamietanna commentedon Apr 20, 2024
Apologies for the delay on getting back to you on this! Correct, this is due to
$refs not being allowed siblings.Interestingly,
vacuumshows that even with an OpenAPI 3.1 spec:This is still deemed invalid:
jamietanna commentedon Jan 28, 2025
THanks @paulmach for the PR! Just taking a look now
Re-reading Vacuum's finding: https://quobix.com/vacuum/rules/schemas/no-ref-siblings/
So it looks like OpenAPI 3.1 should no longer have this issue (but it does seem to in the example tested above)
jamietanna commentedon Jan 28, 2025
It's also possible to wrap it all in an
allOf:jamietanna commentedon Jan 28, 2025
cc @daveshanley sorry for the ping, but do you have any thoughts here as you've likely been thinking about this a bit more than me recently?
I'm considering that the way
oapi-codegen(and tools generally should work) is that:$refs should not be allowed with siblingsallOfworkaround is best$refs can be used with siblingsHowever, this doesn't quite match up with how Vacuum (
v0.12.0) reports that this is anERRORin both 3.0 and 3.1 - do you think that we should never allow siblings with$refs?Related: https://quobix.com/vacuum/rules/schemas/no-ref-siblings/
Xentox-Phil commentedon Mar 5, 2025
@jamietanna
i personally think it should be possible with oapi-codegen to define additional tags with the ref because there are certain use cases as @vennekilde pointed out. Loading the spec sheet does not give me any errors with things besides the refs maybe i am missing here something but using allOf as workaround feels like a hack to me!
daveshanley commentedon Mar 5, 2025
Hi Jamie,
vacuum was updated to allow approved siblings in 3.1. The latest version is
v0.16.3https://github.com/daveshanley/vacuum/blob/main/functions/openapi/oas_no_ref_siblings.go
You can see that 'summary' and 'description' are allowed siblings, but everything else is still a no-go. including extensions.
mromaszewicz commentedon Apr 25, 2026
This was fixed in #1880