UNPKG

@solid-nestjs/rest-api

Version:

solid-nestjs Rest-API utilities

34 lines 1.74 kB
import { HttpStatus, Type } from '@nestjs/common'; import { ReferenceObject, SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface'; /** * Composite decorator for defining multiple API response types for a controller method. * * @param options - Configuration options for the API responses. * @param options.type - The type of the successful response. Can be a class or a function. * @param options.schema - The OpenAPI schema object for the response. * @param options.isArray - Indicates if the response is an array of the specified type. * @param options.successCodes - Array of HTTP status codes to be treated as successful responses. Defaults to [HttpStatus.OK]. * @param options.errorCodes - Array of HTTP status codes to be treated as error responses. Defaults to [HttpStatus.BAD_REQUEST]. * * @remarks * This decorator applies multiple `@ApiResponse` decorators for both success and error HTTP status codes. * For error responses, it uses a standard `ErrorResponse` type and provides an example payload. * * @example * ```typescript * @ApiResponses({ * type: UserDto, * isArray: true, * successCodes: [HttpStatus.OK, HttpStatus.CREATED], * errorCodes: [HttpStatus.BAD_REQUEST, HttpStatus.UNAUTHORIZED] * }) * ``` */ export declare const ApiResponses: ({ type, schema, isArray, successCodes, errorCodes, }: { type?: Type | Function; schema?: SchemaObject & Partial<ReferenceObject>; isArray?: boolean; successCodes?: HttpStatus[]; errorCodes?: HttpStatus[]; }) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void; //# sourceMappingURL=api-responses.decorator.d.ts.map