UNPKG

@jvhaile/loopback4-helper

Version:
90 lines (82 loc) 2.67 kB
import {getModelSchemaRef, Model} from "@loopback/rest"; import {CountSchema} from "@loopback/repository"; import {JsonSchemaOptions} from "@loopback/repository-json-schema"; export function singleResponse<T extends Model>(modelCtor: Function & { prototype: T }, options?: JsonSchemaOptions<T>) { return { responses: { '200': { description: `${modelCtor.name} model instance`, content: {'application/json': {schema: getModelSchemaRef(modelCtor, options)}}, }, }, } } export function countResponse<T extends Model>(modelCtor: Function & { prototype: T }) { return { responses: { '200': { description: `${modelCtor.name} model count`, content: {'application/json': {schema: CountSchema}}, }, }, } } export function plainBody() { return { content: { 'application/json': { schema: { $ref: '/definitions/query', definitions: { query: [] } } } } } } export function singleBody<T extends Model>(modelCtor: Function & { prototype: T }, options?: JsonSchemaOptions<T>) { return { content: { 'application/json': { schema: getModelSchemaRef(modelCtor, options), }, }, } } export function arrayResponse<T extends Model>(modelCtor: Function & { prototype: T }) { return { responses: { '200': { description: `Array of ${modelCtor.name} model instances`, content: { 'application/json': { schema: { type: 'array', items: getModelSchemaRef(modelCtor, {includeRelations: true}), }, }, }, }, }, } } export function patchManyResponse<T extends Model>(modelCtor: Function & { prototype: T }) { return { responses: { '200': { description: `${modelCtor.name} PATCH success count`, content: {'application/json': {schema: CountSchema}}, }, }, } } export function deleteResponse<T extends Model>(modelCtor: Function & { prototype: T }) { return { responses: { '204': { description: `${modelCtor.name} DELETE success`, }, }, } }