OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript-axios] Set and Array type parameters are not generated

Open
#12,649 2 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?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
    Generated client doesn't contain Set/Array type parameters. Second issue is that tsconfig.json doesn't contain "moduleResolution":"node" option, and typescript cannot find axios dependency.
$ npm install

> example@0.0.1 prepare
> npm run build


> example@0.0.1 build
> tsc --outDir dist/

api/default-api.ts:16:78 - error TS2792: Cannot find module 'axios'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

16 import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';
                                                                                ~~~~~~~

api/default-api.ts:35:31 - error TS2314: Generic type 'Set<T>' requires 1 type argument(s).

35         test: async (fileIds: Set, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
                                 ~~~

api/default-api.ts:81:29 - error TS2314: Generic type 'Set<T>' requires 1 type argument(s).

81         async test(fileIds: Set, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
                               ~~~

api/default-api.ts:101:23 - error TS2314: Generic type 'Set<T>' requires 1 type argument(s).

101         test(fileIds: Set, options?: any): AxiosPromise<void> {
                          ~~~

api/default-api.ts:118:23 - error TS2314: Generic type 'Set<T>' requires 1 type argument(s).

118     readonly fileIds: Set
                          ~~~

common.ts:18:46 - error TS2792: Cannot find module 'axios'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

18 import { AxiosInstance, AxiosResponse } from 'axios';
                                                ~~~~~~~

index.ts:18:15 - error TS2792: Cannot find module './models'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

18 export * from "./models";
                 ~~~~~~~~~~


Found 7 errors in 3 files.

Errors  Files
     5  api/default-api.ts:16
     1  common.ts:18
     1  index.ts:18
npm ERR! code 2
npm ERR! path /home/fenuks/Praca/enigma/stack/api/stack-api/test
npm ERR! command failed
npm ERR! command sh -c npm run build

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/fenuks/.cache/npm/_logs/2022-06-20T15_39_06_573Z-debug-0.log
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
openapi-generator version

6.0.0 (also latest)

OpenAPI definition file content or url

test.yml

openapi: 3.0.3
info:
  version: 0.0.1
  title: Example
paths:
  /files/metadata:
    get:
      operationId: test
      parameters:
        - $ref: '#/components/parameters/QuerySet'
        # - name: fileIds
        #   in: query
        #   required: true
        #   description: Misgenerates as well.
        #   schema:
        #     $ref: '#/components/schemas/UuidSet'
        # - name: fileIds
        #   in: query
        #   required: true
        #   explode: true
        #   description: This works.
        #   schema:
        #     type: array
        #     uniqueItems: true
        #     items:
        #       $ref: '#/components/schemas/Uuid'
      responses:
        '200':
          description: OK.
components:
  parameters:
    QuerySet:
      name: fileIds
      in: query
      required: true
      schema:
        $ref: '#/components/schemas/UuidSet'

  schemas:
    Uuid:
      type: string
      format: uuid

    UuidSet:
      type: array
      uniqueItems: true
      items:
        $ref: '#/components/schemas/Uuid'

conf.json

{
    "npmName": "example",
    "enablePostProcessFile": true,
    "enumNameSuffix": "",
    "enumPropertyNaming": "original",
    "supportsES6": true,
    "withSeparateModelsAndApi": true,
    "apiPackage": "api",
    "modelPackage": "models",
    "useSingleRequestParameter": true
}
Generation Details

It seems that generator cannot handle referenced parameters that contain references to schemas. Last commented parameter is schema generates correct code, others misgenerate.

Steps to reproduce
openapi-generator generate -g typescript-axios -i test.yml -c conf.json -o test
cd test
npm install

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 by running the generation commands with test.yml and conf.json, then inspect the generated api/default-api.ts, common.ts, index.ts, and tsconfig.json. Trace how the referenced QuerySet parameter and UuidSet schema are handled by the typescript-axios generator. Done means the generated client uses a typed array or Set parameter and npm install followed by npm run build completes without the reported TypeScript errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.