Skip to content

stdhttp requires param names to be valid go identifiers #2278

Description

@cdevienne

As quoted from the net/http documentation (https://pkg.go.dev/net/http#hdr-Patterns-ServeMux):

A path can include wildcard segments of the form {NAME} or {NAME...}. For example, "/b/{bucket}/o/{objectname...}". The wildcard name must be a valid Go identifier. Wildcards must be full path segments: they must be preceded by a slash and followed by either a slash or the end of the string. For example, "/b_{bucket}" is not a valid pattern.

I have a case where the openapi definition uses path parameters names with dashes (for example: "addressing-identifier"), which are clearly not valid Go identifiers.

I did not check the other servers but would not be surprised if some were concerned.

Workaround

Rename the parameters in the definition file, which can be cumbersome, especially on imposed definitions that are often updated.

Expected solution

  • The code generation should rename the parameters when needed.

or

  • The generation should fail and suggest to switch to gorilla since it doesn't have the issue.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions