swagger-codegen-generators icon indicating copy to clipboard operation
swagger-codegen-generators copied to clipboard

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

Open programmer106 opened this issue 2 years ago • 5 comments

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: [email protected]
 *
 * 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.

programmer106 avatar Jun 02 '23 10:06 programmer106

Hi, did you get a solution for this issue?

Thanks

alemjimer avatar Mar 20 '24 10:03 alemjimer

Hi,

did you get a solution for this issue?

Thanks

Eh, no. Got fired.

twlvl avatar Mar 21 '24 10:03 twlvl

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?

JohannesRiegler avatar Aug 08 '24 07:08 JohannesRiegler

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


Nexiz15 avatar Aug 13 '24 07:08 Nexiz15

@HugoMario @DonIsaac - are either of you able to review the PR for this one / provide feedback or approve ?

bdubroy-atl avatar May 01 '25 08:05 bdubroy-atl