openapistack / openapi-client-axios

JavaScript client library for consuming OpenAPI-enabled APIs with axios
https://openapistack.co
MIT License
558 stars 67 forks source link

typegen response format is unexpected #25

Closed infomofo closed 4 years ago

infomofo commented 4 years ago

I have an openapi json file with responses for operations defined like this:

 "responses": {
                    "404": {
                        "description": "Not found"
                    },
                    "422": {
                        "description": "Validation Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/HTTPValidationError"
                                }
                            }
                        }
...

When I run typegen on this client it seems to generate an invalid file.

It exports the resources fine with a dollar sign preceding the numbers

    namespace Responses {
      export type $200 = Components.Schemas.HospitalUtilization;
      export type $422 = Components.Schemas.HTTPValidationError;
    }

But then the generated response does not have the preceding dollarsign, which is invalid typescript and doesn't reference the generated code properly

    get(
      parameters?: Parameters<Paths.<MY_PATH>.PathParameters>,
      data?: any,
      config?: AxiosRequestConfig  
    ): OperationResponse<Paths.<MY_PATH>.Responses.200 | Paths.<MY_PATH>.Responses.422>
  }

Does anyone else run into this issue? If I find and replace all of these with the preceding dollar sign it seems to work fine.

The other method of generating a client- directly from my openapi.json works as well but I was hoping to switch to the typegen method.

anttiviljami commented 4 years ago

Seems like this bug was introduced from updating dtsgenerator to the latest version.

anttiviljami commented 4 years ago

This is fixed in openapi-client-axios-typegen@1.1.1