Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Handle Default Responses in response generation #124

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

Closed
bladecoates opened this issue Aug 4, 2020 · 1 comment
Closed

Handle Default Responses in response generation #124

bladecoates opened this issue Aug 4, 2020 · 1 comment
Labels
✨ enhancement New feature or improvement 🍭 OpenAPI Compliance Supporting a new bit of the OpenAPI spec

Comments

@bladecoates
Copy link

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.

response = response_from_data(status_code=int(code), data=response_data)

ValueError: invalid literal for int() with base 10: 'default'

To Reproduce
Sample code from a openapi spec.

      responses:
        "200":
          description: An array of items
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/ItemsArrayObj"
        default:
          description: Unknown error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

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.

      responses:
        "200":
          description: An array of items
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/ItemsArrayObj"
        default:
          description: Unknown error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

Desktop (please complete the following information):

  • OS: Linux Mint
  • Python Version: 3.8.3
  • openapi-python-client version: git main
@bladecoates bladecoates added the 🐞bug Something isn't working label Aug 4, 2020
@dbanty dbanty added ✨ enhancement New feature or improvement and removed 🐞bug Something isn't working labels Sep 26, 2020
@micimize
Copy link

micimize commented Sep 28, 2020

fwiy I just monkeypatched parser/openapi.py temporarily with
edit: actually the default was the valid response so for me it ended up being

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

alexifm added a commit to alexifm/openapi-python-client that referenced this issue Jan 27, 2021
alexifm added a commit to alexifm/openapi-python-client that referenced this issue Feb 11, 2021
alexifm added a commit to alexifm/openapi-python-client that referenced this issue Feb 11, 2021
@dbanty dbanty added the 🍭 OpenAPI Compliance Supporting a new bit of the OpenAPI spec label Aug 13, 2023
@openapi-generators openapi-generators locked and limited conversation to collaborators Aug 13, 2023
@dbanty dbanty converted this issue into discussion #832 Aug 13, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
✨ enhancement New feature or improvement 🍭 OpenAPI Compliance Supporting a new bit of the OpenAPI spec
Projects
None yet
Development

No branches or pull requests

3 participants