sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.
https://sanic.dev
MIT License
18.11k stars 1.55k forks source link

The RESTful API has redundant path parameters #2910

Closed jsonvot closed 8 months ago

jsonvot commented 9 months ago

Is there an existing issue for this?

Describe the bug

The RESTful API of the post method should not have the last path argument appear

image

Code snippet

from sanic import Sanic
from sanic.blueprints import Blueprint
from sanic.request import Request
from sanic.response import json
from sanic.views import HTTPMethodView

app = Sanic(__name__)
app.config.update({
    'OAS_UI_DEFAULT': 'swagger'
})

class UserView(HTTPMethodView):
    middleware = []

    async def get(self, request: Request):
        return json({'code': 200})

    async def post(self, request: Request):
        return json({'code': 200})

    async def put(self, request: Request):
        return json({'code': 200})

    async def delete(self, request: Request):
        return json({'code': 200})

user_bp = Blueprint('user_bp')
user_bp.add_route(UserView.as_view(), '/api/user/<user_id:int>')

app.blueprint(user_bp)

Expected Behavior

No response

How do you run Sanic?

Sanic CLI

Operating System

Linux

Sanic Version

23.12.1

Additional context

No response

aldem commented 8 months ago

Just out of curiosity - why it is redundant?

POST method may have a path argument when we want to explicitly name a resource or to assign a specific id, in some cases it could be even mandatory.