Skip to content

[BUG] [GO] [go-server] Incorrect data type for routes definition #19445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Kashugoyal opened this issue Aug 25, 2024 · 1 comment · Fixed by #19550
Closed

[BUG] [GO] [go-server] Incorrect data type for routes definition #19445

Kashugoyal opened this issue Aug 25, 2024 · 1 comment · Fixed by #19550

Comments

@Kashugoyal
Copy link

Description

For routes defined as the following

getPost/latest
getPost/{postId}

and stored in a type defined as:

// Routes is a map of defined api endpoints
type Routes map[string]Route

Refer code here.

The api routes are registered with the router by iterating over the map and since native maps are unordered in golang, this leads to unexpected route ordering and breaks the above two routes (as they depend on route precedence for path matching).

openapi-generator version

Latest 7.9.0

OpenAPI declaration file content or url

Test api.yaml can be downloaded here

Generation Details

You can use any method of generation but I used the following:

npx @openapitools/openapi-generator-cli generate -i api.yaml -g go-server -o ./server
Steps to reproduce

Based on the Golang language spec here,
The iteration order over maps is not specified and is not guaranteed to be the same from one iteration to the next.

So reruns of the server may lead to different paths being matched if one was registered with the router first.

Related issues/PRs

Sounds similar but is not:
#14660

Suggest a fix

Use an ordered data type to store the routes such as a list.

@gcatanese
Copy link
Contributor

The problem is in the generator code when sorting the OpenAPI operations. Re-ordering the operations (routes) doesn't work for the Go Server generator, see #19550

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants