diff --git a/examples/todo-list/src/controllers/todo-list-todo.controller.ts b/examples/todo-list/src/controllers/todo-list-todo.controller.ts index 0dffa4b3de3e..8e697dd7ae9a 100644 --- a/examples/todo-list/src/controllers/todo-list-todo.controller.ts +++ b/examples/todo-list/src/controllers/todo-list-todo.controller.ts @@ -13,33 +13,68 @@ export class TodoListTodoController { @repository(TodoListRepository) protected todoListRepo: TodoListRepository, ) {} - @post('/todo-lists/{id}/todos') - async create(@param.path.number('id') id: number, @requestBody() todo: Todo) { + @post('/todo-lists/{id}/todos', { + responses: { + '200': { + description: 'TodoList.Todo model instance', + content: {'application/json': {'x-ts-type': Todo}}, + }, + }, + }) + async create( + @param.path.number('id') id: number, + @requestBody() todo: Todo, + ): Promise { return await this.todoListRepo.todos(id).create(todo); } - @get('/todo-lists/{id}/todos') + @get('/todo-lists/{id}/todos', { + responses: { + '200': { + description: "Array of Todo's belonging to TodoList", + content: { + 'application/json': { + schema: {type: 'array', items: {'x-ts-type': Todo}}, + }, + }, + }, + }, + }) async find( @param.path.number('id') id: number, @param.query.string('filter') filter?: Filter, - ) { + ): Promise { return await this.todoListRepo.todos(id).find(filter); } - @patch('/todo-lists/{id}/todos') + @patch('/todo-lists/{id}/todos', { + responses: { + '200': { + description: 'TodoList.Todo PATCH success count', + content: {'application/json': {'x-ts-type': Number}}, + }, + }, + }) async patch( @param.path.number('id') id: number, @requestBody() todo: Partial, @param.query.string('where') where?: Where, - ) { + ): Promise { return await this.todoListRepo.todos(id).patch(todo, where); } - @del('/todo-lists/{id}/todos') + @del('/todo-lists/{id}/todos', { + responses: { + '200': { + description: 'TodoList.Todo DELETE success count', + content: {'application/json': {'x-ts-type': Number}}, + }, + }, + }) async delete( @param.path.number('id') id: number, @param.query.string('where') where?: Where, - ) { + ): Promise { return await this.todoListRepo.todos(id).delete(where); } } diff --git a/examples/todo-list/src/controllers/todo-list.controller.ts b/examples/todo-list/src/controllers/todo-list.controller.ts index 8cc1231010b8..c3f33ae12d00 100644 --- a/examples/todo-list/src/controllers/todo-list.controller.ts +++ b/examples/todo-list/src/controllers/todo-list.controller.ts @@ -14,24 +14,52 @@ export class TodoListController { public todoListRepository: TodoListRepository, ) {} - @post('/todo-lists') + @post('/todo-lists', { + responses: { + '200': { + description: 'TodoList model instance', + content: {'application/json': {'x-ts-type': TodoList}}, + }, + }, + }) async create(@requestBody() obj: TodoList): Promise { return await this.todoListRepository.create(obj); } - @get('/todo-lists/count') + @get('/todo-lists/count', { + responses: { + '200': { + description: 'TodoList model count', + content: {'application/json': {'x-ts-type': Number}}, + }, + }, + }) async count(@param.query.string('where') where?: Where): Promise { return await this.todoListRepository.count(where); } - @get('/todo-lists') + @get('/todo-lists', { + responses: { + '200': { + description: 'Array of TodoList model instances', + content: {'application/json': {'x-ts-type': TodoList}}, + }, + }, + }) async find( @param.query.string('filter') filter?: Filter, ): Promise { return await this.todoListRepository.find(filter); } - @patch('/todo-lists') + @patch('/todo-lists', { + responses: { + '200': { + description: 'TodoList PATCH success count', + content: {'application/json': {'x-ts-type': Number}}, + }, + }, + }) async updateAll( @requestBody() obj: Partial, @param.query.string('where') where?: Where, @@ -39,12 +67,26 @@ export class TodoListController { return await this.todoListRepository.updateAll(obj, where); } - @get('/todo-lists/{id}') + @get('/todo-lists/{id}', { + responses: { + '200': { + description: 'TodoList model instance', + content: {'application/json': {'x-ts-type': TodoList}}, + }, + }, + }) async findById(@param.path.number('id') id: number): Promise { return await this.todoListRepository.findById(id); } - @patch('/todo-lists/{id}') + @patch('/todo-lists/{id}', { + responses: { + '200': { + description: 'TodoList PATCH success', + content: {'application/json': {'x-ts-type': Boolean}}, + }, + }, + }) async updateById( @param.path.number('id') id: number, @requestBody() obj: TodoList, @@ -52,7 +94,14 @@ export class TodoListController { return await this.todoListRepository.updateById(id, obj); } - @del('/todo-lists/{id}') + @del('/todo-lists/{id}', { + responses: { + '200': { + description: 'TodoList DELETE success', + content: {'application/json': {'x-ts-type': Boolean}}, + }, + }, + }) async deleteById(@param.path.number('id') id: number): Promise { return await this.todoListRepository.deleteById(id); } diff --git a/examples/todo-list/src/controllers/todo.controller.ts b/examples/todo-list/src/controllers/todo.controller.ts index bdd8a506e39f..87c878002f9f 100644 --- a/examples/todo-list/src/controllers/todo.controller.ts +++ b/examples/todo-list/src/controllers/todo.controller.ts @@ -11,12 +11,26 @@ import {TodoRepository} from '../repositories'; export class TodoController { constructor(@repository(TodoRepository) protected todoRepo: TodoRepository) {} - @post('/todos') + @post('/todos', { + responses: { + '200': { + description: 'Todo model instance', + content: {'application/json': {'x-ts-type': Todo}}, + }, + }, + }) async createTodo(@requestBody() todo: Todo) { return await this.todoRepo.create(todo); } - @get('/todos/{id}') + @get('/todos/{id}', { + responses: { + '200': { + description: 'Todo model instance', + content: {'application/json': {'x-ts-type': Todo}}, + }, + }, + }) async findTodoById( @param.path.number('id') id: number, @param.query.boolean('items') items?: boolean, @@ -24,12 +38,30 @@ export class TodoController { return await this.todoRepo.findById(id); } - @get('/todos') + @get('/todos', { + responses: { + '200': { + description: 'Array of Todo model instances', + content: { + 'application/json': { + schema: {type: 'array', items: {'x-ts-type': Todo}}, + }, + }, + }, + }, + }) async findTodos(): Promise { return await this.todoRepo.find(); } - @put('/todos/{id}') + @put('/todos/{id}', { + responses: { + '200': { + description: 'Todo PUT success', + content: {'application/json': {'x-ts-type': Boolean}}, + }, + }, + }) async replaceTodo( @param.path.number('id') id: number, @requestBody() todo: Todo, @@ -37,7 +69,14 @@ export class TodoController { return await this.todoRepo.replaceById(id, todo); } - @patch('/todos/{id}') + @patch('/todos/{id}', { + responses: { + '200': { + description: 'Todo PATCH success', + content: {'application/json': {'x-ts-type': Boolean}}, + }, + }, + }) async updateTodo( @param.path.number('id') id: number, @requestBody() todo: Todo, @@ -45,7 +84,14 @@ export class TodoController { return await this.todoRepo.updateById(id, todo); } - @del('/todos/{id}') + @del('/todos/{id}', { + responses: { + '200': { + description: 'Todo DELETE success', + content: {'application/json': {'x-ts-type': Boolean}}, + }, + }, + }) async deleteTodo(@param.path.number('id') id: number): Promise { return await this.todoRepo.deleteById(id); }