oapi-codegen
oapi-codegen copied to clipboard
Fix bug in oneOf not propagating external references
This PR fixes a bug in not properly propagating external references when merging schemas of allOf.
If oneOf is used with a type with external reference that itself has a local reference, the generated struct does not have the external reference.
Repro:
schemas:
ContainerAny:
allOf:
- $ref: "sub.yaml#/components/schemas/Inner"
- type: object
properties:
Outer:
type: string
inner.yaml:
components:
schemas:
DeepInner:
type: object
properties:
DeepInner1:
type: string
Inner:
type: object
properties:
Inner1:
type: string
Inner2:
$ref: "#/components/schemas/DeepInner"
Generated code with external references not propagated:
// ContainerAny defines model for ContainerAny.
type ContainerAny struct {
Inner1 *string `json:"Inner1,omitempty"`
// this is incorrect as it is missing the package reference
Inner2 *DeepInner `json:"Inner2,omitempty"`
Outer *string `json:"Outer,omitempty"`
}
With fix:
// ContainerAny defines model for ContainerAny.
type ContainerAny struct {
Inner1 *string `json:"Inner1,omitempty"`
Inner2 *externalRef0.DeepInner `json:"Inner2,omitempty"`
Outer *string `json:"Outer,omitempty"`
}