Handle Default Responses in response generation #832
Replies: 3 comments
-
fwiy I just monkeypatched response_from_data(status_code=int(200 if code == 'default' else code) I think it is atypical @staticmethod
def _add_responses(endpoint: "Endpoint", data: oai.Responses) -> "Endpoint":
endpoint = deepcopy(endpoint)
for code, response_data in data.items():
+ if code == 'default':
+ continue
response = response_from_data(status_code=int(code), data=response_data)
if isinstance(response, ParseError):
endpoint.errors.append(
ParseError(
detail=(
f"Cannot parse response for status code {code}, "
f"response will be ommitted from generated client"
),
data=response.data,
)
)
continue
if isinstance(response, (RefResponse, ListRefResponse)):
endpoint.relative_imports.add(import_string_from_reference(response.reference, prefix="...models"))
endpoint.responses.append(response)
return endpoint |
Beta Was this translation helpful? Give feedback.
-
Currently having to also monkey patch to get around this as Nextgen's API uses "default" for nearly all responses https://github.com/user-attachments/files/18211398/openapi.json. In my first test iteration I'm assuming 200 for everything, but will have to expand on the codes if/when I discover the API gives up more responses. Work (in progress) at https://github.com/ouhft/openapi-python-client/tree/171-Default-Status-Codes-Fix |
Beta Was this translation helpful? Give feedback.
-
Just exploring options to move from Bravado/Swagger to OpenAPI 3. CCP Games ESI API uses default responses Will need to end up patching this in ourselves or contributing if we move this way, just adding our voice for anyone else that may stumble this direction |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
In the specifications, default MAY be used as a default response object for all HTTP codes that are not covered individually by the specification.
ValueError: invalid literal for int() with base 10: 'default'
To Reproduce
Sample code from a openapi spec.
Expected behavior
Code should generate a custom ApiResponseError class if default is defined, with content of error being a model of the reference/schema items
OpenAPI Spec File
Sample code from a openapi spec.
Desktop (please complete the following information):
Beta Was this translation helpful? Give feedback.
All reactions