Skip to content

Commit c29dd19

Browse files
committed
fix: use parameter level decorators for openapi params
1 parent 22f8e05 commit c29dd19

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

packages/example-getting-started/src/controllers/todo.controller.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ export class TodoController {
1212
@repository(TodoRepository.name) protected todoRepo: TodoRepository,
1313
) {}
1414
@post('/todo')
15-
@param.body('todo', TodoSchema)
16-
async createTodo(todo: Todo) {
15+
async createTodo(
16+
@param.body('todo', TodoSchema)
17+
todo: Todo,
18+
) {
1719
// TODO(bajtos) This should be handled by the framework
1820
// See https://github.com/strongloop/loopback-next/issues/118
1921
if (!todo.title) {
@@ -23,9 +25,10 @@ export class TodoController {
2325
}
2426

2527
@get('/todo/{id}')
26-
@param.path.number('id')
27-
@param.query.boolean('items')
28-
async findTodoById(id: number, items?: boolean): Promise<Todo> {
28+
async findTodoById(
29+
@param.path.number('id') id: number,
30+
@param.query.boolean('items') items?: boolean,
31+
): Promise<Todo> {
2932
return await this.todoRepo.findById(id);
3033
}
3134

@@ -35,22 +38,25 @@ export class TodoController {
3538
}
3639

3740
@put('/todo/{id}')
38-
@param.path.number('id')
39-
@param.body('todo', TodoSchema)
40-
async replaceTodo(id: number, todo: Todo): Promise<boolean> {
41+
async replaceTodo(
42+
@param.path.number('id') id: number,
43+
@param.body('todo', TodoSchema)
44+
todo: Todo,
45+
): Promise<boolean> {
4146
return await this.todoRepo.replaceById(id, todo);
4247
}
4348

4449
@patch('/todo/{id}')
45-
@param.path.number('id')
46-
@param.body('todo', TodoSchema)
47-
async updateTodo(id: number, todo: Todo): Promise<boolean> {
50+
async updateTodo(
51+
@param.path.number('id') id: number,
52+
@param.body('todo', TodoSchema)
53+
todo: Todo,
54+
): Promise<boolean> {
4855
return await this.todoRepo.updateById(id, todo);
4956
}
5057

5158
@del('/todo/{id}')
52-
@param.path.number('id')
53-
async deleteTodo(id: number): Promise<boolean> {
59+
async deleteTodo(@param.path.number('id') id: number): Promise<boolean> {
5460
return await this.todoRepo.deleteById(id);
5561
}
5662
}

packages/example-getting-started/test/acceptance/application.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {createClientForHandler, expect, supertest} from '@loopback/testlab';
22
import {RestServer} from '@loopback/rest';
33
import {TodoApplication} from '../../src/application';
4-
import {TodoRepository} from '../../src/repositories/index';
4+
import {TodoRepository} from '../../src/repositories/';
55
import {givenTodo} from '../helpers';
6-
import {Todo} from '../../src/models/index';
6+
import {Todo} from '../../src/models/';
77

88
describe('Application', () => {
99
let app: TodoApplication;

0 commit comments

Comments
 (0)