OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-axios] The wrong type is generated by `additionalProperties`
Nobody has claimed this yet.
- 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?
- [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 noadditionalPropertiesoption
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 anadditionalPropertiesoption
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 noadditionalPropertiesoption
.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 anadditionalPropertiesoption
.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
Nullinstead ofnull
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the provided OpenAPI YAML and the typescript-axios generation command to reproduce the output. Compare models/sample-data-sample-property.ts and models/sample-data.ts with the output from the schema without additionalProperties; done means the generated union uses lowercase null and matches the expected TypeScript types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100