OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript-fetch] anyOf with "number" and "string" leads to empty Interface

Open
#19,155 1 comment 13 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?
  • [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

openapi.json

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
  1. put openapi.json into directory
  2. execute cli command above
  3. check ./out/ts/models/PostsSchema.ts and Content.ts

for reference here are the files I get:
PostsSchema.ts
Content.ts

Related issues/PRs
Suggest a fix

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

Run the documented docker generation command with the linked openapi.json, then inspect out/ts/models/PostsSchema.ts and Content.ts. Trace the typescript-fetch generator's handling of the anyOf schema and add or update coverage where the relevant generator behavior is defined. Done means the generated property is content?: number | string and no empty Content interface is produced.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, java, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.