Skip to content

Commit 5654bfa

Browse files
routing-controllers@0.9.0, class-transformer@0.4.0 (#72)
* fix: fix compatibility with routing-controllers 0.9 * class-validator v0.13.1 * Temporary class-validator-jsonschema bump * Upgrade sample project deps * class-validator-jsonschema v3.0.0 Co-authored-by: miguel costa <miguelcostaparedes@gmail.com>
1 parent 91a4ec5 commit 5654bfa

File tree

10 files changed

+656
-4231
lines changed

10 files changed

+656
-4231
lines changed

__tests__/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// tslint:disable:no-implicit-dependencies no-submodule-imports
2-
import { defaultMetadataStorage } from 'class-transformer/storage'
2+
const { defaultMetadataStorage } = require('class-transformer/cjs/storage')
33
import { validationMetadatasToSchemas } from 'class-validator-jsonschema'
44
import * as _ from 'lodash'
55
import { getMetadataArgsStorage } from 'routing-controllers'

__tests__/parameters.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
import { SchemaObject } from 'openapi3-ts'
2121
import { validationMetadatasToSchemas } from 'class-validator-jsonschema'
2222
import { IsBoolean, IsNumber, IsOptional, IsString } from 'class-validator'
23-
import { defaultMetadataStorage } from 'class-transformer/storage'
23+
const { defaultMetadataStorage } = require('class-transformer/cjs/storage')
2424

2525
describe('parameters', () => {
2626
let route: IRoute

package-lock.json

Lines changed: 24 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
"@types/prettier": "^2.2.2",
4444
"@types/reflect-metadata": "^0.1.0",
4545
"@types/rimraf": "^3.0.0",
46-
"class-transformer": "0.3.1",
47-
"class-validator": "^0.12.2",
48-
"class-validator-jsonschema": "^2.2.0",
46+
"class-transformer": "^0.4.0",
47+
"class-validator": "^0.13.1",
48+
"class-validator-jsonschema": "^3.0.0",
4949
"codecov": "^3.8.1",
5050
"jest": "^26.6.3",
5151
"prettier": "^2.2.1",
@@ -57,6 +57,6 @@
5757
"typescript": "^4.2.3"
5858
},
5959
"peerDependencies": {
60-
"routing-controllers": "^0.8.0"
60+
"routing-controllers": "^0.9.0"
6161
}
6262
}

sample/01-basic/UsersController.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
Put,
1717
QueryParams,
1818
} from 'routing-controllers'
19-
import { OpenAPI } from 'routing-controllers-openapi'
19+
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'
2020

2121
class Child {
2222
@IsString()
@@ -39,6 +39,14 @@ class CreateUserBody {
3939
children: Child[]
4040
}
4141

42+
class UserResponse {
43+
@IsString()
44+
name: string
45+
46+
@IsString({ each: true })
47+
hobbies: string[]
48+
}
49+
4250
class PaginationQuery {
4351
@IsNumber()
4452
@IsPositive()
@@ -56,6 +64,7 @@ class PaginationQuery {
5664
export class UsersController {
5765
@Get('/')
5866
@OpenAPI({ summary: 'Return a list of users' })
67+
@ResponseSchema(UserResponse, { isArray: true })
5968
getAll(@QueryParams() query: PaginationQuery) {
6069
return [
6170
{ id: 1, name: 'First user!', hobbies: [] },
@@ -65,8 +74,9 @@ export class UsersController {
6574

6675
@Get('/:id')
6776
@OpenAPI({ summary: 'Return a single user' })
77+
@ResponseSchema(UserResponse)
6878
getOne(@Param('id') id: number) {
69-
return { name: 'User #' + id }
79+
return { name: 'User #' + id, hobbies: ['something'] }
7080
}
7181

7282
@Post('/')

sample/01-basic/app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import 'reflect-metadata'
2-
import { defaultMetadataStorage } from 'class-transformer/storage' // tslint:disable-line:no-submodule-imports
31
import { validationMetadatasToSchemas } from 'class-validator-jsonschema'
42
import { Express } from 'express'
3+
import 'reflect-metadata'
54
import {
65
createExpressServer,
76
getMetadataArgsStorage,
87
} from 'routing-controllers'
98
import { routingControllersToSpec } from 'routing-controllers-openapi'
109
import * as swaggerUiExpress from 'swagger-ui-express'
11-
1210
import { UsersController } from './UsersController'
1311

12+
const { defaultMetadataStorage } = require('class-transformer/cjs/storage')
13+
1414
const routingControllersOptions = {
1515
controllers: [UsersController],
1616
routePrefix: '/api',

0 commit comments

Comments
 (0)