swagger-api / swagger-api/swagger-codegen

[Typescript-Angular] Not generating models from referenced definition

Open
#6,817 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

I have been searching for a similiar issue, but the proposed solutions didn't solve my problem.

Description

In swaggerhub we have several api definitions. There is one 'domain' api that contains shared definitions and responses, however when this domain is referenced by one of the api's: models for the definitions in the domain are not generated.

I want to know how I can reference a shared api and generate the models, the proper way.

Swagger-codegen version

2.3.0-SNAPSHOT

Swagger declaration file content or url

https://app.swaggerhub.com/apis/Company/JustAnApi/2.0

This is JustAnApi that references the SharedApi

post:
     ...stuff here...
      parameters:    
        schema:
          ....stuff here....
      responses:
        201:
          .....stuff here......
        400:
         $ref: 'https://api.swaggerhub.com/domains/Company/SharedApi/0.1#/responses/GeneralError'

https://api.swaggerhub.com/domains/Company/SharedApi/0.1
Below the response that is used in the JustAnApi.

Response Example A - not working:

definitions:
  ErrorModel:   
    properties:
      <insert properties here>
responses:
   GeneralError:
     description: General Error
     schema:
      type: "array"
      items:
       $ref: '#definitions/ErrorModel'

The above response references the ErrorModel definition. This approach does not generate the ErrorModel.
The example below does work.

Response example B - working response:

definitions:
  ErrorModel:   
    properties:
      <insert properties here>
responses:
   GeneralError:     
     schema:
      type: "array"
      items:
       $ref: 'https://api.swaggerhub.com/domains/Company/SharedApi/0.1#definitions/ErrorModel'

However a static ref as seen in example B is something we cannot use in our development cycle(it will cause trouble), do you have any idea how to solve this problem?

Command line used for generation

java -jar swagger-codegen-cli-2.3.0.jar generate -i https://api.swaggerhub.com/apis/Centric/Belastingen_Subjecten/0.2.2_codegen -l typescript-angular -o

Thank you for reading,
Hermen

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

Reproduce the issue with the supplied swagger-codegen-cli command, the JustAnApi URL, and the SharedApi domain examples; compare the generated TypeScript-Angular models for the two reference forms. Trace how the referenced response and ErrorModel are resolved, and consider the issue complete when the dynamic domain reference generates ErrorModel without requiring a static definition URL.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.