nestjs / swagger

OpenAPI (Swagger) module for Nest framework (node.js) :earth_americas:
https://nestjs.com
MIT License
1.69k stars 476 forks source link

Target es5 breaks nestjs/swagger #88

Closed nodren closed 6 years ago

nodren commented 6 years ago

If you take the nestjs/typescript-starter repo, and changing the target to es5 in tsconfig(and adding lib: ['es6'])

ApiModelProperty defined properties no longer are described in swagger. running this correctly gives me a /api route with swagger ui, but the TestBody definition doesn't exist

app.controller.ts File:

import { AppService } from './app.service';
import { ApiModelProperty, ApiOperation } from '@nestjs/swagger';

export class TestBody {
  @ApiModelProperty() readonly email: string;
  @ApiModelProperty() readonly password: string;
}
@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  root(): string {
    return this.appService.root();
  }

  @Post()
  async test(@Req() request, @Body() body: TestBody) {}
}

tsconfig.json file:

{
  "compilerOptions": {
    "lib": ["es6"],
    "module": "commonjs",
    "declaration": true,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./src"
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}
kamilmysliwiec commented 6 years ago

Why would you like to target es5 when Nest is compiled to es6?

nodren commented 6 years ago

when using typescript client side via ts-loader & webpack, need to target es5 for browser compatibility.

my work around was to have two different tsconfig files, one webpack listens to, and another nest listens to

kamilmysliwiec commented 6 years ago
my work around was to have two different tsconfig files, one webpack listens to, and another nest listens to

This is the only possible solution actually.

patrickhousley commented 6 years ago

@kamilmysliwiec Would you please please please make note of this in the README.md. I just spent hours debugging Nest to find that the issue was caused by the target in the tsconfig. It is pretty common for angular/nest repos to have a target of es5 in the root of the project.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.