swagger-api / swagger-api/swagger-codegen-generators

[typescript-axios] incorrect imports in graph-like structures

Open
#1,163 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

given:

components: 
  schemas: 
     Category:
      x-swagger-router-model: io.swagger.petstore.model.Category
      properties:
        id:
          type: string
        name:
          type: string
          example: Dogs
        subcategories:
          type: array,
          items:
            $ref: '#/components/schemas/Category'
      xml:
        name: category
      type: object

after generation:

/* tslint:disable */
/* eslint-disable */
/**
 * Swagger Petstore - OpenAPI 3.0
 * This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach! You can now help us improve the API whether it's by making changes to the definition itself or to the code. That way, with time, we can improve the API in general, and expose some of the new features in OAS3. Some useful links: - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore) - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
 *
 * OpenAPI spec version: 1.0.17
 * Contact: apiteam@swagger.io
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 * Do not edit the class manually.
 */
import { Category } from './category';
/**
 * 
 * @export
 * @interface Category
 */
export interface Category {
    /**
     * 
     * @type {string}
     * @memberof Category
     */
    id?: string;
    /**
     * 
     * @type {string}
     * @memberof Category
     */
    name?: string;
    /**
     * 
     * @type {Array<Category>}
     * @memberof Category
     */
    subcategories?: Array<Category>;
}

after trying to build got:

models/category.ts:14:10 - error TS2440: Import declaration conflicts with local declaration of 'Category'.

Can't maintain the client-ts layer effectively due to this issue.

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 generated models/category.ts shown in the report and reproduce the TypeScript build error for the recursive Category schema. Trace the TypeScript Axios generator output that produces the import, then verify that generated graph-like models no longer import themselves and the client builds successfully.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.