Skip to content

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

Closed
@Kashugoyal

Description

@Kashugoyal
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.

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