UNPKG

openapi-metadata

Version:

Auto-Generate OpenAPI specifications from Typescript decorators

40 lines (36 loc) 1.17 kB
'use strict'; const symbolKeysNotSupported = require('../errors/symbol-keys-not-supported.cjs'); const property = require('../metadata/property.cjs'); const metadata = require('../utils/metadata.cjs'); function ApiProperty(options) { return (prototype, propertyKey, descriptor) => { const isMethod = Boolean(descriptor?.value); if (typeof propertyKey === "symbol") { throw new symbolKeysNotSupported.SymbolKeysNotSupportedError(); } const metadata$1 = { name: options?.name ?? propertyKey, required: true, ...options }; if (!metadata$1.type && !metadata$1.schema && !metadata$1.enum) { metadata$1.type = (context) => metadata.findType({ metadataKey: isMethod ? "design:returntype" : "design:type", prototype, propertyKey }); } property.PropertyMetadataStorage.mergeMetadata(prototype, { [metadata$1.name]: metadata$1 }); }; } function ApiPropertyOptional(options) { return ApiProperty({ ...options, required: false }); } exports.ApiProperty = ApiProperty; exports.ApiPropertyOptional = ApiPropertyOptional; //# sourceMappingURL=api-property.cjs.map