swagger-api / swagger-api/swagger-codegen
[NEST JS - TYPESCRIPT] nullable field not generated
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Hey Swagger code gen team 🥷
📔 Description
I'm currently working on a monorepo nest js / angular app.
We use nx lib to create a reusable lib to provide frontend model according to backend type defintion.
So we decide to use swagger codegen to generate typescript model and serve that to our frontend
➡️ This working as excepted (good job to the team for the great work 🙌 )
For some reason, we need to use a nullable field.
So i just follow the documentation and i have this piece of code :
@ApiProperty({
type: MyType,
nullable: true,
})
MyNullableField!: MyType | null;
My class definition
but when i try generate my code with the codegen command, Swagger generated
Excepted code
MyNullableField: myType | null;
the code wanted by the generation
Swagger generated code
MyNullableField: myType;
generated code by swagger
🔢 Swagger-codegen version
I use swagger over Brew (im using Macos)
// mac version
Mac intel 2019
Mac OS Monterey
Version 12.5.1
// brew version
Homebrew 4.0.19
// swagger code gen brew package version
swagger-codegen: stable 3.0.44 (bottled)
// swagger nest js package
`@nestjs/swagger": "^6.3.0`
🧰 Command line used for generation
swagger-codegen generate -i http://localhost:3000/swagger-json -l typescript-angular -o myGeneratedFilesFolder/
🔁 Steps to reproduce
- Create a typescript class with nullable fields
- Try to generated it with swagger-codegen
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 by reproducing the issue with the NestJS-generated Swagger JSON and the swagger-codegen generate command using the typescript-angular generator. Trace how the nullable field is represented in the input and generated model; done means the output preserves the field's nullable type and a regression case covers the reproduction.
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
- 35/100