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

Should regexes in path params be automatically removed? #107

Open
Wim-De-Clercq opened this issue Feb 3, 2021 · 2 comments
Open

Should regexes in path params be automatically removed? #107

Wim-De-Clercq opened this issue Feb 3, 2021 · 2 comments

Comments

@Wim-De-Clercq
Copy link
Contributor

Wim-De-Clercq commented Feb 3, 2021

Failing test here: Wim-De-Clercq@e15ebc3

We can't add the regex definitions in the openapi yaml because openapi doesn't support them. Neither is there really a need for this, because the Openapi schema works fine as it is in the test.

The problem is that to guarantee correct routing within pyramid we need to:
A. Either not use regexes in the path and rely on the order of the routes in pyramid. This isn't great and a bit prone to failure when the routes are included from other projects, or the routes are automatically added via scanning the @view_config (I think).
B. Do use regexes in the path. This guarantees correct routing, but doesn't currently work with pyramid_openapi3.

I think pyramid_openapi3 could simply remove the regex definitions similar to how it removes the prefixes at

def remove_prefixes(path):
path = f"/{path}" if not path.startswith("/") else path
for prefix in prefixes:
path = path.replace(prefix, "")
return path
paths = list(openapi_settings["spec"].paths.keys())
routes = [
remove_prefixes(route.path) for name, route in app.routes_mapper.routes.items()
]

Is this something you agree with?

@zupo
Copy link
Collaborator

zupo commented Feb 3, 2021

Should we instead raise an error in pyramid_openapi if we come up against a regex in view path? I'm a bit afraid of silently removing parts of the path, I prefer to be specific with an error saying "Hey, regex paths are not supported in OpenAPIv3 but you gave me a path with regex so I don't know what to do here, please fix".

@zupo
Copy link
Collaborator

zupo commented May 26, 2022

Hey @Wim-De-Clercq, do you have any further thoughts on this?

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

No branches or pull requests

2 participants