Skip to content

Wrong Patern is Generated for root path in OAS Spec for http.ServeMux #1952

Closed as duplicate

Description

@snoweuph

Using the root path /: directly in an OAS spec, results in the generator registering it with the literal "/" which is wrong.

It should instead be "/{$}"

This is because, the go http.ServeMux is interpreting trailing / as a wildcard match.

This means that:

  • / matches anything
  • /cake/ matches anything starting with /cake

The result is that you won't be able to add another handler for all unmatched requests and that the handler for /: will match any unmatched path

The Current Workaround, I'm using for this, is: /\x7B$\x7D: as the root path in my OAS spec.
go will convert these correctly at comp time.

Activity

  1. jamietanna commented on Apr 14, 2025

    @jamietanna
    Member

    Great spot, thanks for reporting! I've got a fix in #1953 for this

  2. snoweuph commented on Apr 14, 2025

    @snoweuph
    Author

    Great spot, thanks for reporting! I've got a fix in #1953 for this

    uhh wow, that was fast.

    Do you by any means know when the next release will be?

  3. jamietanna commented on Apr 14, 2025

    @jamietanna
    Member

    Unexpectedly fast, just happened to have some time to check it out 😁

    Via https://github.com/oapi-codegen/oapi-codegen?tab=readme-ov-file#pinning-to-commits pinning to the latest commit is the best option, the next release has been pending for a bit (fair few things in the queue to fix before we do another, but also limited time 🙃 so couple be a couple of months

  4. snoweuph commented on Apr 14, 2025

    @snoweuph
    Author

    Instead of Pinning to a dev version, I'm going to stay stable and instead for now use my small workaround.

    I prefer using stable versions, but good to know, when I should check in again for updating
    (I probably should start using Renovate xD)

  5. jamietanna commented on Apr 14, 2025

    @jamietanna
    Member

    I will note that we do keep the main branch stable, so it is good and OK for you to do so - and yes, Renovate can then update your digest pinning as new ones come out 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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