Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][typescript-axios] The wrong type is generated by additionalProperties #20029

Open
5 of 6 tasks
punkyoon opened this issue Nov 5, 2024 · 0 comments
Open
5 of 6 tasks

Comments

@punkyoon
Copy link

punkyoon commented Nov 5, 2024

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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)

Description

When there is an additionalProperty value in schemas, it generates incorrect TypeScript code typed as Null instead of null.

openapi-generator version

7.9.0 (@openapitools/openapi-generator-cli is 2.15.3)

OpenAPI declaration file content or url

Note

It works fine when there is no additionalProperties option

openapi: 3.1.0
info:
  title: Sample API
  description: This is sample api
  version: 0.1.0
components:
  schemas:
    SampleData:
      # No `additionalProperties`
      properties:
        sample_property:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/ExampleData'
        sample_property2:
          format: float
          type:
            - number
            - 'null'
    ExampleData:
      type: object
      properties:
        example_property:
          type: string

Caution

It works incorrectly when there is an additionalProperties option

openapi: 3.1.0
info:
  title: Sample API
  description: This is sample api
  version: 0.1.0
components:
  schemas:
    SampleData:
      # With `additionalProperties`
      additionalProperties: {}
      properties:
        sample_property:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/ExampleData'
        sample_property2:
          format: float
          type:
            - number
            - 'null'
    ExampleData:
      type: object
      properties:
        example_property:
          type: string

Generation Details

I've removed the generated comments

Note

It works fine when there is no additionalProperties option

.openapi-generator/FILES

.gitignore
.npmignore
.openapi-generator-ignore
api.ts
base.ts
common.ts
configuration.ts
git_push.sh
index.ts
models/example-data.ts
models/index.ts
models/sample-data.ts

models/sample-data.ts

import type { ExampleData } from './example-data';

export interface SampleData {
    'sample_property'?: ExampleData | null;

    'sample_property2'?: number | null;
}

Caution

It works incorrectly when there is an additionalProperties option

.openapi-generator/FILES

.gitignore
.npmignore
.openapi-generator-ignore
api.ts
base.ts
common.ts
configuration.ts
git_push.sh
index.ts
models/example-data.ts
models/index.ts
models/sample-data-sample-property.ts
models/sample-data.ts

models/sample-data.ts

import type { SampleDataSampleProperty } from './sample-data-sample-property';

export interface SampleData {
    [key: string]: any;

    'sample_property'?: SampleDataSampleProperty;

    'sample_property2'?: number;
}

models/sample-data-sample-property.ts

There is Null instead of null

import type { ExampleData } from './example-data';

export type SampleDataSampleProperty = ExampleData | Null;  //////// This is wrong!

Steps to reproduce

$ npm install @openapitools/openapi-generator-cli@2.15.3

# Generate the code with the `sample.yaml` I've uploaded the above
$ npx openapi-generator-cli generate \
  -g typescript-axios \
  -i sample.yaml \
  -o sample \
  --additional-properties stringEnums=true,legacyDiscriminatorBehavior=false,withSeparateModelsAndApi=true,modelPackage=models,apiPackage=apis,useSingleRequestParameter=true

Related issues/PRs

Nothing

Suggest a fix

It should generate the null instead of Null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant