swagger-api / swagger-codegen-generators

Apache License 2.0
284 stars 424 forks source link

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

Open programmer106 opened 1 year ago

programmer106 commented 1 year ago

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.

alemjimer commented 8 months ago

Hi, did you get a solution for this issue?

Thanks

elkeis commented 8 months ago

Hi,

did you get a solution for this issue?

Thanks

Eh, no. Got fired.

JohannesRiegler commented 3 months ago

The same issue occured in the Angular TypeScript client https://github.com/swagger-api/swagger-codegen/issues/6201. It has already been fixed in https://github.com/swagger-api/swagger-codegen/pull/6450. Maybe a similar change for the axios client would fix the issue?

Nexiz15 commented 3 months ago

It is quiet hacky but you can simply duplicate your DTO:


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/CategoryRecurstion'
       xml:
         name: category
       type: object
     CategoryRecurstion:
       x-swagger-router-model: io.swagger.petstore.model.CategoryRecurstion
       properties:
         id:
           type: string
         name:
           type: string
           example: Dogs
         subcategories:
           type: array,
           items:
             $ref: '#/components/schemas/Category'
       xml:
         name: categoryRecursion
       type: object