Skip to content

Inconsistent YAML libraries #2502

Closed

Description

@vdobler

After updating oapi-codegen and the runtime with

go get -u github.com/oapi-codegen/runtime github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen
go: upgraded github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 => v0.0.0-20260623150633-6f1ed93922d1
go: upgraded github.com/getkin/kin-openapi v0.133.0 => v0.145.0
go: upgraded github.com/go-openapi/jsonpointer v0.21.0 => v1.0.0
go: added github.com/go-openapi/swag/jsonname v0.27.3
go: upgraded github.com/oapi-codegen/oapi-codegen/v2 v2.5.1 => v2.8.0
go: upgraded github.com/oapi-codegen/runtime v1.4.1 => v1.6.0
go: upgraded github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 => v0.1.1
go: upgraded github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 => v0.0.14
go: added github.com/santhosh-tekuri/jsonschema/v6 v6.0.2
go: upgraded github.com/speakeasy-api/jsonpath v0.6.0 => v0.6.3
go: added github.com/speakeasy-api/openapi v1.24.0
go: added go.yaml.in/yaml/v3 v3.0.5
go: added go.yaml.in/yaml/v4 v4.0.0-rc.6
go: upgraded golang.org/x/crypto v0.53.0 => v0.54.0
go: upgraded golang.org/x/mod v0.37.0 => v0.38.0
go: upgraded golang.org/x/net v0.56.0 => v0.57.0
go: upgraded golang.org/x/sys v0.46.0 => v0.47.0
go: upgraded golang.org/x/tools v0.47.0 => v0.48.0

running oapi-codegen failed:

go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config cfg.yaml ./openapi_v1.yaml
# github.com/vmware-labs/yaml-jsonpath/pkg/yamlpath
../../../../../pkg/mod/github.com/vmware-labs/[email protected]/pkg/yamlpath/path.go:29:9: cannot use p.f(node, root).ToArray() (value of type []*"go.yaml.in/yaml/v4".Node) as []*"gopkg.in/yaml.v3".Node value in return statement
../../../../../pkg/mod/github.com/vmware-labs/[email protected]/pkg/yamlpath/path.go:57:32: cannot use node (variable of type *"gopkg.in/yaml.v3".Node) as *"go.yaml.in/yaml/v4".Node value in argument to yit.FromNode
../../../../../pkg/mod/github.com/vmware-labs/[email protected]/pkg/yamlpath/path.go:70:33: cannot use node (variable of type *"gopkg.in/yaml.v3".Node) as *"go.yaml.in/yaml/v4".Node value in argument to yit.FromNode
../../../../../pkg/mod/github.com/vmware-labs/[email protected]/pkg/yamlpath/path.go:75:33: cannot use node (variable of type *"gopkg.in/yaml.v3".Node) as *"go.yaml.in/yaml/v4".Node value in argument to yit.FromNode
../../../../../pkg/mod/github.com/vmware-labs/[email protected]/pkg/yamlpath/path.go:80:33: cannot use node (variable of type *"gopkg.in/yaml.v3".Node) as *"go.yaml.in/yaml/v4".Node value in argument to yit.FromNode
../../../../../pkg/mod/github.com/vmware-labs/[email protected]/pkg/yamlpath/path.go:190:22: cannot use node (variable of type *"gopkg.in/yaml.v3".Node) as *"go.yaml.in/yaml/v4".Node value in argument to yit.FromNode
../../../../../pkg/mod/github.com/vmware-labs/[email protected]/pkg/yamlpath/path.go:200:25: cannot use a (variable of type *"go.yaml.in/yaml/v4".Node) as *"gopkg.in/yaml.v3".Node value in argument to p.f
../../../../../pkg/mod/github.com/vmware-labs/[email protected]/pkg/yamlpath/path.go:218:33: cannot use node.Content[i] (variable of type *"gopkg.in/yaml.v3".Node) as *"go.yaml.in/yaml/v4".Node value in argument to yit.FromNode
../../../../../pkg/mod/github.com/vmware-labs/[email protected]/pkg/yamlpath/path.go:236:37: cannot use node.Content[i] (variable of type *"gopkg.in/yaml.v3".Node) as *"go.yaml.in/yaml/v4".Node value in argument to yit.FromNode
../../../../../pkg/mod/github.com/vmware-labs/[email protected]/pkg/yamlpath/path.go:252:44: cannot use n (variable of type *"gopkg.in/yaml.v3".Node) as *"go.yaml.in/yaml/v4".Node value in argument to yit.FromNode
../../../../../pkg/mod/github.com/vmware-labs/[email protected]/pkg/yamlpath/path.go:252:44: too many errors
server/api.go:3: running "go": exit status 1

