Skip to content
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

Treats trailing slashes differently for swagger and normal endpoints #1884

Open
chbndrhnns opened this issue Feb 16, 2024 · 2 comments
Open
Labels
PR welcome We would welcome and review a PR addressing this issue

Comments

@chbndrhnns
Copy link

Description

  • For swagger, a call to /ui returns a redirect and a call to /ui/ returns the swagger page
  • For other endpoints, a call to /bla returns the content and a call to /bla/ returns a redirect

Expected behaviour

Consistent (and configurable) behaviour

Actual behaviour

Inconsistent

Steps to reproduce

import httpx
import pytest
from connexion import AsyncApp

spec = {
    "openapi": "3.0.0",
    "info": {
        "title": "test",
        "version": "v1"
    },
    "paths": {
        "/hello": {
            "get": {
                "operationId": "test_.hello",
                "responses": {
                    "200": {
                        "description": "ok",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}


async def hello():
    return {}


app = AsyncApp(__name__)
app.add_api(spec)


@pytest.fixture(autouse=True)
def anyio_backend():
    return "asyncio"


@pytest.mark.parametrize(
    "url",
    [
        "/hello",
        "/hello/",
        "/ui",
        "/ui/",
    ],
)
async def test_run(url):
    async with httpx.AsyncClient(app=app, base_url="http://localhost") as client:
        res = await client.get(url)

    assert res.status_code == 200

Additional info:

Output of the commands:

  • Python 3.9.16
  • connexion 3.0.5
@RobbeSneyders
Copy link
Member

Thanks @chbndrhnns,

Not sure if this is inconsistent.

If you change your example spec to (note the trailing slash after hello):

    "paths": {
        "/hello/": {
            "get": {

You get the same behaviour as the UI.

I guess we could remove these two lines though so we use the raw path for the UI, which is configurable by the user:

console_ui_path + "/",

@RobbeSneyders RobbeSneyders added the PR welcome We would welcome and review a PR addressing this issue label Feb 17, 2024
@chbndrhnns
Copy link
Author

Thanks, you are right about the solution.

there is a discussion about this on starlette side. I would want this to be configurable on. Objection side, as well.
However, using a middleware to make it work might also be a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR welcome We would welcome and review a PR addressing this issue
Projects
None yet
Development

No branches or pull requests

2 participants