typera-openapi
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -15,2 +15,3 @@ "use strict"; | ||
const seenFileNames = new Set(); | ||
const seenOperationIds = new Set(); | ||
const components = new components_1.Components(); | ||
@@ -26,3 +27,3 @@ let paths = {}; | ||
ts.forEachChild(sourceFile, (node) => { | ||
const newPaths = visitTopLevelNode((0, context_1.context)(checker, sourceFile, log, node), components, node); | ||
const newPaths = visitTopLevelNode((0, context_1.context)(checker, sourceFile, log, node), components, seenOperationIds, node); | ||
if (newPaths) { | ||
@@ -45,3 +46,3 @@ // TODO: What if a route is defined multiple times? | ||
const isSameFile = (a, b) => path.resolve(a) === path.resolve(b); | ||
const visitTopLevelNode = (ctx, components, node) => { | ||
const visitTopLevelNode = (ctx, components, seenOperationIds, node) => { | ||
if (ts.isExportAssignment(node) && !node.isExportEquals) { | ||
@@ -79,2 +80,10 @@ const prefix = getRouterPrefix(node); | ||
} | ||
if (operation.operationId) { | ||
if (!seenOperationIds.has(operation.operationId)) { | ||
seenOperationIds.add(operation.operationId); | ||
} | ||
else { | ||
ctx.log('warn', `Duplicated operationId ${operation.operationId}. Use @operationId in JSDoc comment to override.`); | ||
} | ||
} | ||
} | ||
@@ -102,2 +111,3 @@ }); | ||
const getRouteDeclaration = (ctx, components, symbol) => { | ||
var _a; | ||
const description = getDescriptionFromComment(ctx, symbol); | ||
@@ -107,2 +117,3 @@ const summary = getRouteSummary(symbol); | ||
const routeInput = getRouteInput(ctx, symbol); | ||
const operationId = (_a = getRouteOperationId(symbol)) !== null && _a !== void 0 ? _a : symbol.escapedName.toString(); | ||
if (!routeInput) { | ||
@@ -132,3 +143,3 @@ ctx.log('warn', `Could not determine route input for symbol ${symbol.name}`); | ||
method, | ||
Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (summary ? { summary } : undefined)), (description ? { description } : undefined)), (tags && tags.length > 0 ? { tags } : undefined)), (parameters.length > 0 ? { parameters } : undefined)), operationRequestBody(requestBody, contentTypeString)), { responses }), | ||
Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (summary ? { summary } : undefined)), { operationId }), (description ? { description } : undefined)), (tags && tags.length > 0 ? { tags } : undefined)), (parameters.length > 0 ? { parameters } : undefined)), operationRequestBody(requestBody, contentTypeString)), { responses }), | ||
]; | ||
@@ -153,2 +164,8 @@ }; | ||
.map((tag) => tag.trim()); | ||
const getRouteOperationId = (symbol) => symbol | ||
.getJsDocTags() | ||
.filter((tag) => tag.name === 'operationId') | ||
.flatMap((tag) => tag.text) | ||
.filter(utils_1.isDefined) | ||
.map((symbolDisplayPart) => symbolDisplayPart.text)[0]; | ||
const getNodeTags = (node) => ts | ||
@@ -155,0 +172,0 @@ .getJSDocTags(node) |
{ | ||
"name": "typera-openapi", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Generate OpenAPI spec from typera routes", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/akheron/typera-openapi", |
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
57506
1039