oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

External references are not propagated recursively when merging "allOf" fields

Open hego-fdc opened this issue 1 year ago • 4 comments

Consider these two specifications:

#a.yaml
openapi: 3.0.0                
components:
  schemas:
    Merged:
      allOf:
        - $ref: '#/components/schemas/Example'
        - $ref: 'b.yaml#/components/schemas/Merge'
    Example:
      type: object
      properties:
        a:
          type: string
        c:
          $ref: 'b.yaml#/components/schemas/Element'
#b.yaml
openapi: 3.0.0
components:
  schemas:
    Merge:
      type: object
      properties:
        b:
          type: array
          items:
            $ref: "#/components/schemas/Element"
    Element:
      type: object
      properties:
        c:
          type: string

As well as the following options:

package: example
generate:
  models: true
import-mapping:
  b.yaml: example.com/b
output-options:
  skip-prune: true

Running oapi-codegen/oapi-codegen -config options.yaml a.yaml results in the following type for Merged:

type Merged struct {
	A *string               `json:"a,omitempty"`
	B *[]Element            `json:"b,omitempty"`
	C *externalRef0.Element `json:"c,omitempty"`
}

Where B should be *[]externalRef0.Element instead.

hego-fdc avatar Nov 21 '24 13:11 hego-fdc

I've created a fix for it: https://github.com/oapi-codegen/oapi-codegen/pull/1842

hego-fdc avatar Nov 21 '24 14:11 hego-fdc

Can the PR please get a bump? Ran into this bug today and would love for it to get fixed.

felixjung avatar Jan 13 '25 20:01 felixjung

Also experiencing the same issue, can we please get a fix in?

jsongo21 avatar Feb 20 '25 01:02 jsongo21

Seems to be duplicate of https://github.com/oapi-codegen/oapi-codegen/issues/1202 and https://github.com/oapi-codegen/oapi-codegen/issues/632.

matoous avatar May 27 '25 08:05 matoous