Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@samchon/openapi",
"version": "6.0.0",
"version": "6.0.1",
"description": "Universal OpenAPI to LLM function calling schemas. Transform any Swagger/OpenAPI document into type-safe schemas for OpenAI, Claude, Qwen, and more.",
"main": "./lib/index.js",
"module": "./lib/index.mjs",
Expand Down
36 changes: 31 additions & 5 deletions src/composers/HttpMigrateRouteComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,7 @@ export namespace HttpMigrateRouteComposer {
query: IHttpMigrateRoute.IQuery | null;
body: IHttpMigrateRoute.IBody | null;
}): string => {
const commentTags: string[] = [];
const add = (text: string) => {
if (commentTags.every((line) => line !== text)) commentTags.push(text);
};

// write basic description combining with summary
let description: string = props.operation.description ?? "";
if (!!props.operation.summary?.length) {
const summary: string = props.operation.summary.endsWith(".")
Expand All @@ -337,6 +333,15 @@ export namespace HttpMigrateRouteComposer {
.map((s) => s.trim())
.join("\n");

//----
// compose jsdoc comment tags
//----
const commentTags: string[] = [];
const add = (text: string) => {
if (commentTags.every((line) => line !== text)) commentTags.push(text);
};

// parameters
add("@param connection");
for (const p of props.parameters ?? []) {
const param = p.parameter();
Expand All @@ -347,12 +352,33 @@ export namespace HttpMigrateRouteComposer {
}
if (props.body?.description()?.length)
add(`@param body ${writeIndented(props.body.description()!, 12)}`);

// security
for (const security of props.operation.security ?? [])
for (const [name, scopes] of Object.entries(security))
add(`@security ${[name, ...scopes].join("")}`);

// categorizing tags
if (props.operation.tags)
props.operation.tags.forEach((name) => add(`@tag ${name}`));

// deprecated
if (props.operation.deprecated) add("@deprecated");

// plugin properties
for (const [key, value] of Object.entries(props.operation)) {
if (key.startsWith("x-") === false) continue;
else if (
value !== null &&
typeof value !== "boolean" &&
typeof value !== "number" &&
typeof value !== "string"
)
continue;
add(`@${key} ${value}`);
}

// finalize description
description = description.length
? commentTags.length
? `${description}\n\n${commentTags.join("\n")}`
Expand Down
41 changes: 41 additions & 0 deletions test/src/features/migrate/test_http_migrate_route_plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { TestValidator } from "@nestia/e2e";
import {
HttpMigration,
IHttpMigrateApplication,
IHttpMigrateRoute,
OpenApi,
} from "@samchon/openapi";

export const test_http_migrate_route_plugin = async (): Promise<void> => {
const document: OpenApi.IDocument = {
openapi: "3.1.0",
"x-samchon-emended-v4": true,
paths: {
"/items": {
get: {
description: "Retrieve a list of items.",
...{
"x-autobe-specification": [
"Hello everyone!",
"",
"Nice to to meet you all.",
].join("\n"),
},
},
},
},
components: {},
};
const migrate: IHttpMigrateApplication = HttpMigration.application(document);
const route: IHttpMigrateRoute = migrate.routes[0];
TestValidator.equals("plugin")(route.comment())(
[
"Retrieve a list of items.",
"",
"@param connection",
"@x-autobe-specification Hello everyone!",
"",
"Nice to to meet you all.",
].join("\n"),
);
};