openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[REQ][typescript-axios] Responses Status

Open wirekang opened this issue 3 years ago • 6 comments

Is your feature request related to a problem? Please describe.

responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type:...
        '409':
          ...
        '500':
          ...

There are many responses in schema, but genearted code ignore all responses except 200. Is this intended behavior?

Describe the solution you'd like

Geneated comments about responses.

wirekang avatar Jul 20 '22 02:07 wirekang

We are also facing the similar issue. Here is the detailed explainantion.

Description

When there are multiple responses defined for an endpoint based on status codes, only the first response's type is marked as 'response_type' for that endpoint in default_api.py file

openapi-generator version

6.0.0

OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "info": {
    "title": "Test API",
    "version": "v1.0"
  },
  "servers": [],
  "paths": {
    "/cluster/node/add": {
      "post": {
        "operationId": "cluster_node_add",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NodeConfig"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "node add success response"
          },
          "500": {
            "description": "node add failure response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DefaultErrorResp"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "DefaultErrorResp": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer",
            "format": "int32"
          },
          "msg": {
            "type": "string"
          }
        }
      },
      "NodeConfig": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int32"
          },
          "hostname": {
            "type": "string",
            "format": "string"
          }
        }
      }
    }
  }
}
Generation Details
Steps to reproduce

Generate code with OpenAPI version 6.0.0 and mention generator as python.

java -jar openapi-generator-cli.jar generate -g python -o test_api -i test.json --additional-properties=packageName=testAPI

Once the code is generated, navigate to the folder test_api/testAPI/api/ and open default_api.py file

The 'response_type' for the endpoint is assigned to first response present in the json file for that endpoint and all other responses are ignored. In this case it is marked as 'None' as in the spec file '200' is response is returning None and the response of '500' is completely ignored.

default_api.py

"""
    Test API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)  # noqa: E501

    The version of the OpenAPI document: v1.0
    Generated by: https://openapi-generator.tech
"""


import re  # noqa: F401
import sys  # noqa: F401

from testAPI.api_client import ApiClient, Endpoint as _Endpoint
from testAPI.model_utils import (  # noqa: F401
    check_allowed_values,
    check_validations,
    date,
    datetime,
    file_type,
    none_type,
    validate_and_convert_types
)
from testAPI.model.default_error_resp import DefaultErrorResp
from testAPI.model.node_config import NodeConfig


class DefaultApi(object):
    """NOTE: This class is auto generated by OpenAPI Generator
    Ref: https://openapi-generator.tech

    Do not edit the class manually.
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client
        self.cluster_node_add_endpoint = _Endpoint(
            settings={
                'response_type': None,
                'auth': [],
                'endpoint_path': '/cluster/node/add',
                'operation_id': 'cluster_node_add',
                'http_method': 'POST',
                'servers': None,
            },
            params_map={
                'all': [
                    'node_config',
                ],
                'required': [],
                'nullable': [
                ],
                'enum': [
                ],
                'validation': [
                ]
            },
            root_map={
                'validations': {
                },
                'allowed_values': {
                },
                'openapi_types': {
                    'node_config':
                        (NodeConfig,),
                },
                'attribute_map': {
                },
                'location_map': {
                    'node_config': 'body',
                },
                'collection_format_map': {
                }
            },
            headers_map={
                'accept': [
                    'application/json'
                ],
                'content_type': [
                    'application/json'
                ]
            },
            api_client=api_client
        )

    def cluster_node_add(
        self,
        **kwargs
    ):
        """cluster_node_add  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

        >>> thread = api.cluster_node_add(async_req=True)
        >>> result = thread.get()


        Keyword Args:
            node_config (NodeConfig): [optional]
            _return_http_data_only (bool): response data without head status
                code and headers. Default is True.
            _preload_content (bool): if False, the urllib3.HTTPResponse object
                will be returned without reading/decoding response data.
                Default is True.
            _request_timeout (int/float/tuple): timeout setting for this request. If
                one number provided, it will be total request timeout. It can also
                be a pair (tuple) of (connection, read) timeouts.
                Default is None.
            _check_input_type (bool): specifies if type checking
                should be done one the data sent to the server.
                Default is True.
            _check_return_type (bool): specifies if type checking
                should be done one the data received from the server.
                Default is True.
            _spec_property_naming (bool): True if the variable names in the input data
                are serialized names, as specified in the OpenAPI document.
                False if the variable names in the input data
                are pythonic names, e.g. snake case (default)
            _content_type (str/None): force body content-type.
                Default is None and content-type will be predicted by allowed
                content-types and body.
            _host_index (int/None): specifies the index of the server
                that we want to use.
                Default is read from the configuration.
            _request_auths (list): set to override the auth_settings for an a single
                request; this effectively ignores the authentication
                in the spec for a single request.
                Default is None
            async_req (bool): execute request asynchronously

        Returns:
            None
                If the method is called asynchronously, returns the request
                thread.
        """
        kwargs['async_req'] = kwargs.get(
            'async_req', False
        )
        kwargs['_return_http_data_only'] = kwargs.get(
            '_return_http_data_only', True
        )
        kwargs['_preload_content'] = kwargs.get(
            '_preload_content', True
        )
        kwargs['_request_timeout'] = kwargs.get(
            '_request_timeout', None
        )
        kwargs['_check_input_type'] = kwargs.get(
            '_check_input_type', True
        )
        kwargs['_check_return_type'] = kwargs.get(
            '_check_return_type', True
        )
        kwargs['_spec_property_naming'] = kwargs.get(
            '_spec_property_naming', False
        )
        kwargs['_content_type'] = kwargs.get(
            '_content_type')
        kwargs['_host_index'] = kwargs.get('_host_index')
        kwargs['_request_auths'] = kwargs.get('_request_auths', None)
        return self.cluster_node_add_endpoint.call_with_http_info(**kwargs)
Related issues/PRs
Suggest a fix

Handle multiple responses for an endpoint based on multiple status codes present in the spec file. For example it can be like, 'response_type' : {'200': None, '500': DefaultErrorResp}

Sameer-6 avatar Aug 18 '22 04:08 Sameer-6

Yes, it will be very useful.

rtatarinov avatar Nov 19 '22 20:11 rtatarinov

This is definitively something that would add a lot of power to this package

raffobaffo avatar Mar 19 '23 13:03 raffobaffo

This is an important feature. Currently, the types generated are incomplete and misleading. It makes it so you cannot use the client without additional work-arounds in quite a few cases. As such, this seems more like a bug than a feature request to me. It would be great to see this fixed.

ahilke avatar Jan 10 '24 08:01 ahilke

Has there been any progress on this?

Julian-Hackenberg avatar Jan 19 '25 15:01 Julian-Hackenberg

Also curious if this is being worked on

juliuskreutz avatar Dec 03 '25 22:12 juliuskreutz