Skip to content

Compilation Error with kin-openapi v0.134.0 #2296

@Tiim

Description

@Tiim

oapi-codegen v2.6.0 fails to compile when used with kin-openapi v0.134.0 due to a type mismatch error.
The code generation step fails with a compilation error in pkg/codegen/schema.go.

Error Message

go generate ./...
# github.com/oapi-codegen/oapi-codegen/v2/pkg/codegen
../../../../go/pkg/mod/github.com/oapi-codegen/oapi-codegen/v2@v2.6.0/pkg/codegen/schema.go:909:13: invalid operation: v == element.Ref (mismatched types openapi3.MappingRef and string)
openapi/oapicodegen.go:8: running "go": exit status 1

Steps to Reproduce

  1. Create a project with go.mod that includes:
    require (
        github.com/getkin/kin-openapi v0.134.0
        github.com/oapi-codegen/oapi-codegen/v2 v2.6.0
    )
    tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen
  2. Create a oapicodegen.go file
    package main
    //go:generate go tool oapi-codegen -config config.yaml spec.yaml
  3. Run go generate ./..
  4. Observe compilation failure

Expected Behavior

Code generation should complete successfully, as it does with kin-openapi v0.133.0.

Actual Behavior

Compilation fails with type mismatch error. The error suggests that element.Ref changed from type string to openapi3.MappingRef in kin-openapi v0.134.0.

Root Cause

The relevant change in kin-openapi seems to be getkin/kin-openapi@88234d0#diff-e6fbba2cbdca4fd502561d14e4c33ea0080e789c48da5a68814fe196a00dc52aR14-R15

Merge Request: getkin/kin-openapi#1108

Workaround

Downgrade to kin-openapi v0.133.0:

go get github.com/getkin/kin-openapi@v0.133.0
go mod tidy

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions