Uh oh!
There was an error while loading. Please reload this page.
Server Base Path Not Applied to Generated Endpoint URLs #833
Replies: 6 comments
It will take some consideration add in support for servers, though maybe we can add in partial support in the near term without building out the full set. Here are some things OpenAPI servers are supposed to be able to do:
There are also some usability questions like:
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Thanks for the response! I definitely appreciate that the servers block could be tricky to fully support. I like the approach/convention of auto-selecting the first server if only one is defined. It seems like the most sane, common behavior. The client might also be able to store all the generated servers and allow them as optional parameter for a given call. So a sample generated method signature: Given: classClient:
base_url: strservers: Optional[List[Server]]
defdefault_server(self) ->Optional[Server]:
ifservers:
returnservers[0]
returnNoneSample generated method: defget_request(*, client: Client, request_id: str, server: Server=client.default_server()) ->Request:If server is |
We might also add @dataclassclassServerVariable:
""" A representation of the OpenAPI Server Variable Object"""default: strdescription: Optional[str]
enum: Optional[List[str]]
@dataclassclassServer:
""" A representation of the OpenAPI Server Object"""url: strdescription: Optional[str]
variables: Optional[Dict[str, ServerVariable]]
defresolve_url(self, variable_values: Optional[Dict[str, str]]) ->str:
substitutions=self._default_values().copy()
substitutions.update(variable_values)
returnself.url.format(**substitutions)
def_default_values(self) ->Dict[str, str]:
return {
key: variable.defaultforkey, variableinself.variables.items()
}The endpoint internally would call the specified server's |
Just ran into this, probably a hard blocker for our usage. |
Anything new regarding this issue? Any workarounds? |
I just ran into this as well, thankfully my OpenAPI schema only has a single path in the |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
When specifying a
urlinserversin a spec, the path is completely ignored in the generated endpoints. Making it necessary to fully qualify thebase_urlpassed to theClient, which is problematic when supporting multiple API namespaces (e.g.,/api/v2,/api/experimental).To Reproduce
Steps to reproduce the behavior:
urldefined inserversopenapi-python-client generate --path openapi.jsonThe generated code in
requestsshows:The first part of the URL only puts in the server name passed to
Client, but ignores the specified server path from the spec. Resulting in an invalid URL like:Expected behavior
Should generate an HTTP request like:
The generated code would write the base path in like:
OpenAPI Spec File
{ "openapi": "3.0.1", "info": { "title": "Example API", "version": "2.0.0" }, "servers": [{ "url": "/api/v2" }], "paths": { "/requests/{request_id}": { "get": { "tags": [ "requests" ], "description": "Get a request by ID", "operationId": "getRequest", "parameters": [{ "name": "request_id", "in": "path", "schema": { "type": "string" }, "required": true }], "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Request" } } } } } } } }, "components": { "schemas": { "Request": { "type": "object", "properties": { "id": { "type": "string" } } } } } }This change might need to be behind a compatibility flag to avoid breaking existing code.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
All reactions