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

[typescript-axios] Classes are not self-aware, try to import self

Open pmcgurk-indeed opened this issue 3 years ago • 2 comments

Description

Hi, the code I generated from swagger spec is throwing a tsc error. The reason is that the model class, DocumentTreeNodeDto, has a field childNodes that is, of course, a List of DocumentTreeNodeDtos. The code generator is creating the DocumentTreeNodeDto model class with import { DocumentTreeNodeDto } from './document-tree-node-dto';, and tsc says error TS2440: Import declaration conflicts with local declaration of DocumentTreeNodeDto.

Swagger-codegen version

3.0.36

Swagger declaration file content or url
"DocumentTreeNodeDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"parentId":{"type":"integer","format":"int64"},"ids":{"type":"array","items":{"type":"object","additionalProperties":{"type":"integer","format":"int64"}}},"childNodes":{"type":"array","items":{"$ref":"#/components/schemas/DocumentTreeNodeDto"}},"nodeName":{"type":"string"},"rank":{"type":"integer","format":"int32"},"deleteType":{"type":"string"},"document":{"$ref":"#/components/schemas/DocumentDto"},"createdAt":{"type":"string","format":"date-time"}}}
Command line used for generation

swagger-codegen generate -i swagger.json -l typescript-axios -o frontend/api

Steps to reproduce

Generate swagger spec and run codegen for Java/Spring Boot class that refers to itself in its fields

Suggest a fix/enhancement

import statements should exclude the class itself that is being generated.

pmcgurk-indeed avatar Jan 13 '23 17:01 pmcgurk-indeed

I stumpeld accros the same bug. Is there any progress or does any workaround exist to solve this problem?

Elscha avatar Mar 20 '23 08:03 Elscha

The code produced by the online generator is affected.

bud-mo avatar Jan 18 '24 10:01 bud-mo