Here the relevant parts of go.mod (after go mod tidy):

go 1.26.4

tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen

require (
	github.com/oapi-codegen/runtime v1.4.1
)

require (
	github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
	github.com/getkin/kin-openapi v0.133.0 // indirect
	github.com/go-openapi/jsonpointer v0.21.0 // indirect
	github.com/go-openapi/swag v0.23.0 // indirect
	github.com/oapi-codegen/oapi-codegen/v2 v2.5.1 // indirect
	github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 // indirect
	github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect
	github.com/speakeasy-api/jsonpath v0.6.0 // indirect
	github.com/speakeasy-api/openapi-overlay v0.10.2 // indirect
	github.com/spiffe/go-spiffe/v2 v2.6.0 // indirect
	github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
	go.yaml.in/yaml/v2 v2.4.4 // indirect
	gopkg.in/yaml.v2 v2.4.0 // indirect
	gopkg.in/yaml.v3 v3.0.1 // indirect
)

Activity

  1. mromaszewicz commented on Aug 2, 2026

    @mromaszewicz
    Member

    He is using v2.8.0 of codegen with v1.6.0 of runtime. We hit this as well, since some of our indirect dependencies in the v0.x.x semver scheme break their API's from time to time, and we have to pin something else.

  2. mromaszewicz commented on Aug 2, 2026

    @mromaszewicz
    Member

    @vdobler , the problem here is go-yit, which is unstable. Please downgrade it:

    go get github.com/dprotaso/[email protected]
    

    There's a long import chain that leads to this conflict.

      oapi-codegen/v2/cmd/oapi-codegen
        → oapi-codegen/v2/pkg/util
          → speakeasy-api/openapi/overlay/loader
            → speakeasy-api/openapi/overlay
              → vmware-labs/yaml-jsonpath/pkg/yamlpath
                → dprotaso/go-yit          ← the one that got upgraded
    
  3. tiagocesar commented on Oct 8, 2026

    @tiagocesar

    Just to add to the above - if more people work in your codebase and there's a risk of them upgrading the dependency, add a replace clause to your go.mod file:

    // We are replacing github.com/dprotaso/go-yit with a specific commit to fix a type
    // incompatibility introduced when using oapi-codegen v2.8.0 with newer yaml dependencies.
    // Issue: cannot use p.f(node, root).ToArray() (value of type []*"go.yaml.in/yaml/v4".Node) as []*"gopkg.in/yaml.v3".Node value in return statement
    replace github.com/dprotaso/go-yit => github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936
    
  4. fastcat commented on Oct 29, 2026

    @fastcat

    In my case the problem is that github.com/speakeasy-api/openapi v1.26.0 took in a BREAKING CHANGE (🤦‍♂️) swapping the underlying yaml dep

    They did that, because the older yaml dep (which this repo uses) is unmaintained and is starting to get flagged by security scanners

  5. mromaszewicz commented on Oct 29, 2026

    @mromaszewicz
    Member

    I think it's time to update out Go version to 1.26 and bump up some of these deps. I'll take care of it in the next few days, and we can see about replacing the YAML library.

  6. mromaszewicz commented on Oct 30, 2026

    @mromaszewicz
    Member

    Even with go 1.26, we have issues with this go-yit library. I'd like to move to using this lib (https://github.com/theory/jsonpath) which does RFC compliant json path, but this breaks previous overlay API syntax. Maybe it's ok to update behavior here, since I think overlay usage is fringe, or maybe we can translate it for backward compatibility. Still looking into it.

    All these problems come from the overlay handling and using rotting old libs.

  7. mromaszewicz commented on Oct 30, 2026

    @mromaszewicz
    Member

    Ok, I've figured out what I will do.

    I'm going to remove overlay support from oapi-codegen, because it's not necessary, and most of the bugs we've had with this were due to overlaying and then re-serializing.

    For the next release (v2.9.0), we will vendor in the speakeasy modules that we need, so as not to break behavior suddenly, but i will document that the release after that is losing overlay support. Users should actually run github.com/speakeasy-api/openapi/cmd/openapi directly, and produce an overlaid spec, which we then ingest without overlaying. It simplifies everything, removes a bug vector, removes many modules from our dependencies. I will updtate all documentation and examples in the upcoming release to use speakeasy's tool directly and encourage that as good behavior.

  8. added
    notable changes
    and removed on Oct 30, 2026
  9. added this to the v2.10.0 milestone on Oct 30, 2026
  10. jamietanna commented on Oct 30, 2026

    @jamietanna
    Member

    @mromaszewicz you mean removing OpenAPI Overlay? No, we shouldn't remove that

    I don't agree that this is a good next step

    The UX of it all being within oapi-codegen is better than a separate step so we should look at what we can do to try and keep it in

  11. mromaszewicz commented on Oct 30, 2026

    @mromaszewicz
    Member

    I'm not sold on this, I'm thinking on options, and options which improve our stability.

    Why does OpenAPI overlay have to be built into our executable?

    You could do something like

    //go:generate github.com/speakeasy-api/openapi/cmd/ .... > overlaid.yaml
    //go:generate go tool run oapi-codegen ... overlaid.yaml
    

    The main reason I am considering replacing it, is that if you look at overlay bugs we've had in the past, a lot of them have to do with us running a portion of Speakeasy's code in-process and then re-marshaling the result to only unmarshal the YAML a second time for code generation. This path is somewhat fragile, and I was thinking how to avoid it.

    The secondary reason is this broken Go packaging stuff and unstable transitive dependencies. @tiagocesar's suggestion to use replace... won't work, because replace only affects our own module when we build it ourselves, it has no effect on a user's module imports. There's nothing we can pin for this to work properly.

    So, these are my options so far:

    1. Fork speakeasy-openapi and fix it (I don't want to maintain another thing). I'd inline go-yit into it, versus importing.
    2. Copy in the subset we use into oapi-codegen code, and fix it.
    3. Switch to a different way of doing overlays. I like https://github.com/theory/jsonpath because it's an implementation of an RFC, but the RFC syntax is different from what we have. I looked into making an adapter, and it's possible for most cases, but some things from yaml-jsonpath aren't expressible in RFC 9535
    4. Make the overlay functionality a separate executable. It's not a widely used feature from what I can tell, and it drags in quite a number of dependencies. I have a prototype of this, but then I noticed that the speakeasy openapi executable already supports exactly what we need, and it's less fragile because it writes the resultant YAML itself and doesn't have the $ref issues that we do. I actually like this option best, and it allows people to use RFC 9535 syntax, or yaml-jsonpath syntax, it's up to them! I prefer minimalism. A separate executable doesn't drag in dependencies, and this wouldn't break because we're not importing these transitively.

    Anyhow, I'm open to other possibilities. What are you thinking, @jamietanna?

  12. fastcat commented on Oct 30, 2026

    @fastcat

    As an overlay user, my main use case is inserting x-go-type all over the place into third party specs.

    I'd be happy to rewrite those overlays to use a different syntax, but removing the functionality would be rather frustrating, esp. since it'd just push the problematic transitive deps problem onto me and, from my perspective, not really fix the issue.

  13. mromaszewicz commented on Oct 31, 2026

    @mromaszewicz
    Member

    @fastcat , you wouldn't have the transitive deps problem at all, because using the speakeasy command line tool wouldn't pull in any.

    I'll try to figure out how to keep this stuff compiling properly, it's just problematic.

  14. fastcat commented on Oct 31, 2026

    @fastcat

    Yes if i used it through e.g. go install, but I like to manage tools like this via go tool these days, so that their dependencies are as visible and maintainable as my own. But that brings with it the issues of compatibility of dependencies between multiple tools, and between them and my own code 🫤

  15. mromaszewicz commented on Oct 31, 2026

    @mromaszewicz
    Member

    Yeah, I see your point.

    Ok, so what I will do is make a new overlay handler on top of theory/jsonpath. We don't need everything in Speakeasy's API. This new library supports RFC9535 syntax (and this is where Speakeasy is moving as well). I'll add a temporary syntax adapter that we'll maintain for a release or two to parse the old syntax, but the default behavior will be RFC9535.

  16. mromaszewicz commented on Oct 31, 2026

    @mromaszewicz
    Member

    Ok, we have a different implementation, and a different behavior by default, however, there's a compatibility mode for old syntax. Please see the README and commit description.

  17. added a commit that references this issue on Oct 31, 2026
    36ca5c6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    notable changes

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions