swagger-api / swagger-api/swagger-codegen

[Typescript-Angular2] Array items exported as extending "models.Array"

Open
#3,616 8 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript Issue: Workaround available
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

If I define a model definition as just an array, then the created model ts file says "extends models.Array" instead of just "extends Array"

Swagger-codegen version 2.2.1
Swagger declaration file content or url
swagger: "2.0"

host: localhost
schemes:
  - http
consumes:
  - application/json
produces:
  - application/json
paths:
  /test:
    get:
      tags:
        - test
      operationId: test
      description: test
      responses:
        "200":
          description: Success
          schema:
            $ref: "#/definitions/TestArray"

definitions:
  TestArray:
    type: array
    items:
      $ref: "#/definitions/TestItem"

  TestItem:
    properties:
      val:
        type: string

The invalid generated model for TestArray is then:

export interface TestArray extends models.Array<models.TestItem> {

}

whereas it should just be as follows (without "models."):

export interface TestArray extends Array<models.TestItem> {

}
Command line used for generation

java -jar swagger-codegen-cli-2.2.1.jar generate -i ./swagger.yaml -l typescript-angular2 --additional-properties modelPropertyNaming=original

Suggest a Fix

For the time-being, I have my codegen run within a script that uses sed to replace the values after generation:
sed -i '' 's/extends models\.Array/extends Array/g' *

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 the provided swagger.yaml definition and run the listed swagger-codegen-cli command using the typescript-angular2 generator. Inspect the generated TestArray model and the generator templates or entry points that produce its extends clause; done means array models extend Array without the models. prefix while item models remain correctly qualified.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.