swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.9k stars 6.03k forks source link

[Typescript-Angular] Not generating models from referenced definition #6817

Open HermenOtter opened 6 years ago

HermenOtter commented 6 years ago

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

HermenOtter commented 6 years ago

This issue explains a workaround, but I wonder if this issue is going to be fixed or that it can't be fixed?

ps. I appreciate the work being done here and the code generation is great.

tony-gutierrez commented 6 years ago

Doesnt follow external refs for ruby in the online generator either.