Skip to content

Commit d76cac7

Browse files
committed
- Fixed server
1 parent 4834c4f commit d76cac7

17 files changed

+262
-68
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
"test:update": "jest --updateSnapshot",
5454
"test:watch": "jest --watch",
5555
"test:coverage": "jest --coverage",
56-
"eslint": "eslint \"./src/**/*.{js,ts}\" \"./test/**/*.{js,ts}\" \"./bin/index.js\"",
57-
"eslint:fix": "eslint \"./src/**/*.{js,ts}\" \"./test/**/*.{js,ts}\" \"./bin/index.js\" --fix",
58-
"prettier": "prettier \"./src/**/*.{js,ts}\" \"./test/**/*.{js,ts}\" \"./bin/index.js\" --check",
59-
"prettier:fix": "prettier \"./src/**/*.{js,ts}\" \"./test/**/*.{js,ts}\" \"./bin/index.js\" --write",
56+
"eslint": "eslint \"./src/**/*.ts\" \"./test/**/*.ts\" \"./bin/index.js\"",
57+
"eslint:fix": "eslint \"./src/**/*.ts\" \"./test/**/*.ts\" \"./bin/index.js\" --fix",
58+
"prettier": "prettier \"./src/**/*.ts\" \"./test/**/*.ts\" \"./bin/index.js\" --check",
59+
"prettier:fix": "prettier \"./src/**/*.ts\" \"./test/**/*.ts\" \"./bin/index.js\" --write",
6060
"prepublish": "yarn run clean && yarn run release",
6161
"codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b"
6262
},

test/server/src/AppModule.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { Module } from '@nestjs/common';
22

3-
import { DefaultsController } from './controllers/DefaultsController';
43
import { ParametersController } from './controllers/ParametersController';
54
import { ResponseController } from './controllers/ResponseController';
65
import { SimpleController } from './controllers/SimpleController';
76

87
@Module({
9-
controllers: [SimpleController, ParametersController, DefaultsController, ResponseController],
8+
controllers: [SimpleController, ParametersController, ResponseController],
109
})
1110
export class AppModule {
1211
//

test/server/src/controllers/DefaultsController.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Controller, Get, Param } from '@nestjs/common';
1+
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
22
import { ApiResponse, ApiTags } from '@nestjs/swagger';
33

