OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-axios] Object type instead any
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)?
- 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 want to use any type in typescript, but generator gives me object type.
From OpenAPI 3 Data Types (section Any Type)
A schema without a type matches any data type – numbers, strings, objects, and so on.
openapi-generator version
4.2.3
OpenAPI declaration file content or url
{
"openapi": "3.0.2",
"info": {
"title": "Api",
"description": "Api",
"version": "1.0.0"
},
"paths": {},
"components": {
"schemas": {
"DataBlock": {
"title": "DataBlock",
"required": [
"data"
],
"type": "object",
"properties": {
"version": {
"title": "Version",
"type": "string",
"description": "Version of data block"
},
"data": {
"title": "Data",
"description": "Block data",
"nullable": true,
"example": "here may be any json value"
}
},
"description": "Data block with version"
}
}
}
}
Command line used for generation
openapi-generator generate -g typescript-axios -i ./src/api/openapi.json -o ./src/api/ -c ./src/api/.openapi-generator/config.yaml -DskipFormModel=true
Steps to reproduce
Do not specify the type in the schema, and generate
Actual output
/**
* Data block with version
* @export
* @interface DataBlock
*/
export interface DataBlock {
/**
* Version of data block
* @type {string}
* @memberof DataBlock
*/
version?: string;
/**
* Block data
* @type {object}
* @memberof DataBlock
*/
data: object | null;
}
Expected output
/**
* Data block with version
* @export
* @interface DataBlock
*/
export interface DataBlock {
/**
* Version of data block
* @type {string}
* @memberof DataBlock
*/
version?: string;
/**
* Block data
* @type {any}
* @memberof DataBlock
*/
data: any; // <----- Any type
}
Related issues/PRs
Not found
Suggest a fix
I have no idea
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
Reproduce the issue with the openapi-generator generate -g typescript-axios command and the provided ./src/api/openapi.json schema. Trace how the typescript-axios generator maps an untyped nullable property, then add or update coverage for the generated DataBlock model so the field uses the intended TypeScript type instead of object.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100