Skip to content

Commit

Permalink
Merge pull request #47 from epiphone/class-validator-0.12
Browse files Browse the repository at this point in the history
Support class-validator v0.12
  • Loading branch information
epiphone authored May 4, 2020
2 parents addba0b + 355c846 commit 81bfab5
Show file tree
Hide file tree
Showing 13 changed files with 1,824 additions and 1,503 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
sudo: false
language: node_js
node_js:
- 8
- 12
script:
- yarn test:format
- yarn lint
- yarn test
cache: yarn
notifications:
email: false
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [2.0.0-rc1] - 2020-05-01
### Changed
- Bump `class-validator` peer dependency to `^0.12.0` - meaning we're no longer compatible with pre-0.12 versions of `class-validator`!

## [1.8.1] - 2020-04-10
### Fixed
- Restored the mistakenly removed `tslib` dependency [#42](https://github.com/epiphone/routing-controllers-openapi/issues/42)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ import { validationMetadatasToSchemas } from 'class-validator-jsonschema'
// ...
const schemas = validationMetadatasToSchemas(metadatas, {
const schemas = validationMetadatasToSchemas({
refPointerPrefix: '#/components/schemas/'
})
Expand Down
5 changes: 1 addition & 4 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// tslint:disable:no-implicit-dependencies no-submodule-imports
import { defaultMetadataStorage } from 'class-transformer/storage'
import { getFromContainer, MetadataStorage } from 'class-validator'
import { validationMetadatasToSchemas } from 'class-validator-jsonschema'
import * as _ from 'lodash'
import { getMetadataArgsStorage } from 'routing-controllers'
Expand Down Expand Up @@ -30,9 +29,7 @@ const routes = parseRoutes(storage, options)
describe('index', () => {
it('generates an OpenAPI spec from routing-controllers metadata', () => {
// Include component schemas parsed with class-validator-jsonschema:
const metadatas = (getFromContainer(MetadataStorage) as any)
.validationMetadatas
const schemas = validationMetadatasToSchemas(metadatas, {
const schemas = validationMetadatasToSchemas({
classTransformerMetadataStorage: defaultMetadataStorage,
refPointerPrefix: '#/components/schemas/'
})
Expand Down
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "routing-controllers-openapi",
"version": "1.8.1",
"version": "2.0.0-rc1",
"description": "Runtime OpenAPI v3 spec generation for routing-controllers",
"keywords": [
"routing-controllers",
Expand All @@ -17,8 +17,9 @@
"clean": "rimraf coverage build",
"build": "yarn clean && tsc -p tsconfig.release.json",
"format": "prettier --write {src,test}/**/*.ts",
"test:format": "prettier --check {src,test}/**/*.ts",
"lint": "tslint --project . src/**/*.ts",
"prepare": "install-self-peers -- --ignore-scripts && yarn build",
"prepare": "install-self-peers -- --frozen-lockfile --ignore-scripts && yarn build",
"send-coverage": "codecov -f coverage/*.json",
"test": "jest --coverage",
"test:watch": "jest --watch"
Expand All @@ -36,24 +37,24 @@
},
"devDependencies": {
"@team-griffin/install-self-peers": "^1.1.1",
"@types/jest": "^24.0.23",
"@types/lodash": "^4.14.149",
"@types/node": "^12.12.14",
"@types/prettier": "^1.19.0",
"@types/jest": "^25.2.1",
"@types/lodash": "^4.14.150",
"@types/node": "^13.13.4",
"@types/prettier": "^2.0.0",
"@types/reflect-metadata": "^0.1.0",
"@types/rimraf": "^2.0.3",
"@types/rimraf": "^3.0.0",
"class-transformer": "^0.2.3",
"class-validator": "^0.11.0",
"class-validator-jsonschema": "^1.3.0",
"class-validator": "^0.12.2",
"class-validator-jsonschema": "^2.0.0-rc1",
"codecov": "^3.6.1",
"jest": "^24.9.0",
"prettier": "^1.19.1",
"rimraf": "^3.0.0",
"ts-jest": "^24.2.0",
"tslint": "^5.20.1",
"jest": "^25.5.3",
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"ts-jest": "^25.4.0",
"tslint": "^6.1.2",
"tslint-config-prettier": "^1.18.0",
"tslint-config-standard": "^9.0.0",
"typescript": "^3.7.2"
"typescript": "^3.8.3"
},
"peerDependencies": {
"routing-controllers": "^0.8.0"
Expand Down
4 changes: 1 addition & 3 deletions sample/01-basic/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'reflect-metadata'
import { getFromContainer, MetadataStorage } from 'class-validator' // tslint:disable-line
import { validationMetadatasToSchemas } from 'class-validator-jsonschema'
import { Express } from 'express'
import {
Expand All @@ -17,8 +16,7 @@ const routingControllersOptions = {
const app: Express = createExpressServer(routingControllersOptions)

// Parse class-validator classes into JSON Schema:
const metadatas = (getFromContainer(MetadataStorage) as any).validationMetadatas
const schemas = validationMetadatasToSchemas(metadatas, {
const schemas = validationMetadatasToSchemas({
refPointerPrefix: '#/components/schemas/'
})

Expand Down
6 changes: 3 additions & 3 deletions sample/01-basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"class-validator": "^0.11.0",
"class-validator-jsonschema": "^1.3.0",
"class-validator": "^0.12.2",
"class-validator-jsonschema": "^2.0.0-rc1",
"express": "^4.16.3",
"reflect-metadata": "^0.1.13",
"routing-controllers": "^0.8.0",
"routing-controllers": "^0.8.1",
"routing-controllers-openapi": "../.."
},
"devDependencies": {
Expand Down
76 changes: 37 additions & 39 deletions sample/01-basic/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@
"@types/express-serve-static-core" "*"
"@types/mime" "*"

"@types/validator@10.11.3":
version "10.11.3"
resolved "https://registry.yarnpkg.com/@types/validator/-/validator-10.11.3.tgz#945799bef24a953c5bc02011ca8ad79331a3ef25"
"@types/validator@13.0.0":
version "13.0.0"
resolved "https://registry.yarnpkg.com/@types/validator/-/validator-13.0.0.tgz#365f1bf936aeaddd0856fc41aa1d6f82d88ee5b3"
integrity sha512-WAy5txG7aFX8Vw3sloEKp5p/t/Xt8jD3GRD9DacnFv6Vo8ubudAsRTXgxpQwU0mpzY/H8U4db3roDuCMjShBmw==

abbrev@1:
version "1.1.1"
Expand Down Expand Up @@ -293,23 +294,25 @@ class-utils@^0.3.5:
isobject "^3.0.0"
static-extend "^0.1.1"

class-validator-jsonschema@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/class-validator-jsonschema/-/class-validator-jsonschema-1.3.0.tgz#d47d777e7721816acbc61271bf5bf56ef665a3f5"
class-validator-jsonschema@^2.0.0-rc1:
version "2.0.0-rc1"
resolved "https://registry.yarnpkg.com/class-validator-jsonschema/-/class-validator-jsonschema-2.0.0-rc1.tgz#80d608b3f1d0b045a9498eed022a54d5cb7cdf16"
integrity sha512-GhHHCUMX8WgGvZWx1GnV64grlJdS2NCD7NMuNfG7HC5W0oGFofjHVmh70wESoqbYkgmfSyyQ7LEN1eSjH+SwZQ==
dependencies:
debug "^4.1.1"
lodash "^4.17.11"
lodash "^4.17.15"
openapi3-ts "^1.3.0"
reflect-metadata "^0.1.13"
tslib "^1.10.0"
tslib "^1.11.1"

class-validator@^0.11.0:
version "0.11.0"
resolved "https://registry.yarnpkg.com/class-validator/-/class-validator-0.11.0.tgz#5fca8b8a957c738a6749391e03ee81fad375dc4a"
class-validator@^0.12.2:
version "0.12.2"
resolved "https://registry.yarnpkg.com/class-validator/-/class-validator-0.12.2.tgz#2ceb72f88873e9c714cf5f9c278cbc71f6f6c8ef"
integrity sha512-TDzPzp8BmpsbPhQpccB3jMUE/3pK0TyqamrK0kcx+ZeFytMA+O6q87JZZGObHHnoo9GM8vl/JppIyKWeEA/EVw==
dependencies:
"@types/validator" "10.11.3"
google-libphonenumber "^3.1.6"
validator "12.0.0"
"@types/validator" "13.0.0"
google-libphonenumber "^3.2.8"
tslib ">=1.9.0"
validator "13.0.0"

cli-boxes@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -417,12 +420,6 @@ debug@^3.1.0:
dependencies:
ms "2.0.0"

debug@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
dependencies:
ms "^2.1.1"

decode-uri-component@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
Expand Down Expand Up @@ -717,9 +714,10 @@ global-dirs@^0.1.0:
dependencies:
ini "^1.3.4"

google-libphonenumber@^3.1.6:
version "3.2.2"
resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.2.tgz#3d9d7ba727e99a50812f21b0ed313723b76c5c54"
google-libphonenumber@^3.2.8:
version "3.2.8"
resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.8.tgz#fb5898cbae18104d456e0fd80df52d860a3eb2b8"
integrity sha512-iWs1KcxOozmKQbCeGjvU0M7urrkNjBYOSBtb819RjkUNJHJLfn7DADKkKwdJTOMPLcLOE11/4h/FyFwJsTiwLg==

got@^6.7.1:
version "6.7.1"
Expand Down Expand Up @@ -1030,7 +1028,7 @@ lodash.debounce@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"

lodash@^4.17.11, lodash@^4.17.15:
lodash@^4.17.15:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"

Expand Down Expand Up @@ -1153,10 +1151,6 @@ ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"

ms@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"

nan@^2.9.2:
version "2.10.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f"
Expand Down Expand Up @@ -1524,16 +1518,18 @@ rimraf@^2.6.1:
glob "^7.0.5"

routing-controllers-openapi@../..:
version "1.7.0"
version "1.8.1"
dependencies:
lodash "^4.17.15"
openapi3-ts "^1.3.0"
path-to-regexp "^2.2.1"
reflect-metadata "^0.1.13"
tslib "^1.11.1"

routing-controllers@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/routing-controllers/-/routing-controllers-0.8.0.tgz#91574e1537ab5e9f293615401f62c49dc4dfb315"
routing-controllers@^0.8.1:
version "0.8.1"
resolved "https://registry.yarnpkg.com/routing-controllers/-/routing-controllers-0.8.1.tgz#d53c35e05d0f0863ee25bd77c3fe41fc09fa39f5"
integrity sha512-dOgt0kiriKMH1swenPX73tU3Mxvlb+1N/sFLSgEpwbK314POrQF+dJGOZVoKv2ya5do1k4aUzSV5xi0K3ykdyw==
dependencies:
cookie "^0.4.0"
glob "^7.1.4"
Expand Down Expand Up @@ -1830,9 +1826,10 @@ touch@^3.1.0:
dependencies:
nopt "~1.0.10"

tslib@^1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
tslib@>=1.9.0, tslib@^1.11.1:
version "1.11.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.11.1.tgz#eb15d128827fbee2841549e171f45ed338ac7e35"
integrity sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==

type-is@~1.6.15, type-is@~1.6.16:
version "1.6.16"
Expand Down Expand Up @@ -1922,9 +1919,10 @@ utils-merge@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"

validator@12.0.0:
version "12.0.0"
resolved "https://registry.yarnpkg.com/validator/-/validator-12.0.0.tgz#fb33221f5320abe2422cda2f517dc3838064e813"
validator@13.0.0:
version "13.0.0"
resolved "https://registry.yarnpkg.com/validator/-/validator-13.0.0.tgz#0fb6c6bb5218ea23d368a8347e6d0f5a70e3bcab"
integrity sha512-anYx5fURbgF04lQV18nEQWZ/3wHGnxiKdG4aL8J+jEDsm98n/sU/bey+tYk6tnGJzm7ioh5FoqrAiQ6m03IgaA==

vary@~1.1.2:
version "1.1.2"
Expand Down
14 changes: 7 additions & 7 deletions src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
OperationObject,
ReferenceObject,
ResponsesObject,
SchemaObject
SchemaObject,
} from 'openapi3-ts'
import 'reflect-metadata'

Expand Down Expand Up @@ -49,7 +49,7 @@ export function applyOpenAPIDecorator(
const { action } = route
const openAPIParams = [
...getOpenAPIMetadata(action.target),
...getOpenAPIMetadata(action.target.prototype, action.method)
...getOpenAPIMetadata(action.target.prototype, action.method),
]

return openAPIParams.reduce((acc: OperationObject, oaParam: OpenAPIParam) => {
Expand Down Expand Up @@ -110,7 +110,7 @@ export function ResponseSchema(

if (responseSchemaName) {
const reference: ReferenceObject = {
$ref: `#/components/schemas/${responseSchemaName}`
$ref: `#/components/schemas/${responseSchemaName}`,
}
const schema: SchemaObject = isArray
? { items: reference, type: 'array' }
Expand All @@ -119,11 +119,11 @@ export function ResponseSchema(
[statusCode]: {
content: {
[contentType]: {
schema
}
schema,
},
},
description
}
description,
},
}

return _.merge({}, source, { responses })
Expand Down
Loading

0 comments on commit 81bfab5

Please sign in to comment.