OpenAPITools / OpenAPITools/openapi-generator
[BUG] [angular-typescript] Unused models not generated
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
When defining model entities that are not used directly by the resscources these models are not generated with the typescript-angular generator. (see SpecialPet in the example below).
This only happens when the model is in a separate file!
This is a problem since our api uses the allOf to extend a base class. The ressource formally returns the base class, but depending on inputs, different acutal responses (subclasses) are returned. It is clear that there needs to be some manual casting, but without the subclass at hand we'd need to manually code it.
openapi-generator version
4.0.2
OpenAPI declaration file content or url
api.yaml:
openapi: 3.0.0
info:
version: "1.0.0"
title: "Swagger Petstore"
paths:
/pet/findByStatus:
get:
responses:
200:
description: "successful operation"
content:
application/json:
schema:
type: "array"
items:
$ref: 'types.yaml#/components/schemas/Pet'
400:
description: "Invalid status value"
types.yaml:
openapi: 3.0.0
info:
version: "1.0.0"
title: "Swagger Petstore"
paths:
/dummy:
get:
responses:
200:
description: 'dummy'
components:
schemas:
Pet:
type: "object"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
example: "doggie"
SpecialPet:
type: "object"
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
specialType:
type: string
Command line used for generation
java -jar openapi-generator-cli-4.0.2.jar generate -i api.yaml -g typescript-angular
Steps to reproduce
Related issues/PRs
Suggest a fix
There should be an option to allow generation of unused models.
Alternatively/Additionally secondary input files from which models are generated might as well solve the problem.
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 api.yaml and types.yaml using the listed OpenAPI Generator 4.0.2 command for typescript-angular. Check why the separately defined SpecialPet model is omitted when it is not referenced directly by a resource. Done means unused models such as SpecialPet are generated, ideally with an option or behavior that covers external model files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, java, openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100