swagger: [Regression] Swagger generates empty schemas

I’m submitting a…

  • Regression
  • Bug report
  • Feature request
  • Documentation issue or request
  • Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

All swagger schemas are empty and contain no information at all.

empty-schemas

Expected behavior

Documentation detailing the property types on schemas should be inferred from the typescript definitions as described here and here. Like so:

image

Minimal reproduction of the problem with instructions

Reproduction: https://github.com/robertmain/meal-plan/tree/update-swagger

Instructions:

  1. Download the app from the link above (the branch is important!) 1 Install the dependencies and navigate to localhost:3000/api (yeah, I know it’s a crappy URL scheme…I’m working on it)

What is the motivation / use case for changing the behavior?

Empty API documentation isn’t very useful…? 🤔

Environment

Nest version: 6.6.4

For Tooling issues:

  • Node version: 10.16.3
  • Platform: Debian Linux 9

Others:

Contents of nest-cli.json

{
  "language": "ts",
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "compilerOptions": {
    "plugins": ["@nestjs/swagger/plugin"]
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 37 (5 by maintainers)

Most upvoted comments

@robertmain Did you solved after build through webpack?

My project already using nest build but I have same issue as you

Entire project has latest nest modules but it dosen’t work… My global version of nest/cli and typescript are same as follows’ devDependencies

Here’s my package.json I’m sorry about not being able to provide reproduction repo, it’s a company project.

Same for me. Newest Nest Version using newest cli with nest new, added the plugin to nest-cli.json and it produces empty models. I’m using docker, but I’m also copying the nest-cli.json into that container

UPDATE:

Please bury me alive, I did’nt use .dto.ts files (yet) but .type.ts files. I had to adjust the “dtoFileNameSuffix” therefore. Now it’s working for me!

I’m encountering the same issue. If I don’t add @ApiProperty() the prop will not show up in the schema.

Using version 4.1.2

I’ve downgraded back to 4.0.9, which seems to work as described in the docs for now.

Yeah, String in typescript refers to the String.prototype object…not an actual string 😉

I didn’t get any further yet, no. I’ve kinda set that problem to one side until one of the framework developers chips in here with some insight. Right now I’m trying to get serve-static working with webpack hot reloading.

When I get to it, sure. I’ll post it in here

On Thu, Jan 9, 2020, 10:10 Hwan-seok notifications@github.com wrote:

@robertmain https://github.com/robertmain No problem, could you tell me the result after test?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nestjs/swagger/issues/459?email_source=notifications&email_token=AAEDIVHYQCS4HCPCQLBGDQLQ4446TA5CNFSM4KAQRPM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIQT4JQ#issuecomment-572603942, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEDIVHS4ZBZNXQ45WKHWKDQ4446TANCNFSM4KAQRPMQ .

@Hwan-seok I haven’t had chance to test it yet, sorry.

@robertmain Did you solved after build through webpack?

My project already using nest build but I have same issue as you

Entire project has latest nest modules but it dosen’t work… My global version of nest/cli and typescript are same as follows’ devDependencies

Here's my package.json
{
  "name": "serving",
  "version": "0.0.3",
  "nginx_version": "0.0.1",
  "description": "",
  "author": "",
  "license": "MIT",
  "scripts": {
    "prebuild": "rimraf dist",
    "build": "nest build --watch --webpack",
    "build:prod": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "node dist/main",
    "loc": "START /B npm run build && npm start",
    "doc": "cross-env NODE_ENV=local npm run build",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main",
    "lint": "tslint -p tsconfig.json -c tslint.json",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json",
    "dkr:build": "docker build -t node . & cd docker.nginx && docker build -t nginx .",
    "dkr:node": "docker rm -f node && docker run -it --name node --net nginx-node node",
    "dkr:nginx": "docker rm -f nginx && docker run -it --name nginx -p 80:80 --net nginx-node nginx"
  },
  "dependencies": {
    "@hapi/joi": "^16.1.8",
    "@nestjs/common": "^6.10.14",
    "@nestjs/core": "^6.10.14",
    "@nestjs/jwt": "^6.1.1",
    "@nestjs/passport": "^6.1.1",
    "@nestjs/platform-express": "^6.10.14",
    "@nestjs/swagger": "^4.1.7",
    "bcrypt": "^3.0.7",
    "class-transformer": "^0.2.3",
    "class-validator": "^0.11.0",
    "csurf": "^1.10.0",
    "deep-equal": "^2.0.1",
    "dotenv": "^8.2.0",
    "helmet": "^3.21.2",
    "mysql2": "^2.1.0",
    "nodemailer": "^6.4.2",
    "passport": "^0.4.1",
    "passport-jwt": "^4.0.0",
    "passport-local": "^1.0.0",
    "qs": "^6.9.1",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.0",
    "rxjs": "^6.5.3",
    "sequelize": "^5.21.3",
    "sequelize-typescript": "^1.1.0",
    "shortid": "^2.2.15",
    "swagger-ui-express": "^4.1.2"
  },
  "devDependencies": {
    "@nestjs/cli": "^6.13.2",
    "@nestjs/schematics": "^6.7.0",
    "@nestjs/testing": "^6.7.1",
    "@types/express": "^4.17.1",
    "@types/jest": "^24.0.18",
    "@types/node": "^12.7.5",
    "@types/passport-local": "^1.0.33",
    "@types/sequelize": "^4.28.8",
    "@types/supertest": "^2.0.8",
    "cross-env": "^6.0.3",
    "jest": "^24.9.0",
    "prettier": "^1.18.2",
    "supertest": "^4.0.2",
    "ts-jest": "^24.1.0",
    "ts-loader": "^6.1.1",
    "ts-node": "^8.4.1",
    "tsconfig-paths": "^3.9.0",
    "tslint": "^5.20.0",
    "typescript": "^3.7.4",
    "webpack-node-externals": "^1.7.2",
    "webpack-shell-plugin": "^0.5.0"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".spec.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}


I’m sorry about not being able to provide reproduction repo, it’s a company project.

would I be correct in saying that nest-cli.json is just a superset of tsconfig.json?

Not exactly. Here you can find a breakdown of all the available CLI properties: https://docs.nestjs.com/cli/monorepo#cli-properties. Both files serve a slightly different purpose. To better understand what nest build is doing, you can read this short explanation https://docs.nestjs.com/cli/scripts#build