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

No mapping for HTTP-method #63

Open
EDDragonWolf opened this issue May 5, 2022 · 3 comments
Open

No mapping for HTTP-method #63

EDDragonWolf opened this issue May 5, 2022 · 3 comments

Comments

@EDDragonWolf
Copy link
Contributor

Hi. I'm continuing to investigate the Swagger integration and found as I think a bug with endpoint mapping but I'm not sure if it's the right scope to discuss it.

I added the following code:

  • The relative base path for the API in the SwaggerComponent:
...
        builder.setTitle("My API")
...
            .addServer("/api/v2.0", "API version 2.0 base URL");
        return builder.build();
...
  • The test endpoint:
ENDPOINT("GET", "test", test)
...

As result, my endpoint is available by the path http://127.0.0.1:8000/test.
But when I try to make a request from the Swagger UI, it's sent to the http://127.0.0.1:8000/api/v2.0/test and returns the following error:

{
  "error": "No mapping for HTTP-method: 'GET', URL: '/api/v2.0/test'",
  "success": false
}

If I change the definition of my endpoint to ENDPOINT("GET", "/api/v2.0/test", test), it doesn't help since Swagger UI tries to send a request to http://127.0.0.1:8000/api/v2.0/api/v2.0/test.

So my API server works, but Swagger UI is broken.

Is it possible to add proper mapping to my API Controller? So my endpoint will use the test path but will be accessible by the api/v2/0/test path.

@EDDragonWolf
Copy link
Contributor Author

Hi. I'm not sure if you had a chance to look at this issue.
I have tried to solve it from my side. Please take a look at this commit EDDragonWolf/oatpp@45180e8.

In short, I have added the possibility to register endpoints with a specific base path. So in the definition, the endpoint is still defined as ENDPOINT("GET", "test", test), but when I'm adding it to the router, I can do next:

docEndpoints.append(router->addController(controller, "/api/v2.0")->getEndpoints());

If you think it's a good solution, I can prepare PR. Or could you propose a better solution?

@lganzzzo
Copy link
Member

Hello @EDDragonWolf ,

Thank you for your question.

I see this issue as follows:

  • This issue concerns the way oatpp-swagger interprets the base path (servers)
  • This is not the issue of the main oatpp.

The solution to this issue I believe should be fixing oatpp-swagger module, so that it can understand the "servers" parameter correctly removing the base-path part from the endpoint description in swagger-ui

Regards,
Leonid

@EDDragonWolf
Copy link
Contributor Author

Hello @lganzzzo,

You are right, it isn't exactly an issue of the main module, but from my point of view, it's a flexible way to handle the multiple servers. It allows registering the same ApiController for each supported base path explicitly.

Removing the base-path part from the endpoint declaration will work only for one server. To support multiple servers, you will need to declare the same endpoint several times. For example:

ENDPOINT("GET", "/staging/test", test_staging)
ENDPOINT("GET", "/dev/test", test_dev)

Or maybe I understood your idea wrong?

I think the base path should be provided dynamically during the registration.

With my changes, I also fixed another issue - the possibility of hosting a separate Swagger UI page for each version.

I hope you'll consider my thoughts and fix this issue.

Regards,
Vitalius

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