swagger-api / swagger-api/swagger-codegen
[typescript-axios] Classes are not self-aware, try to import self
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the typescript-axios generator invoked by swagger-codegen generate and trace how the DocumentTreeNodeDto model imports are produced. Reproduce the self-referential schema from the issue, then verify that generated TypeScript compiles without an import conflicting with the local model declaration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100