Skip to content

[BUG][typescript-nestjs] Generated NestJS Module does not compile with "strict" flag #17671

@ghost

Description

Description

Clients generated with the typescript-nestjs experimental generator will not be compilable with the strict typescript compilation flag due to nullability issues in the generated ApiModule files.

openapi-generator version

Occurs in 7.2.0, used to work in 6.6.0. However, even in 6.6.0, certain features (which we don't use) also cause this to occur - see reproducer.

OpenAPI declaration file content or url

For the reproducer, I used the petstore project

Generation Details
npx @openapitools/openapi-generator-cli generate -g typescript-nestjs -i https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml
Steps to reproduce
  • Generate client using command above
  • Setup rest of dependencies (npm i typescript axios @nestjs/common @nestjs/axios, npx tsc init)
  • Setup necessary compilation flags in tsconfig.json ("experimentalDecorators": true, "emitDecoratorMetadata": true)
  • Run typecheck (npx tsc --noEmit)

A ready-to-use repository with the steps above taken is available at https://github.com/swcm-mnestler/nestjs-openapi-reproducer

Suggest a fix

I'll create a MR for the nullability instances that I encountered, but it's possible there are more of these occurrences in the code base.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions