Skip to content

Commit

Permalink
fix: use parameter level decorators for openapi params
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Feb 5, 2018
1 parent 22f8e05 commit c29dd19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
32 changes: 19 additions & 13 deletions packages/example-getting-started/src/controllers/todo.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ export class TodoController {
@repository(TodoRepository.name) protected todoRepo: TodoRepository,
) {}
@post('/todo')
@param.body('todo', TodoSchema)
async createTodo(todo: Todo) {
async createTodo(
@param.body('todo', TodoSchema)
todo: Todo,
) {
// TODO(bajtos) This should be handled by the framework
// See https://github.com/strongloop/loopback-next/issues/118
if (!todo.title) {
Expand All @@ -23,9 +25,10 @@ export class TodoController {
}

@get('/todo/{id}')
@param.path.number('id')
@param.query.boolean('items')
async findTodoById(id: number, items?: boolean): Promise<Todo> {
async findTodoById(
@param.path.number('id') id: number,
@param.query.boolean('items') items?: boolean,
): Promise<Todo> {
return await this.todoRepo.findById(id);
}

Expand All @@ -35,22 +38,25 @@ export class TodoController {
}

@put('/todo/{id}')
@param.path.number('id')
@param.body('todo', TodoSchema)
async replaceTodo(id: number, todo: Todo): Promise<boolean> {
async replaceTodo(
@param.path.number('id') id: number,
@param.body('todo', TodoSchema)
todo: Todo,
): Promise<boolean> {
return await this.todoRepo.replaceById(id, todo);
}

@patch('/todo/{id}')
@param.path.number('id')
@param.body('todo', TodoSchema)
async updateTodo(id: number, todo: Todo): Promise<boolean> {
async updateTodo(
@param.path.number('id') id: number,
@param.body('todo', TodoSchema)
todo: Todo,
): Promise<boolean> {
return await this.todoRepo.updateById(id, todo);
}

@del('/todo/{id}')
@param.path.number('id')
async deleteTodo(id: number): Promise<boolean> {
async deleteTodo(@param.path.number('id') id: number): Promise<boolean> {
return await this.todoRepo.deleteById(id);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {createClientForHandler, expect, supertest} from '@loopback/testlab';
import {RestServer} from '@loopback/rest';
import {TodoApplication} from '../../src/application';
import {TodoRepository} from '../../src/repositories/index';
import {TodoRepository} from '../../src/repositories/';
import {givenTodo} from '../helpers';
import {Todo} from '../../src/models/index';
import {Todo} from '../../src/models/';

describe('Application', () => {
let app: TodoApplication;
Expand Down

0 comments on commit c29dd19

Please sign in to comment.