typera-openapi
Advanced tools
Comparing version 0.10.1 to 0.10.2
@@ -422,10 +422,12 @@ "use strict"; | ||
} | ||
if (type.isIntersection()) { | ||
// io-ts int | ||
const memberTypes = type.types.map((memberType) => ctx.checker.typeToString(memberType)); | ||
if (memberTypes.length === 2 && | ||
memberTypes.includes('number') && | ||
memberTypes.includes('Brand<IntBrand>')) { | ||
const branded = utils_1.getBrandedType(ctx, type); | ||
if (branded) { | ||
// io-ts branded type | ||
const { brandName, brandedType } = branded; | ||
if (brandName === 'Brand<IntBrand>') { | ||
// io-ts Int | ||
return Object.assign({ type: 'integer' }, base); | ||
} | ||
// other branded type | ||
return typeToSchema(ctx, brandedType, options); | ||
} | ||
@@ -432,0 +434,0 @@ ctx.log('warn', `Ignoring an unknown type: ${ctx.checker.typeToString(type)}`); |
import * as ts from 'typescript'; | ||
import { Context } from './context'; | ||
export declare const isDefined: <T>(value: T | undefined) => value is T; | ||
@@ -18,1 +19,5 @@ export declare const isOptional: (symbol: ts.Symbol) => boolean; | ||
export declare const isPackageSymbol: (symbol: ts.Symbol, packageName: string, symbolName: string) => boolean; | ||
export declare const getBrandedType: (ctx: Context, type: ts.Type) => { | ||
brandName: string; | ||
brandedType: ts.Type; | ||
} | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isPackageSymbol = exports.getPropertyType = exports.isBufferType = exports.isDateType = exports.isNullType = exports.isUndefinedType = exports.isStringLiteralType = exports.isNumberLiteralType = exports.isBooleanLiteralType = exports.isBooleanType = exports.isNumberType = exports.isStringType = exports.isObjectType = exports.isArrayType = exports.isOptional = exports.isDefined = void 0; | ||
exports.getBrandedType = exports.isPackageSymbol = exports.getPropertyType = exports.isBufferType = exports.isDateType = exports.isNullType = exports.isUndefinedType = exports.isStringLiteralType = exports.isNumberLiteralType = exports.isBooleanLiteralType = exports.isBooleanType = exports.isNumberType = exports.isStringType = exports.isObjectType = exports.isArrayType = exports.isOptional = exports.isDefined = void 0; | ||
const ts = require("typescript"); | ||
@@ -66,1 +66,13 @@ const isDefined = (value) => value !== undefined; | ||
exports.isPackageSymbol = isPackageSymbol; | ||
const getBrandedType = (ctx, type) => { | ||
if (!type.isIntersection() || type.types.length !== 2) | ||
return undefined; | ||
const brandIndex = type.types.findIndex((t) => { var _a; return ((_a = t.symbol) === null || _a === void 0 ? void 0 : _a.escapedName) === 'Brand'; }); | ||
if (brandIndex === -1) | ||
return undefined; | ||
const brand = type.types[brandIndex]; | ||
const brandName = ctx.checker.typeToString(brand); | ||
const brandedType = type.types[brandIndex === 1 ? 0 : 1]; | ||
return { brandName, brandedType }; | ||
}; | ||
exports.getBrandedType = getBrandedType; |
{ | ||
"name": "typera-openapi", | ||
"version": "0.10.1", | ||
"version": "0.10.2", | ||
"description": "Generate OpenAPI spec from typera routes", | ||
@@ -45,4 +45,4 @@ "repository": "https://github.com/akheron/typera-openapi", | ||
"ts-jest": "^26.4.4", | ||
"typera-express": "2.2.0" | ||
"typera-express": "2.2.1" | ||
} | ||
} |
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
37996
726