Skip to content

Commit 654f49f

Browse files
author
Thiago Bustamante
committed
lint tests
1 parent 9c15a48 commit 654f49f

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

test/data/apis.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
'use strict';
22

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';
911

1012
import * as swagger from '../../src/decorators';
1113

@@ -27,13 +29,13 @@ export class MyService {
2729
@swagger.Response<string>(500, 'There was an unexpected error.')
2830
@GET
2931
@Accept('text/html')
30-
test( ): string {
32+
test(): string {
3133
return 'OK';
3234
}
3335

3436
/**
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
3739
*/
3840
@GET
3941
@Path('secondpath')
@@ -42,11 +44,11 @@ export class MyService {
4244
})
4345
@swagger.Response<Person>(200, 'The success test.')
4446
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
4850
): Person {
49-
return {name: 'OK'};
51+
return { name: 'OK' };
5052
}
5153

5254
@POST
@@ -88,7 +90,7 @@ export class MyService {
8890
class BaseService {
8991
@DELETE
9092
@Path(':id')
91-
testDelete( @PathParam('id')id: string): Promise<void> {
93+
testDelete(@PathParam('id') id: string): Promise<void> {
9294
return new Promise<void>((resolve, reject) => {
9395
resolve();
9496
});
@@ -103,9 +105,9 @@ export class PromiseService extends BaseService {
103105
*/
104106
@swagger.Response<string>(401, 'Unauthorized')
105107
@GET
106-
test( @QueryParam('testParam')test?: string ): Promise<Person> {
108+
test(@QueryParam('testParam') test?: string): Promise<Person> {
107109
return new Promise<Person>((resolve, reject) => {
108-
resolve({name: 'OK'});
110+
resolve({ name: 'OK' });
109111
});
110112
}
111113

@@ -114,7 +116,7 @@ export class PromiseService extends BaseService {
114116
@swagger.Example<Person>({ name: 'Test Person' })
115117
@GET
116118
@Path(':id')
117-
testGetSingle( @PathParam('id') id: string ): Promise<Person> {
119+
testGetSingle(@PathParam('id') id: string): Promise<Person> {
118120
return new Promise<Person>((resolve, reject) => {
119121
resolve({ name: 'OK' });
120122
});
@@ -124,27 +126,27 @@ export class PromiseService extends BaseService {
124126
@swagger.Response<string>(401, 'Unauthorized')
125127
@swagger.Example<Person>({ name: 'Example Person' }) // NOTE: this is here to test that it doesn't overwrite the example in the @Response above
126128
@POST
127-
testPost( obj: Person ): Promise<Return.NewResource<Person>> {
129+
testPost(obj: Person): Promise<Return.NewResource<Person>> {
128130
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' }));
130132
});
131133
}
132134

133135
@GET
134136
@Path('myFile')
135137
@swagger.Produces('application/pdf')
136-
testFile( @QueryParam('testParam')test?: string ): Promise<Return.DownloadBinaryData> {
138+
testFile(@QueryParam('testParam') test?: string): Promise<Return.DownloadBinaryData> {
137139
return new Promise<Return.DownloadBinaryData>((resolve, reject) => {
138140
resolve(null);
139141
});
140142
}
141143
}
142144

143145
export class BasicModel {
144-
id: number;
146+
id: number;
145147
}
146148

147-
export class BasicEndpoint <T extends BasicModel> {
149+
export class BasicEndpoint<T extends BasicModel> {
148150

149151
protected list(@QueryParam('full') full?: boolean): Promise<Array<T>> {
150152
return new Promise((resolve, reject) => {
@@ -194,7 +196,7 @@ export class DerivedEndpoint extends BasicEndpoint<MyDatatype> {
194196
@GET
195197
@Path(':param')
196198
protected test(@PathParam('param') param: string): Promise<void> {
197-
return new Promise<void>((resolve, reject)=> {
199+
return new Promise<void>((resolve, reject) => {
198200
// content
199201
});
200202
}
@@ -214,7 +216,7 @@ export class DerivedEndpoint2 {
214216
@GET
215217
@Path(':param')
216218
protected test(@PathParam('param') param: string): Promise<MyDatatype2> {
217-
return new Promise<MyDatatype2>((resolve, reject)=> {
219+
return new Promise<MyDatatype2>((resolve, reject) => {
218220
// content
219221
});
220222
}
@@ -251,7 +253,7 @@ export class TypeEndpoint {
251253
@GET
252254
@Path(':param')
253255
test(@PathParam('param') param: string): Promise<SimpleHelloType> {
254-
return new Promise<MyDatatype2>((resolve, reject)=> {
256+
return new Promise<MyDatatype2>((resolve, reject) => {
255257
// content
256258
});
257259
}
@@ -324,7 +326,7 @@ export class ParameterizedEndpoint {
324326

325327
@Path('/test')
326328
@GET
327-
test(@PathParam('objectId')objectId: string): PrimitiveClassModel {
329+
test(@PathParam('objectId') objectId: string): PrimitiveClassModel {
328330
return new PrimitiveClassModel();
329331
}
330332
}

test/unit/definitions.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ describe('Definition generation', () => {
4444
expect(expression.evaluate(spec)).to.eq(false);
4545
});
4646

47+
it('should generate description for methods and paraemters', () => {
48+
let expression = jsonata('paths."/mypath/secondpath".get.parameters[0].description');
49+
expect(expression.evaluate(spec)).to.eq('This is the test param description');
50+
expression = jsonata('paths."/mypath/secondpath".get.description');
51+
expect(expression.evaluate(spec)).to.eq('This is the method description');
52+
});
53+
4754
it('should support multiple response decorators', () => {
4855
let expression = jsonata('paths."/mypath".get.responses."400".description');
4956
expect(expression.evaluate(spec)).to.eq('The request format was incorrect.');
@@ -282,7 +289,7 @@ describe('Definition generation', () => {
282289
it('should generate path param for params declared on class', () => {
283290
const expression = jsonata('paths."/parameterized/{objectId}/test".get.parameters[0].in');
284291
expect(expression.evaluate(spec)).to.eq('path');
285-
});
292+
});
286293
});
287294

288295
describe('AbstractEntityEndpoint', () => {

0 commit comments

Comments
 (0)