How to use the @loopback/rest.getModelSchemaRef function in @loopback/rest

To help you get started, we’ve selected a few @loopback/rest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strongloop / loopback-next / examples / todo-list / src / controllers / todo-list-image.controller.ts View on Github external
import {repository} from '@loopback/repository';
import {get, getModelSchemaRef, param, post, requestBody} from '@loopback/rest';
import {TodoListImage} from '../models';
import {TodoListRepository} from '../repositories';

export class TodoListImageController {
  constructor(
    @repository(TodoListRepository) protected todoListRepo: TodoListRepository,
  ) {}

  @post('/todo-lists/{id}/image', {
    responses: {
      '200': {
        description: 'create todoListImage model instance',
        content: {
          'application/json': {schema: getModelSchemaRef(TodoListImage)},
        },
      },
    },
  })
  async create(
    @param.path.number('id') id: number,
    @requestBody() image: TodoListImage,
  ): Promise {
    return this.todoListRepo.image(id).create(image);
  }

  @get('/todo-lists/{id}/image', {
    responses: {
      '200': {
        description: 'The image belonging to the TodoList',
        content: {
github strongloop / loopback-next / examples / todo-list / src / controllers / todo-list-todo.controller.ts View on Github external
}),
        },
      },
    })
    todo: Omit,
  ): Promise {
    return this.todoListRepo.todos(id).create(todo);
  }

  @get('/todo-lists/{id}/todos', {
    responses: {
      '200': {
        description: "Array of Todo's belonging to TodoList",
        content: {
          'application/json': {
            schema: {type: 'array', items: getModelSchemaRef(Todo)},
          },
        },
      },
    },
  })
  async find(
    @param.path.number('id') id: number,
    @param.query.object('filter') filter?: Filter,
  ): Promise {
    return this.todoListRepo.todos(id).find(filter);
  }

  @patch('/todo-lists/{id}/todos', {
    responses: {
      '200': {
        description: 'TodoList.Todo PATCH success count',
github strongloop / loopback-next / examples / todo / src / controllers / model-admin.controller.ts View on Github external
if (!this.endpoints) this.endpoints = {};
  }
}

export class ModelAdminController {
  constructor(
    @inject(CoreBindings.APPLICATION_INSTANCE)
    private app: TodoListApplication,
  ) {}

  @post('/discover', {
    responses: {
      200: {
        description: 'Information about discovered models',
        content: {
          'application/json': {schema: getModelSchemaRef(DiscoverResponse)},
        },
      },
    },
  })
  async discoverAndPublishModels(
    @requestBody() {connectionString, tableNames}: DiscoverRequest,
  ): Promise {
    const result = new DiscoverResponse();

    const ds = await getDataSourceForConnectionString(
      this.app,
      connectionString,
    );

    for (const table of tableNames) {
      const basePath = await this.discoverAndPublish(ds, table);
github strongloop / loopback-next / packages / rest-crud / src / crud-rest.controller.ts View on Github external
export function model(
    statusCode: number,
    description: string,
    modelCtor: Function & {prototype: T},
    options?: JsonSchemaOptions,
  ) {
    return response(statusCode, description, {
      schema: getModelSchemaRef(modelCtor, options),
    });
  }
github strongloop / loopback-next / packages / rest-crud / src / crud-rest.controller.ts View on Github external
export function array(
    statusCode: number,
    description: string,
    modelCtor: Function & {prototype: T},
    options?: JsonSchemaOptions,
  ) {
    return response(statusCode, description, {
      schema: {
        type: 'array',
        items: getModelSchemaRef(modelCtor, options),
      },
    });
  }
}
github strongloop / loopback-next / examples / express-composition / src / controllers / note.controller.ts View on Github external
requestBody,
} from '@loopback/rest';
import {Note} from '../models';
import {NoteRepository} from '../repositories';

export class NoteController {
  constructor(
    @repository(NoteRepository)
    public noteRepository: NoteRepository,
  ) {}

  @post('/notes', {
    responses: {
      '200': {
        description: 'Note model instance',
        content: {'application/json': {schema: getModelSchemaRef(Note)}},
      },
    },
  })
  async create(
    @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Note, {title: 'NewNote', exclude: ['id']}),
        },
      },
    })
    note: Omit,
  ): Promise {
    return this.noteRepository.create(note);
  }
github strongloop / loopback-next / examples / todo-list / src / controllers / todo-list-todo.controller.ts View on Github external
post,
  requestBody,
} from '@loopback/rest';
import {Todo} from '../models';
import {TodoListRepository} from '../repositories';

export class TodoListTodoController {
  constructor(
    @repository(TodoListRepository) protected todoListRepo: TodoListRepository,
  ) {}

  @post('/todo-lists/{id}/todos', {
    responses: {
      '200': {
        description: 'TodoList.Todo model instance',
        content: {'application/json': {schema: getModelSchemaRef(Todo)}},
      },
    },
  })
  async create(
    @param.path.number('id') id: number,
    @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Todo, {
            title: 'NewTodoInTodoList',
            exclude: ['id'],
            optional: ['todoListId'],
          }),
        },
      },
    })
github strongloop / loopback-next / examples / todo-list / src / controllers / todo-list.controller.ts View on Github external
async count(
    @param.query.object('where', getWhereSchemaFor(TodoList))
    where?: Where,
  ): Promise {
    return this.todoListRepository.count(where);
  }

  @get('/todo-lists', {
    responses: {
      '200': {
        description: 'Array of TodoList model instances',
        content: {
          'application/json': {
            schema: {
              type: 'array',
              items: getModelSchemaRef(TodoList, {includeRelations: true}),
            },
          },
        },
      },
    },
  })
  async find(
    @param.query.object('filter', getFilterSchemaFor(TodoList))
    filter?: Filter,
  ): Promise {
    return this.todoListRepository.find(filter);
  }

  @patch('/todo-lists', {
    responses: {
      '200': {
github strongloop / loopback-next / packages / rest-crud / src / crud-rest.controller.ts View on Github external
function body(
  modelCtor: Function & {prototype: T},
  options?: JsonSchemaOptions,
) {
  return requestBody({
    content: {
      'application/json': {
        schema: getModelSchemaRef(modelCtor, options),
      },
    },
  });
}
github strongloop / loopback-next / examples / todo-list / src / controllers / todo.controller.ts View on Github external
patch,
  post,
  put,
  requestBody,
} from '@loopback/rest';
import {Todo, TodoList} from '../models';
import {TodoRepository} from '../repositories';

export class TodoController {
  constructor(@repository(TodoRepository) protected todoRepo: TodoRepository) {}

  @post('/todos', {
    responses: {
      '200': {
        description: 'Todo model instance',
        content: {'application/json': {schema: getModelSchemaRef(Todo)}},
      },
    },
  })
  async createTodo(
    @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Todo, {title: 'NewTodo', exclude: ['id']}),
        },
      },
    })
    todo: Omit,
  ): Promise {
    return this.todoRepo.create(todo);
  }