@marxlnfcs/nest-swagger-decorators
Advanced tools
Comparing version 0.3.1 to 0.4.1
import { IApiControllerOptions } from "../interfaces/options.model"; | ||
import { IApiRouteLike } from "../interfaces/types.model"; | ||
export declare function ApiController(options?: IApiControllerOptions | false): ClassDecorator; | ||
export declare function ApiController(prefix: string, options?: Omit<IApiControllerOptions, 'path'> | false): ClassDecorator; | ||
export declare function ApiController(prefix: IApiRouteLike, options?: Omit<IApiControllerOptions, 'path'> | false): ClassDecorator; |
@@ -1,25 +0,26 @@ | ||
import { IApiRouteOptions, IApiRoutePath } from "../interfaces/options.model"; | ||
import { IApiRouteOptions } from "../interfaces/options.model"; | ||
import { IApiRouteLike } from "../interfaces/types.model"; | ||
export declare function ApiAll(status?: number): MethodDecorator; | ||
export declare function ApiAll(options?: IApiRouteOptions | false, status?: number): MethodDecorator; | ||
export declare function ApiAll(path?: IApiRoutePath, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiAll(path?: IApiRouteLike, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiGet(status?: number): MethodDecorator; | ||
export declare function ApiGet(options?: IApiRouteOptions | false, status?: number): MethodDecorator; | ||
export declare function ApiGet(path?: IApiRoutePath, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiGet(path?: IApiRouteLike, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiPost(status?: number): MethodDecorator; | ||
export declare function ApiPost(options?: IApiRouteOptions | false, status?: number): MethodDecorator; | ||
export declare function ApiPost(path?: IApiRoutePath, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiPost(path?: IApiRouteLike, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiPatch(status?: number): MethodDecorator; | ||
export declare function ApiPatch(options?: IApiRouteOptions | false, status?: number): MethodDecorator; | ||
export declare function ApiPatch(path?: IApiRoutePath, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiPatch(path?: IApiRouteLike, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiPut(status?: number): MethodDecorator; | ||
export declare function ApiPut(options?: IApiRouteOptions | false, status?: number): MethodDecorator; | ||
export declare function ApiPut(path?: IApiRoutePath, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiPut(path?: IApiRouteLike, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiDelete(status?: number): MethodDecorator; | ||
export declare function ApiDelete(options?: IApiRouteOptions | false, status?: number): MethodDecorator; | ||
export declare function ApiDelete(path?: IApiRoutePath, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiDelete(path?: IApiRouteLike, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiHead(status?: number): MethodDecorator; | ||
export declare function ApiHead(options?: IApiRouteOptions | false, status?: number): MethodDecorator; | ||
export declare function ApiHead(path?: IApiRoutePath, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiHead(path?: IApiRouteLike, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiOptions(status?: number): MethodDecorator; | ||
export declare function ApiOptions(options?: IApiRouteOptions | false, status?: number): MethodDecorator; | ||
export declare function ApiOptions(path?: IApiRoutePath, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; | ||
export declare function ApiOptions(path?: IApiRouteLike, options?: Omit<IApiRouteOptions, 'path'> | false, status?: number): MethodDecorator; |
@@ -6,5 +6,5 @@ import { HttpException, Type } from "@nestjs/common"; | ||
import { ApiPropertyOptions } from "@nestjs/swagger"; | ||
export type IApiRoutePath = string | string[]; | ||
import { IApiRouteLike } from "./types.model"; | ||
export interface IApiRouteOptions { | ||
path?: IApiRoutePath; | ||
path?: IApiRouteLike; | ||
summary?: string; | ||
@@ -22,3 +22,3 @@ description?: string; | ||
export interface IApiControllerOptions { | ||
path?: IApiRoutePath; | ||
path?: IApiRouteLike; | ||
tagGroups?: string[]; | ||
@@ -25,0 +25,0 @@ tags?: string[]; |
@@ -12,1 +12,5 @@ import { Type } from "@nestjs/common"; | ||
export type IApiClassRef = IApiClassRefSingle | IApiClassRefList | IApiClassRefSingleList; | ||
export type IApiRouteLike = string | IApiRouteLikeFn | Array<string | IApiRouteLikeFn>; | ||
export type IApiRouteLikeFn = { | ||
toString: () => string; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveClassRef = exports.transformException = exports.createHttpErrorFromException = exports.createHttpError = exports.getStatusMessage = exports.flatten = exports.extractClassRef = exports.isClass = exports.extractString = exports.extractStatus = exports.extractOptions = exports.extractPath = exports.isFalse = exports.isBoolean = exports.isNumber = exports.isString = exports.isArray = exports.isFunction = exports.isObject = exports.isNil = exports.getApiSchemaPath = void 0; | ||
exports.resolveClassRef = exports.transformException = exports.createHttpErrorFromException = exports.createHttpError = exports.getStatusMessage = exports.flatten = exports.extractClassRef = exports.isClass = exports.isRouteLike = exports.extractString = exports.extractStatus = exports.extractOptions = exports.extractPath = exports.isFalse = exports.isBoolean = exports.isNumber = exports.isString = exports.isArray = exports.isFunction = exports.isObject = exports.isNil = exports.getApiSchemaPath = void 0; | ||
const common_1 = require("@nestjs/common"); | ||
@@ -52,3 +52,15 @@ const swagger_1 = require("@nestjs/swagger"); | ||
function extractPath(...args) { | ||
return args.find(r => isString(r) || Array.isArray(r)) || ''; | ||
const paths = args.filter(r => isRouteLike(r)); | ||
for (let p of paths) { | ||
if (p === undefined || p === null) { | ||
// skip | ||
} | ||
else if (Array.isArray(p)) { | ||
return p.filter(i => !!i).map(i => i.toString()); | ||
} | ||
else { | ||
return (typeof p === 'string' ? p : isRouteLike(p) ? p.toString() : null) || '/'; | ||
} | ||
} | ||
return '/'; | ||
} | ||
@@ -59,3 +71,3 @@ exports.extractPath = extractPath; | ||
var _a; | ||
return (_a = args.find(r => !isNil(r) && isObject(r) && !Array.isArray(r))) !== null && _a !== void 0 ? _a : false; | ||
return (_a = args.find(r => !isNil(r) && (isObject(r) || isFalse(r)) && !Array.isArray(r) && !isRouteLike(r))) !== null && _a !== void 0 ? _a : {}; | ||
} | ||
@@ -75,2 +87,21 @@ exports.extractOptions = extractOptions; | ||
/** @internal */ | ||
function isRouteLike(v) { | ||
if (v === undefined || v === null) { | ||
return false; | ||
} | ||
else if (Array.isArray(v)) { | ||
return true; | ||
} | ||
else { | ||
if (typeof v === 'string') { | ||
return true; | ||
} | ||
else if (typeof v === 'object' && v.toString !== Object.prototype.toString) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
exports.isRouteLike = isRouteLike; | ||
/** @internal */ | ||
function isClass(v) { | ||
@@ -77,0 +108,0 @@ return typeof v === 'function' && /^\s*class\s+/.test(v.toString()); |
{ | ||
"name": "@marxlnfcs/nest-swagger-decorators", | ||
"private": false, | ||
"version": "0.3.1", | ||
"version": "0.4.1", | ||
"description": "Extended decorators for the @nestjs/swagger module", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
241660
1516