Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #3278
Closed
Open
Issue created Jul 04, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][typescript-fetch] Schema with type array generates undefined function

Created by: gk4m

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

I'm generating a typescript-fetch client using OpenAPI Generator 4.0.2. After running the generator, function stringToJSON is included in the output, but it is not defined.

openapi-generator version

4.0.2

OpenAPI declaration file content or url
{
  "swagger": "2.0",
  "info": {
    "description": "MyApi",
    "title": "MyApi",
    "version": "1.0.0"
  },
  "basePath": "/v1",
  "schemes": ["http"],
  "paths": {
    "/test": {
      "put": {
        "consumes": ["application/json"],
        "produces": ["application/json"],
        "parameters": [
          {
            "in": "body",
            "name": "body",
            "required": true,
            "schema": {
              "items": {
                "type": "string"
              },
              "type": "array"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  }
}
Command line used for generation
node_modules/.bin/openapi-generator generate -g typescript-fetch -i ./openapi.json -o ./src
Steps to reproduce

I've created a gist that should help to reproduce the issue.

git clone https://gist.github.com/gk4m/67045978063c7e2caf97fc8725620d62 bug-report
cd bug-report
yarn install
yarn generate
yarn test

You should see the following output:

src/apis/DefaultApi.ts:44:46 - error TS2304: Cannot find name 'stringToJSON'.

44             body: requestParameters.body.map(stringToJSON),

The source of the error can be found in src/apis/DefaultApi.ts which contains the following:

export interface TestPutRequest {
    body: Array<string>;
}

/**
 * no description
 */
export class DefaultApi extends runtime.BaseAPI {

    /**
     */
    async testPutRaw(requestParameters: TestPutRequest): Promise<runtime.ApiResponse<void>> {
        if (requestParameters.body === null || requestParameters.body === undefined) {
            throw new runtime.RequiredError('body','Required parameter requestParameters.body was null or undefined when calling testPut.');
        }

        const queryParameters: runtime.HTTPQuery = {};

        const headerParameters: runtime.HTTPHeaders = {};

        headerParameters['Content-Type'] = 'application/json';

        const response = await this.request({
            path: `/test`,
            method: 'PUT',
            headers: headerParameters,
            query: queryParameters,
            body: requestParameters.body.map(stringToJSON),
        });

        return new runtime.VoidApiResponse(response);
    }

    /**
     */
    async testPut(requestParameters: TestPutRequest): Promise<void> {
        await this.testPutRaw(requestParameters);
    }

}
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/1877

Suggest a fix

Function stringToJSON should be added to generated file.

Assignee
Assign to
Time tracking