Skip to content

[v1.12.4 -> v2.3.0] - Order of arguments for runtime.JsonMerge and runtime.JSONMerge are being flipped. #1762

@jamesdillon-pol

Description

@jamesdillon-pol

Hi there.

I'm working on a project where the team currently use the oapi-codegen@v1.12.4 command line tool, and we were looking into upgrading to the newest version v2.3.0.

The issue I'm having is that when any small change is made to the existing openapi yaml spec and we run the following command with oapi-codegen@v2.3.0:

oapi-codegen --config api/config.yaml ./api/openapi.yaml> ./api/v1/go/ServerConfig.gen.go

It generates hundreds of changes - most of them are benign but some are breaking changes.

The change that is causing issues is to do with converting any instance of the deprecated runtime.JsonMerge to the preferred runtime.JSONMerge. This should be a straightforward drop-in replacement, but for some reason the order of the arguments being supplied is flipped like so:

image

This change breaks some of our tests.

However, after I do a find and replace in ServerConfig.gen.go to change runtime.JSONMerge(t.union, b) to runtime.JSONMerge(b, t.union) the tests all pass. Obviously modifying the generated file isn't a solution, but it seems to pinpoint the fact that the issue is oapi-codegen reversing the order of the arguments to runtime.JSONMerge.

This is quite surprising to me, as the result of merging two JSON objects shouldn't depend on the order of the arguments.

I'm still actively looking into this, and when I've a bit more time available I'll supply steps to replicate from scratch.

Thanks loads!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions