Skip to content

support distinct routes for methods #169

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mzihlmann
Copy link

@mzihlmann mzihlmann commented May 22, 2025

I would like to add support for endpoints like this

@app.put("/user")
@app.route("/user/<user>")
def user(user = None):
    """user endpoint.

    ---
    get:
        description: get user details
        responses:
            200:
                description: a user to be returned
    put:
        description: create a user
        responses:
            200:
                description: some data
    """
    pass

that define different paths on top of the same handler. Currently this would result in wrong spec like this:

{
  "paths": {
    "/user/{user}": {
      "get": {
        "description": "get user details",
        "responses": {
          "200": {
            "description": "a user to be returned"
          }
        }
      },
      "put": {
        "description": "create a user",
        "responses": {
          "200": {
            "description": "some data"
          }
        }
      }
    }
  }
}

note that all methods get attributed to whatever path comes in last.

with this change we can render the correct data

{
  "paths": {
    "/user/{user}": {
      "get": {
        "description": "get user details",
        "responses": {
          "200": {
            "description": "a user to be returned"
          }
        }
      }
    },
    "/user": {
      "put": {
        "description": "create a user",
        "responses": {
          "200": {
            "description": "some data"
          }
        }
      }
    }
  }
}

note that for this to work, users must adapt the way they call into the library a bit.

- spec.path(view=view)
+ spec.path(rule=rule)

as based on the handler function alone we cannot deduce what path, and hence which methods, matched.

without this change users can circumvent this issue by splitting their handler functions up, s.t. we have a 1:1 mapping between endpoints and handlers.

please excuse the a bit nonsensical example.

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

Successfully merging this pull request may close these issues.

1 participant