Skip to content

Commit

Permalink
feat: update examples and docs to use getModelSchemaRef
Browse files Browse the repository at this point in the history
  • Loading branch information
nabdelgadir committed Jul 22, 2019
1 parent 4147619 commit 99758b1
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 25 deletions.
23 changes: 15 additions & 8 deletions docs/site/Controller-generator.md
Expand Up @@ -96,12 +96,19 @@ Here's an example of what the template will produce given a `Todo` model and a
`TodoRepository`:

```ts
import {Filter, repository, Where} from '@loopback/repository';
import {
Count,
CountSchema,
Filter,
repository,
Where
} from '@loopback/repository';
import {
post,
param,
get,
getFilterSchemaFor,
getModelSchemaRef,
getWhereSchemaFor,
patch,
del,
Expand All @@ -119,7 +126,7 @@ export class TodoController {
responses: {
'200': {
description: 'Todo model instance',
content: {'application/json': {schema: {'x-ts-type': Todo}}},
content: {'application/json': {schema: getModelSchemaRef(Todo)}},
},
},
})
Expand All @@ -140,13 +147,13 @@ export class TodoController {
responses: {
'200': {
description: 'Todo model count',
content: {'application/json': {schema: {'x-ts-type': Number}}},
content: {'application/json': {schema: CountSchema}},
},
},
})
async count(
@param.query.object('where', getWhereSchemaFor(Todo)) where?: Where<Todo>,
): Promise<number> {
): Promise<Count> {
return await this.todoRepository.count(where);
}

Expand All @@ -156,7 +163,7 @@ export class TodoController {
description: 'Array of Todo model instances',
content: {
'application/json': {
schema: {type: 'array', items: {'x-ts-type': Todo}},
schema: {type: 'array', items: getModelSchemaRef(Todo)},
},
},
},
Expand All @@ -173,7 +180,7 @@ export class TodoController {
responses: {
'200': {
description: 'Todo PATCH success count',
content: {'application/json': {schema: {'x-ts-type': Number}}},
content: {'application/json': {schema: CountSchema}},
},
},
})
Expand All @@ -187,15 +194,15 @@ export class TodoController {
})
todo: Partial<Todo>
@param.query.object('where', getWhereSchemaFor(Todo)) where?: Where<Todo>,
): Promise<number> {
): Promise<Count> {
return await this.todoRepository.updateAll(todo, where);
}

@get('/todos/{id}', {
responses: {
'200': {
description: 'Todo model instance',
content: {'application/json': {schema: {'x-ts-type': Todo}}},
content: {'application/json': {schema: getModelSchemaRef(Todo)}},
},
},
})
Expand Down
3 changes: 2 additions & 1 deletion docs/site/Loopback-component-authorization.md
Expand Up @@ -463,6 +463,7 @@ export class User extends Entity {
import {inject} from '@loopback/context';
import {
FindRoute,
getModelSchemaRef,
InvokeMethod,
ParseParams,
Reject,
Expand Down Expand Up @@ -535,7 +536,7 @@ decorator as below.
[STATUS_CODE.OK]: {
description: 'Role model instance',
content: {
[CONTENT_TYPE.JSON]: {schema: {'x-ts-type': Role}},
[CONTENT_TYPE.JSON]: {schema: getModelSchemaRef(Role)}},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion docs/site/Sequence.md
Expand Up @@ -231,7 +231,7 @@ from the path object.
responses: {
'200': {
description: 'Note model instance',
content: {'application/json': {schema: {'x-ts-type': Note}}},
content: {'application/json': {schema: getModelSchemaRef(Note)}},
},
},
})
Expand Down
Expand Up @@ -209,6 +209,7 @@ import {
import {
del,
get,
getModelSchemaRef,
getWhereSchemaFor,
param,
patch,
Expand All @@ -227,7 +228,7 @@ export class TodoListTodoController {
responses: {
'200': {
description: 'TodoList.Todo model instance',
content: {'application/json': {schema: {'x-ts-type': Todo}}},
content: {'application/json': {schema: getModelSchemaRef(Todo)}},
},
},
})
Expand All @@ -251,7 +252,7 @@ export class TodoListTodoController {
description: "Array of Todo's belonging to TodoList",
content: {
'application/json': {
schema: {type: 'array', items: {'x-ts-type': Todo}},
schema: {type: 'array', items: getModelSchemaRef(Todo)},
},
},
},
Expand Down
Expand Up @@ -35,7 +35,7 @@ export class NoteController {
responses: {
'200': {
description: 'Note model instance',
content: {'application/json': {schema: {'x-ts-type': Note}}},
content: {'application/json': {schema: getModelSchemaRef(Note)}},
},
},
})
Expand Down Expand Up @@ -72,7 +72,7 @@ export class NoteController {
description: 'Array of Note model instances',
content: {
'application/json': {
schema: {type: 'array', items: {'x-ts-type': Note}},
schema: {type: 'array', items: getModelSchemaRef(Note)},
},
},
},
Expand Down Expand Up @@ -111,7 +111,7 @@ export class NoteController {
responses: {
'200': {
description: 'Note model instance',
content: {'application/json': {schema: {'x-ts-type': Note}}},
content: {'application/json': {schema: getModelSchemaRef(Note)}},
},
},
})
Expand Down
Expand Up @@ -17,7 +17,9 @@ export class TodoListImageController {
responses: {
'200': {
description: 'create todoListImage model instance',
content: {'application/json': {schema: {'x-ts-type': TodoListImage}}},
content: {
'application/json': {schema: getModelSchemaRef(TodoListImage)},
},
},
},
})
Expand Down
Expand Up @@ -32,7 +32,7 @@ export class TodoListTodoController {
responses: {
'200': {
description: 'TodoList.Todo model instance',
content: {'application/json': {schema: {'x-ts-type': Todo}}},
content: {'application/json': {schema: getModelSchemaRef(Todo)}},
},
},
})
Expand All @@ -59,7 +59,7 @@ export class TodoListTodoController {
description: "Array of Todo's belonging to TodoList",
content: {
'application/json': {
schema: {type: 'array', items: {'x-ts-type': Todo}},
schema: {type: 'array', items: getModelSchemaRef(Todo)},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion examples/todo-list/src/controllers/todo-list.controller.ts
Expand Up @@ -34,7 +34,7 @@ export class TodoListController {
responses: {
'200': {
description: 'TodoList model instance',
content: {'application/json': {schema: {'x-ts-type': TodoList}}},
content: {'application/json': {schema: getModelSchemaRef(TodoList)}},
},
},
})
Expand Down
4 changes: 2 additions & 2 deletions examples/todo-list/src/controllers/todo.controller.ts
Expand Up @@ -25,7 +25,7 @@ export class TodoController {
responses: {
'200': {
description: 'Todo model instance',
content: {'application/json': {schema: {'x-ts-type': Todo}}},
content: {'application/json': {schema: getModelSchemaRef(Todo)}},
},
},
})
Expand Down Expand Up @@ -134,7 +134,7 @@ export class TodoController {
responses: {
'200': {
description: 'TodoList model instance',
content: {'application/json': {schema: {'x-ts-type': TodoList}}},
content: {'application/json': {schema: getModelSchemaRef(TodoList)}},
},
},
})
Expand Down
6 changes: 3 additions & 3 deletions examples/todo/src/controllers/todo.controller.ts
Expand Up @@ -30,7 +30,7 @@ export class TodoController {
responses: {
'200': {
description: 'Todo model instance',
content: {'application/json': {schema: {'x-ts-type': Todo}}},
content: {'application/json': {schema: getModelSchemaRef(Todo)}},
},
},
})
Expand Down Expand Up @@ -60,7 +60,7 @@ export class TodoController {
responses: {
'200': {
description: 'Todo model instance',
content: {'application/json': {schema: {'x-ts-type': Todo}}},
content: {'application/json': {schema: getModelSchemaRef(Todo)}},
},
},
})
Expand All @@ -77,7 +77,7 @@ export class TodoController {
description: 'Array of Todo model instances',
content: {
'application/json': {
schema: {type: 'array', items: {'x-ts-type': Todo}},
schema: {type: 'array', items: getModelSchemaRef(Todo)},
},
},
},
Expand Down
Expand Up @@ -4,7 +4,7 @@ import {
import {
param,
get,
getModelSchemaRef
getModelSchemaRef,
} from '@loopback/rest';
import {
<%= sourceModelClassName %>,
Expand Down

0 comments on commit 99758b1

Please sign in to comment.