OpenAPITools / OpenAPITools/openapi-generator

[BUG] [TypeScript] Generated TS client sets void return type for 302 Redirects

Open
#15,955 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
Description

The generated code for a TypeScript client returns void for 302's

openapi-generator version

6.6.0

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Example API
  version: v1
paths:
  /a:
    get:
      tags:
        - Example
      summary: 302 Found (With Content)
      operationId: a
      responses:
        '302':
          description: Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Schema'
  /b:
    get:
      tags:
        - Example
      summary: 302 Found (Without Content)
      operationId: b
      responses:
        '302':
          description: Found
components:
  schemas:
    Schema:
      type: object
      properties:
        a:
          type: string
      additionalProperties: false
/* tslint:disable */
/* eslint-disable */
/**
 * Example API
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: v1
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


import * as runtime from '../runtime';
import type {
  Schema,
} from '../models';
import {
    SchemaFromJSON,
    SchemaToJSON,
} from '../models';

/**
 * ExampleApi - interface
 * 
 * @export
 * @interface ExampleApiInterface
 */
export interface ExampleApiInterface {
    /**
     * 
     * @summary 302 Found (With Content)
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof ExampleApiInterface
     */
    aRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>>;

    /**
     * 302 Found (With Content)
     */
    a(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void>;

    /**
     * 
     * @summary 302 Found (Without Content)
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof ExampleApiInterface
     */
    bRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>>;

    /**
     * 302 Found (Without Content)
     */
    b(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void>;

}

/**
 * 
 */
export class ExampleApi extends runtime.BaseAPI implements ExampleApiInterface {

    /**
     * 302 Found (With Content)
     */
    async aRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        const response = await this.request({
            path: `/a`,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * 302 Found (With Content)
     */
    async a(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.aRaw(initOverrides);
    }

    /**
     * 302 Found (Without Content)
     */
    async bRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        const response = await this.request({
            path: `/b`,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * 302 Found (Without Content)
     */
    async b(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.bRaw(initOverrides);
    }

}
Generation Details

Generated via openapi-cli node package that uses openapi-generator behind the scenes with this config:

{
  "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "6.6.0",
    "generators": {
      "v1": {
        "inputSpec": "test.yaml",
        "generatorName": "typescript-fetch",
        "output": "src/lib/api",
        "additionalProperties": {
          "supportsES6": true,
          "stringEnums": true,
          "withInterfaces": true,
          "enumPropertyNaming": "camelCase",
          "modelPropertyNaming": "camelCase",
          "useSingleRequestParameter": false
        }
      }
    }
  }
}
Steps to reproduce

Install npm

npm init

put the provided spec into a test.yaml file in the same directory as the package.json generated by npm init

npm i -D @openapitools/openapi-generator-cli
npx openapi-generator-cli generate

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided test.yaml and the typescript-fetch generator configuration, then inspect the generated ExampleApi output for the two 302 responses. Trace how the response schema is represented when generating the client methods. Done means a 302 response with application/json content is not generated as void, while the response without content remains distinguishable.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.