OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript-angular] Missing generated tagged unions via npm in comparison to docker image

Open
#17,619 0 comments 0 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][typescript-angular] Missing generated tagged unions via npm in comparison to docker image

Description

Tagged unions are not generated when files are created using the npm module, but they are created when using Docker images with the same additional-properties.

The versions are consistent; in both scenarios, the output of ./out/.openapi-generator/VERSION is 7.2.0.

Actual Output via npm:

export interface Pet { 
    pet_type: string;
}

export interface Lizard extends Pet { 
    lovesRocks?: boolean;
}

Expected Output (same as via docker image):

export interface Lizard { 
    pet_type: 'lizard';
    lovesRocks?: boolean;
}
openapi-generator version
  • npm @openapitools/openapi-generator-cli ^2.7.0
    • npx openapi-generator-cli version-manager set 7.2.0
  • docker image openapitools/openapi-generator-cli:v7.2.0
  • node 10.2.3

Please don't get confused, version 2.7.0 is the npm package, version 7.2.0 is openapi-generator-cli.

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: "OpenAPI Tagged Unions Test"
  version: 1.0.0

paths:
  /pet:
    get:
      responses:
        "200":
          description: "Get current pet"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pet"
components:
  schemas:
    Pet:
      type: object
      required:
        - pet_type
      properties:
        pet_type:
          type: string
      discriminator:
        propertyName: pet_type
        mapping:
          cat: Cat
          dog: Dog
          lizard: Lizard
    Cat:
      allOf:
        - $ref: "#/components/schemas/Pet"
        - type: object
          # all other properties specific to a `Cat`
          properties:
            name:
              type: string
    Dog:
      allOf:
        - $ref: "#/components/schemas/Pet"
        - type: object
          # all other properties specific to a `Dog`
          properties:
            bark:
              type: string
    Lizard:
      allOf:
        - $ref: "#/components/schemas/Pet"
        - type: object
          # all other properties specific to a `Lizard`
          properties:
            lovesRocks:
              type: boolean

Generation Details
Steps to reproduce
  1. npm init
  2. npm install @openapitools/openapi-generator-cli@2.7.0
  3. npx openapi-generator-cli version-manager set 7.2.0
  4. Copy specs in openapi.yaml
  5. npx openapi-generator-cli generate -i ./openapi.yaml -g typescript-angular -o ./out --additional-properties=taggedUnion=true
    • -> Models with no tagged unions are created in cat.ts, dog.ts or lizard.ts in ./out/model/
  6. docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v7.2.0 generate -i /local/openapi.yaml -g typescript-angular -o /local/out --additional-properties=taggedUnions=true
    • -> Models with tagged unions are created
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

Start with openapi.yaml and reproduce the two generation paths using the npm and Docker commands in the issue, including their differing taggedUnion/taggedUnions properties. Compare the generated files under ./out/model/ and trace the typescript-angular generator configuration for the 7.2.0 version. Done when npm generation produces the same tagged-union models as the Docker command.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, docker, openapi, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.