@nestjs/swagger
Advanced tools
Comparing version 4.7.2 to 4.7.3
import { Type } from '@nestjs/common'; | ||
import { ParameterObject, SchemaObject } from '../interfaces/open-api-spec.interface'; | ||
import { ParameterObject, ReferenceObject, SchemaObject } from '../interfaces/open-api-spec.interface'; | ||
import { SwaggerEnumType } from '../types/swagger-enum.type'; | ||
declare type ParameterOptions = Omit<ParameterObject, 'in' | 'schema'>; | ||
declare type ParameterOptions = Omit<ParameterObject, 'in' | 'schema' | 'name'>; | ||
interface ApiQueryMetadata extends ParameterOptions { | ||
name?: string; | ||
type?: Type<unknown> | Function | [Function] | string; | ||
@@ -12,3 +13,4 @@ isArray?: boolean; | ||
interface ApiQuerySchemaHost extends ParameterOptions { | ||
schema: SchemaObject; | ||
name?: string; | ||
schema: SchemaObject | ReferenceObject; | ||
} | ||
@@ -15,0 +17,0 @@ export declare type ApiQueryOptions = ApiQueryMetadata | ApiQuerySchemaHost; |
import { Type } from '@nestjs/common'; | ||
export declare const exploreGlobalApiExtraModelsMetadata: (metatype: Type<unknown>) => any; | ||
export declare const exploreGlobalApiExtraModelsMetadata: (metatype: Type<unknown>) => Function[]; | ||
export declare const exploreApiExtraModelsMetadata: (instance: object, prototype: Type<unknown>, method: object) => Function[]; |
import { Type } from '@nestjs/common'; | ||
import { BaseParameterObject, ReferenceObject, SchemaObject } from '../interfaces/open-api-spec.interface'; | ||
import { BaseParameterObject, ParameterObject, ReferenceObject, SchemaObject } from '../interfaces/open-api-spec.interface'; | ||
import { SchemaObjectMetadata } from '../interfaces/schema-object-metadata.interface'; | ||
@@ -12,13 +12,15 @@ import { ModelPropertiesAccessor } from './model-properties-accessor'; | ||
createFromModel(parameters: ParamWithTypeMetadata[], schemas: SchemaObject[], schemaRefsStack?: string[]): Array<ParamWithTypeMetadata | BaseParameterObject>; | ||
createQueryOrParamSchema(param: ParamWithTypeMetadata, schemas: SchemaObject[], schemaRefsStack: string[]): ParamWithTypeMetadata | Partial<ParamWithTypeMetadata & BaseParameterObject> | { | ||
type: Function; | ||
isArray: boolean; | ||
createQueryOrParamSchema(param: ParamWithTypeMetadata, schemas: SchemaObject[], schemaRefsStack: string[]): ParamWithTypeMetadata | Partial<ParamWithTypeMetadata & BaseParameterObject> | ParameterObject[] | { | ||
type: string; | ||
name?: string | number | object; | ||
in?: "query" | "header" | "path" | "cookie" | "body" | "placeholder"; | ||
isArray?: boolean; | ||
required: true; | ||
enum?: unknown[]; | ||
enumName?: string; | ||
format: string; | ||
}; | ||
extractPropertiesFromType(type: Type<unknown>, schemas: SchemaObject[], schemaRefsStack: string[]): ParameterObject[]; | ||
exploreModelSchema(type: Type<unknown> | Function, schemas: SchemaObject[], schemaRefsStack?: string[]): string; | ||
mergePropertyWithMetadata(key: string, prototype: Type<unknown>, schemas: SchemaObject[], schemaRefsStack?: string[], metadata?: SchemaObjectMetadata): SchemaObjectMetadata | ReferenceObject; | ||
mergePropertyWithMetadata(key: string, prototype: Type<unknown>, schemas: SchemaObject[], schemaRefsStack?: string[], metadata?: SchemaObjectMetadata): SchemaObjectMetadata | ReferenceObject | ParameterObject; | ||
createEnumParam(param: ParamWithTypeMetadata & BaseParameterObject, schemas: SchemaObject[], schemaRefsStack: string[]): Partial<ParamWithTypeMetadata & BaseParameterObject>; | ||
@@ -25,0 +27,0 @@ createEnumSchemaType(key: string, metadata: SchemaObjectMetadata, schemas: SchemaObject[], schemaRefsStack: string[]): Partial<{ |
@@ -20,5 +20,5 @@ "use strict"; | ||
createFromModel(parameters, schemas, schemaRefsStack = []) { | ||
return parameters.map((param) => { | ||
if (!is_body_parameter_util_1.isBodyParameter(param)) { | ||
return this.createQueryOrParamSchema(param, schemas, schemaRefsStack); | ||
const parameterObjects = parameters.map((param) => { | ||
if (this.isLazyTypeFunc(param.type)) { | ||
[param.type, param.isArray] = helpers_1.getTypeIsArrayTuple(param.type(), undefined); | ||
} | ||
@@ -31,2 +31,5 @@ if (this.isPrimitiveType(param.type)) { | ||
} | ||
if (!is_body_parameter_util_1.isBodyParameter(param)) { | ||
return this.createQueryOrParamSchema(param, schemas, schemaRefsStack); | ||
} | ||
const modelName = this.exploreModelSchema(param.type, schemas, schemaRefsStack); | ||
@@ -46,2 +49,3 @@ const name = param.name || modelName; | ||
}); | ||
return lodash_1.flatten(parameterObjects); | ||
} | ||
@@ -52,16 +56,22 @@ createQueryOrParamSchema(param, schemas, schemaRefsStack) { | ||
} | ||
if (this.isLazyTypeFunc(param.type)) { | ||
const [type, isArray] = helpers_1.getTypeIsArrayTuple(param.type(), undefined); | ||
return Object.assign(Object.assign({}, param), { type, | ||
isArray }); | ||
if (is_date_ctor_util_1.isDateCtor(param.type)) { | ||
return Object.assign(Object.assign({ format: 'date-time' }, param), { type: 'string' }); | ||
} | ||
if (lodash_1.isFunction(param.type)) { | ||
const propertiesWithType = this.extractPropertiesFromType(param.type, schemas, schemaRefsStack); | ||
if (!propertiesWithType) { | ||
return param; | ||
} | ||
return propertiesWithType.map((property) => { | ||
var _a; | ||
const parameterObject = Object.assign(Object.assign({}, lodash_1.omit(property, 'enumName')), { in: 'query', required: (_a = property.required) !== null && _a !== void 0 ? _a : true }); | ||
return parameterObject; | ||
}); | ||
} | ||
return param; | ||
} | ||
exploreModelSchema(type, schemas, schemaRefsStack = []) { | ||
if (this.isLazyTypeFunc(type)) { | ||
type = type(); | ||
} | ||
extractPropertiesFromType(type, schemas, schemaRefsStack) { | ||
const { prototype } = type; | ||
if (!prototype) { | ||
return ''; | ||
return; | ||
} | ||
@@ -80,2 +90,12 @@ const extraModels = api_extra_models_explorer_1.exploreGlobalApiExtraModelsMetadata(type); | ||
}); | ||
return propertiesWithType; | ||
} | ||
exploreModelSchema(type, schemas, schemaRefsStack = []) { | ||
if (this.isLazyTypeFunc(type)) { | ||
type = type(); | ||
} | ||
const propertiesWithType = this.extractPropertiesFromType(type, schemas, schemaRefsStack); | ||
if (!propertiesWithType) { | ||
return ''; | ||
} | ||
const typeDefinition = { | ||
@@ -82,0 +102,0 @@ type: 'object', |
/// <reference types="lodash" /> | ||
import { ApiPropertyOptions } from '../decorators'; | ||
import { BaseParameterObject, SchemaObject } from '../interfaces/open-api-spec.interface'; | ||
import { BaseParameterObject, ReferenceObject, SchemaObject } from '../interfaces/open-api-spec.interface'; | ||
import { ParamWithTypeMetadata } from './parameter-metadata-accessor'; | ||
@@ -19,8 +19,8 @@ export declare class SwaggerTypesMapper { | ||
deprecated?: boolean; | ||
allOf?: (SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject)[]; | ||
oneOf?: (SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject)[]; | ||
anyOf?: (SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject)[]; | ||
not?: SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject; | ||
properties?: Record<string, SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject>; | ||
additionalProperties?: boolean | SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject; | ||
allOf?: (SchemaObject | ReferenceObject)[]; | ||
oneOf?: (SchemaObject | ReferenceObject)[]; | ||
anyOf?: (SchemaObject | ReferenceObject)[]; | ||
not?: SchemaObject | ReferenceObject; | ||
properties?: Record<string, SchemaObject | ReferenceObject>; | ||
additionalProperties?: boolean | SchemaObject | ReferenceObject; | ||
description?: string; | ||
@@ -55,3 +55,3 @@ format?: string; | ||
allowReserved?: boolean; | ||
examples?: Record<string, import("../interfaces/open-api-spec.interface").ReferenceObject | import("../interfaces/open-api-spec.interface").ExampleObject>; | ||
examples?: Record<string, ReferenceObject | import("../interfaces/open-api-spec.interface").ExampleObject>; | ||
example?: any; | ||
@@ -70,3 +70,3 @@ content?: Record<string, import("../interfaces/open-api-spec.interface").MediaTypeObject>; | ||
mapTypeToOpenAPIType(type: string | Function): string; | ||
mapEnumArrayType(param: Record<string, any>, keysToRemove: Array<keyof ApiPropertyOptions>): { | ||
mapEnumArrayType(param: Record<string, any>, keysToRemove: Array<keyof ApiPropertyOptions | '$ref'>): { | ||
schema: { | ||
@@ -84,8 +84,8 @@ type: string; | ||
deprecated?: boolean; | ||
allOf?: (SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject)[]; | ||
oneOf?: (SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject)[]; | ||
anyOf?: (SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject)[]; | ||
not?: SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject; | ||
properties?: Record<string, SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject>; | ||
additionalProperties?: boolean | SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject; | ||
allOf?: (SchemaObject | ReferenceObject)[]; | ||
oneOf?: (SchemaObject | ReferenceObject)[]; | ||
anyOf?: (SchemaObject | ReferenceObject)[]; | ||
not?: SchemaObject | ReferenceObject; | ||
properties?: Record<string, SchemaObject | ReferenceObject>; | ||
additionalProperties?: boolean | SchemaObject | ReferenceObject; | ||
description?: string; | ||
@@ -112,3 +112,3 @@ format?: string; | ||
}; | ||
mapArrayType(param: ParamWithTypeMetadata, keysToRemove: Array<keyof ApiPropertyOptions>): { | ||
mapArrayType(param: (ParamWithTypeMetadata & SchemaObject) | BaseParameterObject, keysToRemove: Array<keyof ApiPropertyOptions | '$ref'>): { | ||
schema: { | ||
@@ -126,8 +126,8 @@ type: string; | ||
deprecated?: boolean; | ||
allOf?: (SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject)[]; | ||
oneOf?: (SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject)[]; | ||
anyOf?: (SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject)[]; | ||
not?: SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject; | ||
properties?: Record<string, SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject>; | ||
additionalProperties?: boolean | SchemaObject | import("../interfaces/open-api-spec.interface").ReferenceObject; | ||
allOf?: (SchemaObject | ReferenceObject)[]; | ||
oneOf?: (SchemaObject | ReferenceObject)[]; | ||
anyOf?: (SchemaObject | ReferenceObject)[]; | ||
not?: SchemaObject | ReferenceObject; | ||
properties?: Record<string, SchemaObject | ReferenceObject>; | ||
additionalProperties?: boolean | SchemaObject | ReferenceObject; | ||
description?: string; | ||
@@ -153,9 +153,91 @@ format?: string; | ||
}; | ||
description?: string; | ||
required?: boolean; | ||
deprecated?: boolean; | ||
allowEmptyValue?: boolean; | ||
style?: import("../interfaces/open-api-spec.interface").ParameterStyle; | ||
explode?: boolean; | ||
allowReserved?: boolean; | ||
examples?: Record<string, ReferenceObject | import("../interfaces/open-api-spec.interface").ExampleObject>; | ||
example?: any; | ||
content?: Record<string, import("../interfaces/open-api-spec.interface").MediaTypeObject>; | ||
} | { | ||
schema: { | ||
type: string; | ||
items: import("lodash").Dictionary<any>; | ||
nullable?: boolean; | ||
discriminator?: import("../interfaces/open-api-spec.interface").DiscriminatorObject; | ||
readOnly?: boolean; | ||
writeOnly?: boolean; | ||
xml?: import("../interfaces/open-api-spec.interface").XmlObject; | ||
externalDocs?: import("../interfaces/open-api-spec.interface").ExternalDocumentationObject; | ||
example?: any; | ||
examples?: any[]; | ||
deprecated?: boolean; | ||
allOf?: (SchemaObject | ReferenceObject)[]; | ||
oneOf?: (SchemaObject | ReferenceObject)[]; | ||
anyOf?: (SchemaObject | ReferenceObject)[]; | ||
not?: SchemaObject | ReferenceObject; | ||
properties?: Record<string, SchemaObject | ReferenceObject>; | ||
additionalProperties?: boolean | SchemaObject | ReferenceObject; | ||
description?: string; | ||
format?: string; | ||
default?: any; | ||
title?: string; | ||
multipleOf?: number; | ||
maximum?: number; | ||
exclusiveMaximum?: boolean; | ||
minimum?: number; | ||
exclusiveMinimum?: boolean; | ||
maxLength?: number; | ||
minLength?: number; | ||
pattern?: string; | ||
maxItems?: number; | ||
minItems?: number; | ||
uniqueItems?: boolean; | ||
maxProperties?: number; | ||
minProperties?: number; | ||
required?: string[]; | ||
enum?: any[]; | ||
}; | ||
name?: string | number | object; | ||
type?: import("@nestjs/common").Type<unknown>; | ||
type?: import("@nestjs/common").Type<unknown> & string; | ||
in?: "query" | "header" | "path" | "cookie" | "body" | "placeholder"; | ||
isArray?: boolean; | ||
required?: true; | ||
enum?: unknown[]; | ||
required?: true & string[]; | ||
enum?: unknown[] & any[]; | ||
enumName?: string; | ||
nullable?: boolean; | ||
discriminator?: import("../interfaces/open-api-spec.interface").DiscriminatorObject; | ||
readOnly?: boolean; | ||
writeOnly?: boolean; | ||
xml?: import("../interfaces/open-api-spec.interface").XmlObject; | ||
externalDocs?: import("../interfaces/open-api-spec.interface").ExternalDocumentationObject; | ||
example?: any; | ||
examples?: any[]; | ||
deprecated?: boolean; | ||
allOf?: (SchemaObject | ReferenceObject)[]; | ||
oneOf?: (SchemaObject | ReferenceObject)[]; | ||
anyOf?: (SchemaObject | ReferenceObject)[]; | ||
not?: SchemaObject | ReferenceObject; | ||
items?: SchemaObject | ReferenceObject; | ||
properties?: Record<string, SchemaObject | ReferenceObject>; | ||
additionalProperties?: boolean | SchemaObject | ReferenceObject; | ||
description?: string; | ||
format?: string; | ||
default?: any; | ||
title?: string; | ||
multipleOf?: number; | ||
maximum?: number; | ||
exclusiveMaximum?: boolean; | ||
minimum?: number; | ||
exclusiveMinimum?: boolean; | ||
maxLength?: number; | ||
minLength?: number; | ||
pattern?: string; | ||
maxItems?: number; | ||
minItems?: number; | ||
uniqueItems?: boolean; | ||
maxProperties?: number; | ||
minProperties?: number; | ||
}; | ||
@@ -162,0 +244,0 @@ private getSchemaOptions; |
@@ -21,2 +21,3 @@ "use strict"; | ||
'items', | ||
'$ref', | ||
...this.getSchemaOptionsKeys() | ||
@@ -30,3 +31,3 @@ ]; | ||
} | ||
return Object.assign(Object.assign({}, lodash_1.omit(param, keysToRemove)), { schema: lodash_1.omitBy(Object.assign(Object.assign(Object.assign({}, this.getSchemaOptions(param)), (param.schema || {})), { enum: paramWithTypeMetadata.enum, type: paramWithTypeMetadata.type }), lodash_1.isUndefined) }); | ||
return Object.assign(Object.assign({}, lodash_1.omit(param, keysToRemove)), { schema: lodash_1.omitBy(Object.assign(Object.assign(Object.assign({}, this.getSchemaOptions(param)), (param.schema || {})), { enum: paramWithTypeMetadata.enum, type: paramWithTypeMetadata.type, $ref: paramWithTypeMetadata.$ref }), lodash_1.isUndefined) }); | ||
}); | ||
@@ -36,3 +37,3 @@ } | ||
if (!(type && type.charAt)) { | ||
return ''; | ||
return; | ||
} | ||
@@ -45,3 +46,4 @@ return type.charAt(0).toLowerCase() + type.slice(1); | ||
mapArrayType(param, keysToRemove) { | ||
const items = lodash_1.omitBy(Object.assign(Object.assign({}, (param.schema || {})), { enum: param.enum, type: this.mapTypeToOpenAPIType(param.type) }), lodash_1.isUndefined); | ||
const items = param.items || | ||
lodash_1.omitBy(Object.assign(Object.assign({}, (param.schema || {})), { enum: param.enum, type: this.mapTypeToOpenAPIType(param.type) }), lodash_1.isUndefined); | ||
return Object.assign(Object.assign({}, lodash_1.omit(param, keysToRemove)), { schema: Object.assign(Object.assign({}, this.getSchemaOptions(param)), { type: 'array', items }) }); | ||
@@ -48,0 +50,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.refs = exports.getSchemaPath = void 0; | ||
const util_1 = require("util"); | ||
const shared_utils_1 = require("@nestjs/common/utils/shared.utils"); | ||
function getSchemaPath(model) { | ||
const modelName = util_1.isString(model) ? model : model && model.name; | ||
const modelName = shared_utils_1.isString(model) ? model : model && model.name; | ||
return `#/components/schemas/${modelName}`; | ||
@@ -8,0 +8,0 @@ } |
{ | ||
"name": "@nestjs/swagger", | ||
"version": "4.7.2", | ||
"version": "4.7.3", | ||
"description": "Nest - modern, fast, powerful node.js web framework (@swagger)", | ||
@@ -5,0 +5,0 @@ "author": "Kamil Mysliwiec", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
214341
4384