acacode / swagger-typescript-api

Generate the API Client for Fetch or Axios from an OpenAPI Specification
MIT License
3.37k stars 361 forks source link

No result from methods that do not have an explicit content type #527

Open laktak opened 1 year ago

laktak commented 1 year ago

When generating an api from a spec that does not define the content, the generated code does not return anything.

IMO, since a result type is defined it should return a result.

e.g. from https://github.com/gothinkster/realworld/blob/main/api/openapi.yml

      responses:
        '200':
          $ref: '#/components/responses/MultipleArticlesResponse'

will generate

      this.request<void, GenericErrorModel>({
        path: `/articles`,
        method: "GET",
        query: query,
        ...params,
      }),

The problem is that this method will not return anything.

If I manually change the spec:

        '200':
          content:
            application/json:
              $ref: '#/components/responses/MultipleArticlesResponse'

I get the correct result with:

      this.request<void, GenericErrorModel>({
        path: `/articles`,
        method: "GET",
        query: query,
        format: "json",
        ...params,
      }),
laktak commented 1 year ago

I noticed that if I push the yml into https://apitools.dev/swagger-parser/online/ and then use the JSON output, the generated API is OK.

Not sure if a preprocessing step would be a good solution.