OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.78k stars 6.57k forks source link

[BUG] NestJS - withInterfaces flag being ignored #17655

Open robbie-johnstone-bjss opened 9 months ago

robbie-johnstone-bjss commented 9 months ago

Bug Report Checklist

Description

My understanding of the NestJS OpenAPI Generator docs is that by not including the withInterfaces flag, I should expect models to instead be generated as classes.

Removing or setting this flag to false continues to output interfaces in typescript.

openapi-generator version

7.2

OpenAPI declaration file content or url

https://openapi-generator.tech/docs/generators/typescript-nestjs/#:~:text=false-,withInterfaces,-Setting%20this%20property

Generation Details

Language set to typescript-nestjs (by default this should set withInterfaces to false)

Steps to reproduce

Run npx @openapitools/openapi-generator-cli generate -i <location-of-openapi-spec> -g typescript-nestjs -o <your-output-dir>

Example OpenAPI spec

{
  "openapi": "3.0.0",
  "info": {
    "title": "Dummy API",
    "description": "Dummy",
    "version": "0"
  },
  "paths": {},
  "components": {
    "schemas": {
      "DummyClass": {
        "type": "object",
        "properties": {
          "propertyOne": {
            "type": "string"
          },
          "propertyTwo": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": ["propertyOne", "propertyTwo"]
      }
    }
  }
}

I would expect the file dummyClass.ts to have a class within it, but instead it has an interface.

I am aware that the nestjs generator is considered experimental, but I had thought I'd seen this working previously, though I can't confirm.

gwesterman commented 5 days ago

I second this. Currently it does not seem possible to have NestJS OpenAPI Generator create classes.

Interfaces can not be used in conjunction with @nestjs/ swagger decorators for instance, which can be useful in some situations.