Skip to content

Embedded spec sometimes omits schemas from external refs, race-like #1572

@mgabeler-lee-6rs

Description

@mgabeler-lee-6rs

I have a couple OAS specs in my app. One of them loads a schema from another spec file, using something like this:

components:
  specs:
    MyFoo:
      $ref: '../otherdir/otherspec.yaml#/components/schemas/Foo'

I have oapi-codegen configured thus:

package: mythingy
generate:
  models: true
  client: true
  gin-server: true
  embedded-spec: true
import-mapping:
  "../otherdir/otherspec.yaml": "mymodule/otherthingy"
output: generated.go

I added a CI step to verify the committed generated code was up to date, and started noticing random failures. In the failure cases, the schemas from the externally referenced spec were missing.

I was able to reproduce this locally by running a loop:

( set -x ; while go run github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -config oapi-codegen.yaml ./openapi.yaml ; do git diff --exit-code || break ; done )

This fails within 10 loops at most for me.

This looks a lot like #1055, but that was closed as "using an old version". I'm reproducing this with the latest release (v2.1.0).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingupstream

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions