1
1
'use strict' ;
2
2
3
- import { Path , Server , GET , POST , PUT , DELETE , HttpMethod ,
4
- PathParam , QueryParam , CookieParam , HeaderParam ,
5
- FormParam , Param , Context , ServiceContext , ContextRequest ,
6
- ContextResponse , ContextLanguage , ContextAccept ,
7
- ContextNext , AcceptLanguage , Accept , FileParam ,
8
- Errors , Return , BodyOptions } from 'typescript-rest' ;
3
+ import {
4
+ Path , Server , GET , POST , PUT , DELETE , HttpMethod ,
5
+ PathParam , QueryParam , CookieParam , HeaderParam ,
6
+ FormParam , Param , Context , ServiceContext , ContextRequest ,
7
+ ContextResponse , ContextLanguage , ContextAccept ,
8
+ ContextNext , AcceptLanguage , Accept , FileParam ,
9
+ Errors , Return , BodyOptions
10
+ } from 'typescript-rest' ;
9
11
10
12
import * as swagger from '../../src/decorators' ;
11
13
@@ -27,13 +29,13 @@ export class MyService {
27
29
@swagger . Response < string > ( 500 , 'There was an unexpected error.' )
28
30
@GET
29
31
@Accept ( 'text/html' )
30
- test ( ) : string {
32
+ test ( ) : string {
31
33
return 'OK' ;
32
34
}
33
35
34
36
/**
35
- * Esta eh a da classe
36
- * @param test Esta eh a description do param teste
37
+ * This is the method description
38
+ * @param test This is the test param description
37
39
*/
38
40
@GET
39
41
@Path ( 'secondpath' )
@@ -42,11 +44,11 @@ export class MyService {
42
44
} )
43
45
@swagger . Response < Person > ( 200 , 'The success test.' )
44
46
test2 (
45
- @QueryParam ( 'testRequired' ) test : string ,
46
- @QueryParam ( 'testDefault' ) test2 : string = 'value' ,
47
- @QueryParam ( 'testOptional' ) test3 ?: string
47
+ @QueryParam ( 'testRequired' ) test : string ,
48
+ @QueryParam ( 'testDefault' ) test2 : string = 'value' ,
49
+ @QueryParam ( 'testOptional' ) test3 ?: string
48
50
) : Person {
49
- return { name : 'OK' } ;
51
+ return { name : 'OK' } ;
50
52
}
51
53
52
54
@POST
@@ -88,7 +90,7 @@ export class MyService {
88
90
class BaseService {
89
91
@DELETE
90
92
@Path ( ':id' )
91
- testDelete ( @PathParam ( 'id' ) id : string ) : Promise < void > {
93
+ testDelete ( @PathParam ( 'id' ) id : string ) : Promise < void > {
92
94
return new Promise < void > ( ( resolve , reject ) => {
93
95
resolve ( ) ;
94
96
} ) ;
@@ -103,9 +105,9 @@ export class PromiseService extends BaseService {
103
105
*/
104
106
@swagger . Response < string > ( 401 , 'Unauthorized' )
105
107
@GET
106
- test ( @QueryParam ( 'testParam' ) test ?: string ) : Promise < Person > {
108
+ test ( @QueryParam ( 'testParam' ) test ?: string ) : Promise < Person > {
107
109
return new Promise < Person > ( ( resolve , reject ) => {
108
- resolve ( { name : 'OK' } ) ;
110
+ resolve ( { name : 'OK' } ) ;
109
111
} ) ;
110
112
}
111
113
@@ -114,7 +116,7 @@ export class PromiseService extends BaseService {
114
116
@swagger . Example < Person > ( { name : 'Test Person' } )
115
117
@GET
116
118
@Path ( ':id' )
117
- testGetSingle ( @PathParam ( 'id' ) id : string ) : Promise < Person > {
119
+ testGetSingle ( @PathParam ( 'id' ) id : string ) : Promise < Person > {
118
120
return new Promise < Person > ( ( resolve , reject ) => {
119
121
resolve ( { name : 'OK' } ) ;
120
122
} ) ;
@@ -124,27 +126,27 @@ export class PromiseService extends BaseService {
124
126
@swagger . Response < string > ( 401 , 'Unauthorized' )
125
127
@swagger . Example < Person > ( { name : 'Example Person' } ) // NOTE: this is here to test that it doesn't overwrite the example in the @Response above
126
128
@POST
127
- testPost ( obj : Person ) : Promise < Return . NewResource < Person > > {
129
+ testPost ( obj : Person ) : Promise < Return . NewResource < Person > > {
128
130
return new Promise < Return . NewResource < Person > > ( ( resolve , reject ) => {
129
- resolve ( new Return . NewResource < Person > ( 'id' , { name : 'OK' } ) ) ;
131
+ resolve ( new Return . NewResource < Person > ( 'id' , { name : 'OK' } ) ) ;
130
132
} ) ;
131
133
}
132
134
133
135
@GET
134
136
@Path ( 'myFile' )
135
137
@swagger . Produces ( 'application/pdf' )
136
- testFile ( @QueryParam ( 'testParam' ) test ?: string ) : Promise < Return . DownloadBinaryData > {
138
+ testFile ( @QueryParam ( 'testParam' ) test ?: string ) : Promise < Return . DownloadBinaryData > {
137
139
return new Promise < Return . DownloadBinaryData > ( ( resolve , reject ) => {
138
140
resolve ( null ) ;
139
141
} ) ;
140
142
}
141
143
}
142
144
143
145
export class BasicModel {
144
- id : number ;
146
+ id : number ;
145
147
}
146
148
147
- export class BasicEndpoint < T extends BasicModel > {
149
+ export class BasicEndpoint < T extends BasicModel > {
148
150
149
151
protected list ( @QueryParam ( 'full' ) full ?: boolean ) : Promise < Array < T > > {
150
152
return new Promise ( ( resolve , reject ) => {
@@ -194,7 +196,7 @@ export class DerivedEndpoint extends BasicEndpoint<MyDatatype> {
194
196
@GET
195
197
@Path ( ':param' )
196
198
protected test ( @PathParam ( 'param' ) param : string ) : Promise < void > {
197
- return new Promise < void > ( ( resolve , reject ) => {
199
+ return new Promise < void > ( ( resolve , reject ) => {
198
200
// content
199
201
} ) ;
200
202
}
@@ -214,7 +216,7 @@ export class DerivedEndpoint2 {
214
216
@GET
215
217
@Path ( ':param' )
216
218
protected test ( @PathParam ( 'param' ) param : string ) : Promise < MyDatatype2 > {
217
- return new Promise < MyDatatype2 > ( ( resolve , reject ) => {
219
+ return new Promise < MyDatatype2 > ( ( resolve , reject ) => {
218
220
// content
219
221
} ) ;
220
222
}
@@ -251,7 +253,7 @@ export class TypeEndpoint {
251
253
@GET
252
254
@Path ( ':param' )
253
255
test ( @PathParam ( 'param' ) param : string ) : Promise < SimpleHelloType > {
254
- return new Promise < MyDatatype2 > ( ( resolve , reject ) => {
256
+ return new Promise < MyDatatype2 > ( ( resolve , reject ) => {
255
257
// content
256
258
} ) ;
257
259
}
@@ -324,7 +326,7 @@ export class ParameterizedEndpoint {
324
326
325
327
@Path ( '/test' )
326
328
@GET
327
- test ( @PathParam ( 'objectId' ) objectId : string ) : PrimitiveClassModel {
329
+ test ( @PathParam ( 'objectId' ) objectId : string ) : PrimitiveClassModel {
328
330
return new PrimitiveClassModel ( ) ;
329
331
}
330
332
}
0 commit comments