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

Nested types included by local $ref in external references are omitted from the swaggerSpec

Open marcparadise opened this issue 2 years ago • 4 comments

The generated swaggerSpec does not contain nested types when the nested type is defined in an external reference, and included there via $ref.

I have modified the externalref test to demonstrate it, which you can see here:

https://github.com/marcparadise/oapi-codegen/pull/1

It changes packageB/spec.yaml to look like:

components:
  schemas:
    ObjectB:
      properties:
        name:
          type: string
        nested:
          $ref: "#/components/schemas/ObjectC"
    ObjectC:
      properties:
        name:
          type: string

After go generate, running the externalref test results in:

- FAIL: TestGetSwagger (0.00s)
    imports_test.go:27:
                Error Trace:    /home/username/projects/oapi-codegen/internal/test/externalref/imports_test.go:27
                Error:          Expected nil, but got: &fmt.wrapError{msg:"failed to resolve \"ObjectC\" in fragment in URI: \"#/components/schemas/ObjectC\": map key \"ObjectC\" not found", err:(*errors.errorString)(0xc000277b90)}
                Test:           TestGetSwagger
FAIL

It's worth mentioning that in this example, a struct for ObjectC is also not generated. In my real-world issue that led to this, its equivalent is getting generated. I haven't explored this further yet, since this example correctly reproduces the symptom.

marcparadise avatar Nov 22 '22 18:11 marcparadise

Also met this issue. Very annoyng for me.

derfenix avatar Nov 23 '22 08:11 derfenix

Same here

valensto avatar Dec 04 '22 16:12 valensto

Looks the same as what I also met: https://github.com/deepmap/oapi-codegen/issues/860

tmartin-git avatar Dec 05 '22 09:12 tmartin-git

I have the same problem error generating code: error creating operation definitions: error describing global parameters for /{version}/account/{account_req_uuid}/asset/: error generating type for param (account_req_uuid): parameter 'account_req_uuid' has no schema or content with ref keyword

DanubioBlu avatar Jan 16 '23 11:01 DanubioBlu

Any updates or workarounds on this issue?

adabuleanu avatar Apr 12 '24 08:04 adabuleanu