Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][typescript-angular] allOf without discriminator results in unnecessary imports #5171

Open
5 tasks done
amakhrov opened this issue Jan 31, 2020 · 1 comment · May be fixed by #9834
Open
5 tasks done

[BUG][typescript-angular] allOf without discriminator results in unnecessary imports #5171

amakhrov opened this issue Jan 31, 2020 · 1 comment · May be fixed by #9834

Comments

@amakhrov
Copy link
Contributor

amakhrov commented Jan 31, 2020

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?
Description

When a model uses allOf, where some of the referenced models do not have a discriminator (hence, do not denote any hierarchy), the target interface just gets all properties copied from the referenced models, no interface inheritance/extending involved.

However, the base interfaces are still imported into the file with the target model - despite being unused.

openapi-generator version

Latest

OpenAPI declaration file content or url
definitions:
  ExtraFields:
    type: object
    properties:
      extra_field:
        type: string

  ResponseOnePlus:
    type: object
    allOf:
      - $ref: '#/definitions/ExtraFields'
      - type: object
        properties:
          own_field:
            type: string
Command line used for generation
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \
    -i /local/spec.yaml \
    -g typescript-angular \
    -o /local/generated
Steps to reproduce
  • Run a command above, providing a spec file with allOf
  • Check model/responseOnePlus.ts.It will looks like this:
import { ExtraFields } from './extraFields';
import { ResponseOnePlusAllOf } from './responseOnePlusAllOf';

export interface ResponseOnePlus { 
    extraField?: string;
    ownField?: string;
}

Both imports here are not used.

Related issues/PRs

Similar issues:

Suggest a fix

The fixes for linked axios and rxjs generators above change the approach for generating a target interface: instead of copying all properties from the source interfaces into the target one, the target type is simply defined as type intersection.

Perhaps we should consider doing the same for typescript-angular (and probably other typescript generators that emit each model in a separate file with imports).

Note that the above mentioned fixes apply the same approach both with or without discriminator, thus erasing the semantic difference between them (hierarchy vs composition)

@auto-labeler
Copy link

auto-labeler bot commented Jan 31, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant