Skip to content

Update routing-controllers class-validator dependency to latest (0.9.1) #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rmuchall opened this issue Jul 24, 2018 · 15 comments
Closed
Labels
status: awaiting answer Awaiting answer from the author of issue or PR.

Comments

@rmuchall
Copy link

rmuchall commented Jul 24, 2018

Please could you update the class-validator dependency to the latest version (0.9.1)?
If I use the latest version (0.9.1) and routing-controllers is still using the older version (0.8.5) then oddities occur as described in this issue by @NoNameProvided
typestack/class-validator#166

EDIT: should class-validator be a peer dependency?

As always, thanks for your awesome efforts guys :)

@MardariG
Copy link

MardariG commented Aug 2, 2018

Last publish 5 months ago, it seems abandoned.

@acuntex
Copy link

acuntex commented Aug 15, 2018

I hope not, since it's quite the best framework to get some architecture to the nodejs mess for bigger projects.

@MichalLytek
Copy link
Contributor

MichalLytek commented Aug 15, 2018

I have access to master branch but no access to npm to publish package.

So last year when I created the PR #315, I published it as @19majkel94/routing-controllers 😉
As routing-controllers has great build script, you can easily just fork the master, make your changes, change the package name and then just npx gulp package and npm publish in build/package folder 🎉

@FSM1
Copy link

FSM1 commented Nov 8, 2018

@19majkel94 I tried doing the same (created my own routing-controllers package on npm), and after npm dedupe I now only have one version of class-validator installed in the project (0.9.1), but I am still getting the error message about no metadata. Any suggestions on what else I can try?

@FSM1
Copy link

FSM1 commented Nov 8, 2018

@MardariG will give it a try... are you using your version as part of the TypeORM stack?

@MardariG
Copy link

MardariG commented Nov 8, 2018

@MardariG will give it a try... are you using your version as part of the TypeORM stack?

Sorry I deleted the comment, didn't noticed 19majkel94 has published already another version;

https://www.npmjs.com/package/@mardari/routing-controllers

Yes, I'm using it in https://github.com/w3tecch/express-typescript-boilerplate boilerplate, as with official version validation of @Body is not working.

@FSM1
Copy link

FSM1 commented Nov 8, 2018

@MardariG I had also done the exact same with my package, and now I have replaced with your version of Routing-Controllers and I still get the metadata error log and no validation happens.

Yes, I'm using it in https://github.com/w3tecch/express-typescript-boilerplate boilerplate, as with official version validation of @Body is not working.

I am using the exact same boilerplate and not having any luck with the validation. Any ideas what else I could look at?

I have checked the app's node_modules, and there is only one version of class-validator in the root of the app's node_modules. I have also checked Routing-Controllers folder and there is definitely not a copy of class-validator in there. Im running out of ideas here.

@MardariG
Copy link

MardariG commented Nov 8, 2018

FSM1 can you share your error trace?

@FSM1
Copy link

FSM1 commented Nov 9, 2018

@MardariG not getting any errors. I just get a console log from class-validator that no metadata has been found, and a response of an empty ValidationErrors array, even though the request is invalid.

    @Post()
    @HttpCode(201)
    public async create(@Body({validate: true}) user: User): Promise<User> {
        this.log.info('Validating request');
        const valid = validateSync(user);
        console.log(valid);
   ......

the following is logged to console when executing:

No metadata found. There is more than once class-validator version installed probably. You
 need to flatten your dependencies.
info: [api:controllers\UserController] Validating request
No metadata found. There is more than once class-validator version installed probably. You
 need to flatten your dependencies.
[]

@MardariG
Copy link

MardariG commented Nov 9, 2018

FSM1 can you share your package.json also ?

@FSM1
Copy link

FSM1 commented Nov 9, 2018

{
  "name": "MoleculeRestApiServer",
  "version": "1.0.0",
  "description": "Molecule API server built using NodeJS, MongoDb, Mongoose, Typegoose",
  "main": "src/app.ts",
  "scripts": {
    "start": "nps",
    "test": "npm start test",
    "build": "npm start build",
    "presetup": "yarn install",
    "setup": "npm start config && npm start setup.script"
  },
  "engines": {
    "node": ">=8.0.0"
  },
  "keywords": [
    "NodeJS",
    "TypeScript",
    "express",
    "boilerplate",
    "skeleton",
    "starter-kit",
    "mongoose"
  ],
  "homepage": "https://gitlab.com/linumlabs/molecule-sandbox/Api",
  "author": "Linum Labs - Michael Yankelev",
  "dependencies": {
    "@mardari/routing-controllers": "^0.7.9",
    "bcrypt": "3.0.1",
    "body-parser": "^1.18.2",
    "chalk": "^2.3.0",
    "class-validator": "0.9.1",
    "commander": "^2.11.0",
    "compression": "^1.7.1",
    "copyfiles": "^2.0.0",
    "cors": "^2.8.4",
    "dataloader": "^1.3.0",
    "dotenv": "6.0.0",
    "event-dispatch": "^0.4.1",
    "express": "^4.16.2",
    "express-basic-auth": "^1.1.3",
    "express-graphql": "^0.6.11",
    "express-status-monitor": "^1.0.1",
    "figlet": "^1.2.0",
    "glob": "^7.1.2",
    "graphql": "^0.13.0",
    "helmet": "^3.9.0",
    "jsonfile": "5.0.0",
    "jsonwebtoken": "^8.3.0",
    "lodash": "^4.17.4",
    "microframework-w3tec": "^0.6.3",
    "mongodb-uri": "^0.9.7",
    "mongoose": "^5.3.4",
    "mongoose-lean-virtuals": "^0.3.1",
    "morgan": "^1.9.0",
    "nodemon": "^1.12.1",
    "nps": "^5.7.1",
    "nps-utils": "^1.5.0",
    "path": "^0.12.7",
    "reflect-metadata": "^0.1.10",
    "request": "^2.83.0",
    "serve-favicon": "^2.4.5",
    "supertest": "^3.0.0",
    "swagger-ui-express": "4.0.1",
    "ts-node": "7.0.1",
    "tslint": "^5.8.0",
    "typedi": "0.8.0",
    "typegoose": "^5.4.1",
    "typescript": "3.0.3",
    "uuid": "^3.3.2",
    "winston": "3.1.0"
  },
  "jest": {
    "transform": {
      ".(ts|tsx)": "<rootDir>/test/preprocessor.js"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "json"
    ],
    "testEnvironment": "node",
    "setupTestFrameworkScriptFile": "./test/unit/lib/setup.ts"
  },
  "license": "MIT",
  "devDependencies": {
    "@types/bcrypt": "^2.0.0",
    "@types/bluebird": "^3.5.18",
    "@types/body-parser": "^1.16.7",
    "@types/cors": "^2.8.1",
    "@types/dotenv": "^4.0.2",
    "@types/express": "^4.0.39",
    "@types/faker": "^4.1.2",
    "@types/figlet": "^1.2.0",
    "@types/helmet": "0.0.41",
    "@types/jest": "23.3.2",
    "@types/jsonwebtoken": "^7.2.8",
    "@types/lodash": "^4.14.80",
    "@types/mongoose": "^5.2.19",
    "@types/morgan": "^1.7.35",
    "@types/nock": "^9.1.3",
    "@types/request": "^2.0.8",
    "@types/serve-favicon": "^2.2.29",
    "@types/supertest": "^2.0.4",
    "@types/uuid": "^3.4.3",
    "cross-env": "^5.1.1",
    "faker": "^4.1.0",
    "jest": "23.6.0",
    "mock-express-request": "^0.2.0",
    "mock-express-response": "^0.2.1",
    "nock": "10.0.0",
    "ts-jest": "23.10.1"
  }
}

@MardariG
Copy link

MardariG commented Nov 9, 2018

FSM1 Strange, using this https://github.com/w3tecch/express-typescript-boilerplate template, all I have to change is replacing official routing-controllers with mine @mardari/routing-controllers .
That's it, and @Body() is validated. Maybe there is a problem with models maybe other settings idk.

You can clone a clean project and see what is different from yours.

@FSM1
Copy link

FSM1 commented Nov 9, 2018

I have changed quite a bit from the original boilerplate (ripped out TypeORM and using Mongoose + Typegoose instead).

Class-validator should be quite agnostic to that though. I am using other annotations throughout the project without issue.

Think I am just going to give up on the W3tecch boilerplate and move on over to Nest.js, hopefully with a lot less issues and a bit more support.

thanks for the help @MardariG

@github-actions
Copy link

github-actions bot commented Feb 9, 2020

Stale issue message

@github-actions github-actions bot added the status: awaiting answer Awaiting answer from the author of issue or PR. label Feb 9, 2020
@github-actions
Copy link

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: awaiting answer Awaiting answer from the author of issue or PR.
Development

No branches or pull requests

5 participants