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

Invalid OpenAPI doc for route parameter with pattern #286

Closed
antipooh opened this issue Dec 7, 2022 · 2 comments
Closed

Invalid OpenAPI doc for route parameter with pattern #286

antipooh opened this issue Dec 7, 2022 · 2 comments

Comments

@antipooh
Copy link
Contributor

antipooh commented Dec 7, 2022

Using route parameter with pattern, like @get("{uuid:image_id}") will generate the wrong parameter name image_id in openapi.json method description and Swagger make bad parameter substitutions on method request. If manualy replace image_id to uuid:image_id all work well.

@RobertoPrevato
Copy link
Member

RobertoPrevato commented Dec 10, 2022

Hi @antipooh
Thank you for your interest and taking the time to open an issue. However, judging by the description you wrote, that is the intended behavior.

Everything that appears before the ":" in route parameters definition is intended to be used as additional information on the expected format of the route to match. The parameter name must be indeed what appears after the ":".

Example, let's say that you define this route:

@get("/api/cats/{cat_id}")

In this case, the route matches any kind of ID, regardless of its format:

  • /api/cats/100
  • /api/cats/some-id
  • /api/cats/39a8ac6a-1adf-412a-a172-83ce8d2d7c3b

However, if you specify a route like this:

@get("/api/cats/{uuid:cat_id}")

You are instructing the framework to only match requests when the path contains a parameter matching the pattern of a UUID (also called GUID).

Therefore, it will only match requests like this one:

  • /api/cats/39a8ac6a-1adf-412a-a172-83ce8d2d7c3b

This feature is described here: https://www.neoteroi.dev/blacksheep/routing/#value-patterns

@RobertoPrevato
Copy link
Member

RobertoPrevato commented Dec 17, 2022

Fixed at a7b8f7a.

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