Closed mariofix closed 1 year ago
Your example basically mirrors a server definition as shown in the swagger doc. Yet - it does not work. A client is free to use any server defined, random.choice would be as valid as [0]. If you want to use a single description document to address different server backends - such as live and development, the use of server-variables is required.
e.g.
openapi: 3.0.0
servers:
- url: 'https://{host}.flow.cl/api'
variables:
host:
enum:
- sandbox
- www
default: sandbox
The client has to support server-variables. You have to provide the server-variables to the client upon instantiation, such as
api = OpenAPI(…, server_variables={"host":"www"})
next, client has to create the url using the provided variables, default values and format.
So overall, it's possible, but I do not know about the implementation status of server-variables wrt. to client libraries/generators, expect it to be marginal/niche.
Additionally it is possible to specify "servers" on a PathItem and Operation scope, but this won't help with your use-case.
I think you'll be better of to modify servers
to match your requirements before passing the description document to the client/library.
Thanks, yeah, I noticed they do not conform to the standard, so I just created one file for sandbox and another for live.
Awesome library, thanks!
The file i'm trying to read has two servers in it
But i noticed in _get_callable that you select the first one in the array
is there another way to select the server to send the request?