Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in oneOf not propagating external references #729

Merged
merged 1 commit into from Oct 27, 2022

Conversation

technicianted
Copy link
Contributor

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"`
}

@deepmap-marcinr deepmap-marcinr merged commit cf23455 into deepmap:master Oct 27, 2022
adrianpk pushed a commit to foorester/oapi-codegen that referenced this pull request Jan 16, 2024
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.

None yet

2 participants