openapi-generator
openapi-generator copied to clipboard
[BUG] [typescript-fetch] anyOf with "number" and "string" leads to empty Interface
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] What's the actual output vs expected output?
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using openapi-generator on an openapi.json that inluced anyOf with number and string, the resulting typescript schema is incorrect.
"PostsSchema": {
"properties": {
"content": {
"anyOf": [
{
"type": "number"
},
{
"type": "string"
}
],
"title": "Content"
}
},
"title": "PostsSchema",
"type": "object"
}
leads to
export interface Content {
}
export interface PostsSchema {
/**
*
* @type {Content}
* @memberof PostsSchema
*/
content?: Content;
}
but it should be content?: number | string; Content should not be an interface I think?.
openapi-generator version
v7.7.0 (https://github.com/OpenAPITools/openapi-generator/releases/tag/v7.7.0)
OpenAPI declaration file content or url
Generation Details
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v7.7.0 generate -i /local/openapi.json -g typescript-fetch -o /local/out/ts
Steps to reproduce
- put openapi.json into directory
- execute cli command above
- check
./out/ts/models/PostsSchema.tsandContent.ts
for reference here are the files I get: PostsSchema.ts Content.ts
Related issues/PRs
Suggest a fix
+1 seeing this as well
"status": {
"anyOf": [
{
"type": "string",
"const": "CREATED_NOT_STARTED"
},
{
"type": "string",
"const": "IN_PROGRESS"
},
{
"type": "string",
"const": "COMPLETED"
},
{
"type": "string",
"const": "FAILED"
},
{
"type": "string"
}
],
"title": "Status"
},
generates empty interface
/**
*
* @export
* @interface Status
*/
export interface Status {}