diff --git a/docs/site/Controller-generator.md b/docs/site/Controller-generator.md index c85964c21685..1251e29cc0fb 100644 --- a/docs/site/Controller-generator.md +++ b/docs/site/Controller-generator.md @@ -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, @@ -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)}}, }, }, }) @@ -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, - ): Promise { + ): Promise { return await this.todoRepository.count(where); } @@ -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)}, }, }, }, @@ -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}}, }, }, }) @@ -187,7 +194,7 @@ export class TodoController { }) todo: Partial @param.query.object('where', getWhereSchemaFor(Todo)) where?: Where, - ): Promise { + ): Promise { return await this.todoRepository.updateAll(todo, where); } @@ -195,7 +202,7 @@ export class TodoController { responses: { '200': { description: 'Todo model instance', - content: {'application/json': {schema: {'x-ts-type': Todo}}}, + content: {'application/json': {schema: getModelSchemaRef(Todo)}}, }, }, }) diff --git a/docs/site/Loopback-component-authorization.md b/docs/site/Loopback-component-authorization.md index 76e949ca81b2..668c5245390c 100644 --- a/docs/site/Loopback-component-authorization.md +++ b/docs/site/Loopback-component-authorization.md @@ -463,6 +463,7 @@ export class User extends Entity { import {inject} from '@loopback/context'; import { FindRoute, + getModelSchemaRef, InvokeMethod, ParseParams, Reject, @@ -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)}}, }, }, }, diff --git a/docs/site/Sequence.md b/docs/site/Sequence.md index a753502562c5..bb01e440c29b 100644 --- a/docs/site/Sequence.md +++ b/docs/site/Sequence.md @@ -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)}}, }, }, }) diff --git a/docs/site/tutorials/todo-list/todo-list-tutorial-controller.md b/docs/site/tutorials/todo-list/todo-list-tutorial-controller.md index b6e65a04cc7c..272ce55c18b9 100644 --- a/docs/site/tutorials/todo-list/todo-list-tutorial-controller.md +++ b/docs/site/tutorials/todo-list/todo-list-tutorial-controller.md @@ -209,6 +209,7 @@ import { import { del, get, + getModelSchemaRef, getWhereSchemaFor, param, patch, @@ -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)}}, }, }, }) @@ -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)}, }, }, }, diff --git a/examples/express-composition/src/controllers/note.controller.ts b/examples/express-composition/src/controllers/note.controller.ts index 8d582082019e..7d9e899e9f20 100644 --- a/examples/express-composition/src/controllers/note.controller.ts +++ b/examples/express-composition/src/controllers/note.controller.ts @@ -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)}}, }, }, }) @@ -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)}, }, }, }, @@ -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)}}, }, }, }) diff --git a/examples/todo-list/src/controllers/todo-list-image.controller.ts b/examples/todo-list/src/controllers/todo-list-image.controller.ts index dc764934e3a7..84ad6a0d3ece 100644 --- a/examples/todo-list/src/controllers/todo-list-image.controller.ts +++ b/examples/todo-list/src/controllers/todo-list-image.controller.ts @@ -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)}, + }, }, }, }) 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 3244d735f327..851dc69111a7 100644 --- a/examples/todo-list/src/controllers/todo-list-todo.controller.ts +++ b/examples/todo-list/src/controllers/todo-list-todo.controller.ts @@ -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)}}, }, }, }) @@ -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)}, }, }, }, diff --git a/examples/todo-list/src/controllers/todo-list.controller.ts b/examples/todo-list/src/controllers/todo-list.controller.ts index 2cf514ae478f..d6d42f1fe38f 100644 --- a/examples/todo-list/src/controllers/todo-list.controller.ts +++ b/examples/todo-list/src/controllers/todo-list.controller.ts @@ -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)}}, }, }, }) diff --git a/examples/todo-list/src/controllers/todo.controller.ts b/examples/todo-list/src/controllers/todo.controller.ts index fbd30ac8dd96..a907257b8a67 100644 --- a/examples/todo-list/src/controllers/todo.controller.ts +++ b/examples/todo-list/src/controllers/todo.controller.ts @@ -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)}}, }, }, }) @@ -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)}}, }, }, }) diff --git a/examples/todo/src/controllers/todo.controller.ts b/examples/todo/src/controllers/todo.controller.ts index 05039e9334b9..94e9391005de 100644 --- a/examples/todo/src/controllers/todo.controller.ts +++ b/examples/todo/src/controllers/todo.controller.ts @@ -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)}}, }, }, }) @@ -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)}}, }, }, }) @@ -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)}, }, }, }, diff --git a/packages/cli/generators/relation/templates/controller-relation-template-belongs-to.ts.ejs b/packages/cli/generators/relation/templates/controller-relation-template-belongs-to.ts.ejs index 163125b499b2..92b492dc4c1d 100644 --- a/packages/cli/generators/relation/templates/controller-relation-template-belongs-to.ts.ejs +++ b/packages/cli/generators/relation/templates/controller-relation-template-belongs-to.ts.ejs @@ -4,7 +4,7 @@ import { import { param, get, - getModelSchemaRef + getModelSchemaRef, } from '@loopback/rest'; import { <%= sourceModelClassName %>,