44
import { ModelWithString } from '../models/ModelWithString';
@@ -7,14 +7,72 @@ import { ModelWithString } from '../models/ModelWithString';
77
@ApiTags('parameters')
88
@Controller('parameters')
99
export class ParametersController {
10-
@Get('monkey')
10+
@Get('callWithParameters')
11+
public callWithParameters(
12+
@Param('parameterString') parameterString: string,
13+
@Param('parameterNumber') parameterNumber: number,
14+
@Param('parameterBoolean') parameterBoolean: boolean,
15+
@Param('parameterDictionary') parameterDictionary: Record<string, string>
16+
): any {
17+
return {
18+
parameterString,
19+
parameterNumber,
20+
parameterBoolean,
21+
parameterDictionary,
22+
};
23+
}
24+
25+
@Get('callWithWeirdParameterNames')
26+
public callWithWeirdParameterNames(
27+
@Param('parameter.1') parameter1: string,
28+
@Param('parameter-2') parameter2: string,
29+
@Param('parameter_3') parameter3: string,
30+
@Param('PARAMETER.4') parameter4: string,
31+
@Param('PARAMETER+5') parameter5: string,
32+
@Param('PARAMETER&6') parameter6: string
33+
): any {
34+
return {
35+
parameter1,
36+
parameter2,
37+
parameter3,
38+
parameter4,
39+
parameter5,
40+
parameter6,
41+
};
42+
}
43+
44+
@Get('callWithDefaultParameters')
1145
@ApiResponse({
1246
status: 200,
1347
type: ModelWithString,
1448
})
15-
monkey(@Param('id') id: string): ModelWithString {
49+
public callWithDefaultParameters(
50+
@Param('parameterNumberWithDefault') parameterNumberWithDefault: number = 123,
51+
@Param('parameterBooleanWithDefault') parameterBooleanWithDefault: boolean = true,
52+
@Param('parameterStringWithDefault') parameterStringWithDefault: string = 'Hello World!'
53+
): any {
1654
return {
17-
prop: 'Hello World!',
55+
parameterNumberWithDefault,
56+
parameterBooleanWithDefault,
57+
parameterStringWithDefault,
1858
};
1959
}
60+
61+
@Get('getCallWithBody')
62+
@ApiResponse({
63+
status: 200,
64+
type: ModelWithString,
65+
})
66+
public getCallWithBody(@Body() body: ModelWithString): ModelWithString {
67+
return body;
68+
}
69+
70+
@Post('postCallWithBody')
71+
@ApiResponse({
72+
status: 200,
73+
type: ModelWithString,
74+
})
75+
public postCallWithBody(@Body() body: ModelWithString): ModelWithString {
76+
return body;
77+
}
2078
}
Lines changed: 116 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,129 @@
1-
import { Controller, Get, Param } from '@nestjs/common';
1+
import { Controller, Get } from '@nestjs/common';
22
import { ApiResponse, ApiTags } from '@nestjs/swagger';
33

4+
import { ModelThatExtends } from '../models/ModelThatExtends';
5+
import { ModelThatExtendsExtends } from '../models/ModelThatExtendsExtends';
6+
import { ModelWithArray } from '../models/ModelWithArray';
7+
import { ModelWithBoolean } from '../models/ModelWithBoolean';
8+
import { ModelWithDictionary } from '../models/ModelWithDictionary';
9+
import { ModelWithInteger } from '../models/ModelWithInteger';
10+
import { ModelWithProperties } from '../models/ModelWithProperties';
11+
import { ModelWithReference } from '../models/ModelWithReference';
412
import { ModelWithString } from '../models/ModelWithString';
513

614
/* eslint-disable @typescript-eslint/no-unused-vars */
715
@ApiTags('response')
816
@Controller('response')
917
export class ResponseController {
10-
@Get('monkey')
11-
@ApiResponse({
12-
status: 200,
13-
type: ModelWithString,
14-
})
15-
monkey(@Param('id') id: string): ModelWithString {
18+
@Get('getString')
19+
@ApiResponse({ status: 200, type: String })
20+
public getString(): string {
21+
return 'Hello World!';
22+
}
23+
24+
@Get('getNumber')
25+
@ApiResponse({ status: 200, type: Number })
26+
public getNumber(): number {
27+
return 123;
28+
}
29+
30+
@Get('getBoolean')
31+
@ApiResponse({ status: 200, type: Boolean })
32+
public getBoolean(): boolean {
33+
return true;
34+
}
35+
36+
@Get('getModelWithString')
37+
@ApiResponse({ status: 200, type: ModelWithString })
38+
public getModelWithString(): ModelWithString {
1639
return {
1740
prop: 'Hello World!',
1841
};
1942
}
43+
44+
@Get('getModelWithInteger')
45+
@ApiResponse({ status: 200, type: ModelWithInteger })
46+
public getModelWithInteger(): ModelWithInteger {
47+
return {
48+
prop: 123,
49+
};
50+
}
51+
52+
@Get('getModelWithBoolean')
53+
@ApiResponse({ status: 200, type: ModelWithBoolean })
54+
public getModelWithBoolean(): ModelWithBoolean {
55+
return {
56+
prop: true,
57+
};
58+
}
59+
60+
@Get('getModelWithArray')
61+
@ApiResponse({ status: 200, type: ModelWithArray })
62+
public getModelWithArray(): ModelWithArray {
63+
return {
64+
prop: ['foo', 'bar'],
65+
};
66+
}
67+
68+
@Get('getModelWithDictionary')
69+
@ApiResponse({ status: 200, type: ModelWithDictionary })
70+
public getModelWithDictionary(): ModelWithDictionary {
71+
return {
72+
prop: {
73+
foo: 'bar',
74+
},
75+
};
76+
}
77+
78+
@Get('getModelWithReference')
79+
@ApiResponse({ status: 200, type: ModelWithReference })
80+
public getModelWithReference(): ModelWithReference {
81+
return {
82+
prop: {
83+
prop: 'Hello World!',
84+
},
85+
};
86+
}
87+
88+
@Get('getModelWithProperties')
89+
@ApiResponse({ status: 200, type: ModelWithProperties })
90+
public getModelWithProperties(): ModelWithProperties {
91+
return {
92+
string: 'Hello World!',
93+
number: 123,
94+
boolean: true,
95+
array: ['foo', 'bar'],
96+
dictionary: {
97+
foo: 'bar',
98+
},
99+
};
100+
}
101+
102+
@Get('getModelThatExtends')
103+
@ApiResponse({ status: 200, type: ModelThatExtends })
104+
public getModelThatExtends(): ModelThatExtends {
105+
return {
106+
prop: 'prop',
107+
propertyA: 'propertyA',
108+
propertyB: {
109+
prop: 'propertyB',
110+
},
111+
};
112+
}
113+
114+
@Get('getModelThatExtendsExtends')
115+
@ApiResponse({ status: 200, type: ModelThatExtendsExtends })
116+
public getModelThatExtendsExtends(): ModelThatExtendsExtends {
117+
return {
118+
prop: 'prop',
119+
propertyA: 'propertyA',
120+
propertyB: {
121+
prop: 'propertyB',
122+
},
123+
propertyC: 'propertyC',
124+
propertyD: {
125+
prop: 'propertyD',
126+
},
127+
};
128+
}
20129
}
Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
1-
import { Controller, Get, Param } from '@nestjs/common';
2-
import { ApiResponse, ApiTags } from '@nestjs/swagger';
3-
4-
import { ModelWithString } from '../models/ModelWithString';
1+
import { Controller, Delete, Get, Head, Options, Patch, Post, Put } from '@nestjs/common';
2+
import { ApiTags } from '@nestjs/swagger';
53

64
/* eslint-disable @typescript-eslint/no-unused-vars */
75
@ApiTags('simple')
86
@Controller('simple')
97
export class SimpleController {
10-
@Get('monkey')
11-
@ApiResponse({
12-
status: 200,
13-
type: ModelWithString,
14-
})
15-
monkey(@Param('id') id: string): ModelWithString {
16-
return {
17-
prop: 'Hello World!',
18-
};
8+
@Get('getCallWithoutParametersAndResponse')
9+
public getCallWithoutParametersAndResponse(): void {
10+
//
11+
}
12+
13+
@Put('putCallWithoutParametersAndResponse')
14+
public putCallWithoutParametersAndResponse(): void {
15+
//
16+
}
17+
18+
@Post('postCallWithoutParametersAndResponse')
19+
public postCallWithoutParametersAndResponse(): void {
20+
//
21+
}
22+
23+
@Delete('deleteCallWithoutParametersAndResponse')
24+
public deleteCallWithoutParametersAndResponse(): void {
25+
//
26+
}
27+
28+
@Options('optionsCallWithoutParametersAndResponse')
29+
public optionsCallWithoutParametersAndResponse(): void {
30+
//
31+
}
32+
33+
@Head('headCallWithoutParametersAndResponse')
34+
public headCallWithoutParametersAndResponse(): void {
35+
//
36+
}
37+
38+
@Patch('patchCallWithoutParametersAndResponse')
39+
public patchCallWithoutParametersAndResponse(): void {
40+
//
1941
}
2042
}

test/server/src/main.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
33

44
import { AppModule } from './AppModule';
55

6+
/**
7+
* This is a simple OpenAPI test server that we use to run e2e tests. You can find
8+
* more information inside the controllers and models of this server.
9+
* When you run this server the following urls are available:
10+
* - Swagger UI: http://localhost:3000/api
11+
* - Swagger Specification: http://localhost:3000/api-json
12+
*/
613
async function bootstrap(): Promise<void> {
714
const app = await NestFactory.create(AppModule);
815

9-
const options = new DocumentBuilder().setTitle('OpenAPI').setDescription('The OpenAPI description').setVersion('1.0').build();
16+
const options = new DocumentBuilder().setTitle('OpenAPI').setVersion('1.0').build();
1017

1118
const document = SwaggerModule.createDocument(app, options);
1219

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { ApiProperty } from '@nestjs/swagger';
22

3-
export class ModelThatExtends {
3+
import { ModelWithString } from './ModelWithString';
4+
5+
export class ModelThatExtends extends ModelWithString {
6+
@ApiProperty()
7+
public readonly propertyA?: string;
8+
49
@ApiProperty()
5-
prop?: number;
10+
public readonly propertyB?: ModelWithString;
611
}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { ApiProperty } from '@nestjs/swagger';
22

3-
export class ModelThatExtendsExtends {
3+
import { ModelThatExtends } from './ModelThatExtends';
4+
import { ModelWithString } from './ModelWithString';
5+
6+
export class ModelThatExtendsExtends extends ModelThatExtends {
7+
@ApiProperty()
8+
public readonly propertyC?: string;
9+
410
@ApiProperty()
5-
prop?: number;
11+
public readonly propertyD?: ModelWithString;
612
}

test/server/src/models/ModelWithArray.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { ApiProperty } from '@nestjs/swagger';
22

33
export class ModelWithArray {
44
@ApiProperty()
5-
prop?: number;
5+
public readonly prop?: string[];
66
}

0 commit comments

Comments
 (0)