2

I have deployed a web service using Connexion and OpenAPI 3.0. I run it locally for debugging testing, and deploy it to a production server subsequently.

I am struggling with how to specify the server URLs properly in the OpenAPI file. All works as expected when I specify this:

servers:
  - url: http://localhost:5000/basepath/v1

I can test it with a simple call:

curl -X POST "http://localhost:5000/basepath/v1/endpoint" -H "accept: application/json" -H "Content-Type: application/json" -d "..."

Same works on the production server:

curl -X POST "http://myserver.net/basepath/v1/endpoint" -H "accept: application/json" -H "Content-Type: application/json" -d "..."

However, I would like to specify the production server URL in order to make use of the full power of OpenAPI (e.g. the UI to generate cURL calls). So I add another url:

servers:
  - url: http://localhost:5000/basepath/v1
  - url: http://myserver.net/basepath/v1

When I call the service, however, the endpoint is no longer found on the production server:

curl -X POST "http://myserver.net/basepath/v1/endpoint" -H "accept: application/json" -H "Content-Type: application/json" -d "..."
{
  "detail": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.",
  "status": 404,
  "title": "Not Found",
  "type": "about:blank"
}

I have verified so many times to make sure the calls are identical and that the added URL entry was the only change.

When I remove the localhost line, it works neither locally nor on the production server.

I reckon this has to do with how Connexion reads the API specificiation and how it sets up the routing. The documentation about this is very sparse though, and I could not find other examples about the best practice with Connexion and OpenAPI 3.0.

Any hints what the best practices are and/or where to start debugging this issue?

Carsten
  • 1,912
  • 1
  • 28
  • 55
  • I could not reproduce your problem. I uploaded two instances of the application through the docker using two servers and both responded. https://github.com/kevinmmartins/python-flask-connexion-example-openapi3/tree/multi-servers – Kevin Martins Apr 15 '19 at 21:04
  • `curl http://myserver.net` via proxy , right ? – Thanh Nguyen Van Apr 16 '19 at 07:34
  • @ThanhNguyenVan that is right; might hence be related to reverse DNS? – Carsten Apr 16 '19 at 07:37
  • so its no way to define environment for it, actually, its running on port 5000 for `dev` enviroment, so if you would like to create `prod` environment, you have to run it on another port ex 6000 – Thanh Nguyen Van Apr 16 '19 at 07:40
  • I've worked around it by using just `/v1` instead of `http://localhost...`. This way, it also works with multiple server URLs. However, I am under the impression that only the first URL is ever used, resulting in problems for the Swagger UI when basepaths differ on other servers. – Carsten Apr 18 '19 at 10:10

0 Answers0