Skip to content

Should regexes in path params be automatically removed? #107

Description

@Wim-De-Clercq

Failing test here: https://github.com/Wim-De-Clercq/pyramid_openapi3/commit/e15ebc369197c5b2dc0523b153ff6bcab040b426

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions