typera-openapi
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -19,3 +19,3 @@ "use strict"; | ||
ts.forEachChild(sourceFile, (node) => { | ||
const paths = visit(context_1.context(checker, sourceFile, log, node), node); | ||
const paths = visitTopLevelNode(context_1.context(checker, sourceFile, log, node), node); | ||
if (paths) { | ||
@@ -29,3 +29,3 @@ result.push({ fileName: sourceFile.fileName, paths }); | ||
exports.generate = generate; | ||
const visit = (ctx, node) => { | ||
const visitTopLevelNode = (ctx, node) => { | ||
if (ts.isExportAssignment(node) && !node.isExportEquals) { | ||
@@ -38,5 +38,11 @@ // 'export default' statement | ||
argSymbols.forEach((symbol) => { | ||
const location = symbol.valueDeclaration; | ||
if (!location) | ||
let location = symbol.valueDeclaration; | ||
if (!location && symbol.flags & ts.SymbolFlags.Alias) { | ||
symbol = ctx.checker.getAliasedSymbol(symbol); | ||
location = symbol.valueDeclaration; | ||
} | ||
if (!location) { | ||
ctx.log('warn', `Could not find the definition of router arg ${symbol.name}`); | ||
return; | ||
} | ||
const routeDeclaration = getRouteDeclaration(context_1.withLocation(ctx, location), symbol); | ||
@@ -78,4 +84,6 @@ if (routeDeclaration) { | ||
const routeInput = getRouteInput(ctx, symbol); | ||
if (!routeInput) | ||
if (!routeInput) { | ||
ctx.log('warn', `Could not determine route input for symbol ${symbol.name}`); | ||
return; | ||
} | ||
const { method, path, requestNode, body, query, headers, routeParams, cookies, } = routeInput; | ||
@@ -137,5 +145,9 @@ const responses = getResponseTypes(ctx, symbol); | ||
const declaration = symbol.valueDeclaration; | ||
if (!declaration || !ts.isVariableDeclaration(declaration)) | ||
if (!declaration) | ||
return; | ||
let expr = declaration.initializer; | ||
let expr = ts.isVariableDeclaration(declaration) | ||
? declaration.initializer | ||
: ts.isExportAssignment(declaration) | ||
? declaration.expression | ||
: undefined; | ||
if (!expr) | ||
@@ -142,0 +154,0 @@ return; |
{ | ||
"name": "typera-openapi", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Generate OpenAPI spec from typera routes", | ||
@@ -22,3 +22,4 @@ "repository": "https://github.com/akheron/typera-openapi", | ||
"test": "jest", | ||
"doctoc": "doctoc README.md --title '## Table of Contents' && prettier --write README.md" | ||
"doctoc": "doctoc README.md --title '## Table of Contents' && prettier --write README.md", | ||
"prepublishOnly": "yarn clean && yarn build" | ||
}, | ||
@@ -25,0 +26,0 @@ "dependencies": { |
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
42251
826