Skip to content
This repository was archived by the owner on Mar 20, 2026. It is now read-only.

Commit 6f72b89

Browse files
samchonCopilot
andauthored
HTTP migration writese plugin properties on comment. (#223)
* HTTP migration writese plugin properties on comment. * Update src/composers/HttpMigrateRouteComposer.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent d85be18 commit 6f72b89

3 files changed

Lines changed: 73 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@samchon/openapi",
3-
"version": "6.0.0",
3+
"version": "6.0.1",
44
"description": "Universal OpenAPI to LLM function calling schemas. Transform any Swagger/OpenAPI document into type-safe schemas for OpenAI, Claude, Qwen, and more.",
55
"main": "./lib/index.js",
66
"module": "./lib/index.mjs",

src/composers/HttpMigrateRouteComposer.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,7 @@ export namespace HttpMigrateRouteComposer {
316316
query: IHttpMigrateRoute.IQuery | null;
317317
body: IHttpMigrateRoute.IBody | null;
318318
}): string => {
319-
const commentTags: string[] = [];
320-
const add = (text: string) => {
321-
if (commentTags.every((line) => line !== text)) commentTags.push(text);
322-
};
323-
319+
// write basic description combining with summary
324320
let description: string = props.operation.description ?? "";
325321
if (!!props.operation.summary?.length) {
326322
const summary: string = props.operation.summary.endsWith(".")
@@ -337,6 +333,15 @@ export namespace HttpMigrateRouteComposer {
337333
.map((s) => s.trim())
338334
.join("\n");
339335

336+
//----
337+
// compose jsdoc comment tags
338+
//----
339+
const commentTags: string[] = [];
340+
const add = (text: string) => {
341+
if (commentTags.every((line) => line !== text)) commentTags.push(text);
342+
};
343+
344+
// parameters
340345
add("@param connection");
341346
for (const p of props.parameters ?? []) {
342347
const param = p.parameter();
@@ -347,12 +352,33 @@ export namespace HttpMigrateRouteComposer {
347352
}
348353
if (props.body?.description()?.length)
349354
add(`@param body ${writeIndented(props.body.description()!, 12)}`);
355+
356+
// security
350357
for (const security of props.operation.security ?? [])
351358
for (const [name, scopes] of Object.entries(security))
352359
add(`@security ${[name, ...scopes].join("")}`);
360+
361+
// categorizing tags
353362
if (props.operation.tags)
354363
props.operation.tags.forEach((name) => add(`@tag ${name}`));
364+
365+
// deprecated
355366
if (props.operation.deprecated) add("@deprecated");
367+
368+
// plugin properties
369+
for (const [key, value] of Object.entries(props.operation)) {
370+
if (key.startsWith("x-") === false) continue;
371+
else if (
372+
value !== null &&
373+
typeof value !== "boolean" &&
374+
typeof value !== "number" &&
375+
typeof value !== "string"
376+
)
377+
continue;
378+
add(`@${key} ${value}`);
379+
}
380+
381+
// finalize description
356382
description = description.length
357383
? commentTags.length
358384
? `${description}\n\n${commentTags.join("\n")}`
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { TestValidator } from "@nestia/e2e";
2+
import {
3+
HttpMigration,
4+
IHttpMigrateApplication,
5+
IHttpMigrateRoute,
6+
OpenApi,
7+
} from "@samchon/openapi";
8+
9+
export const test_http_migrate_route_plugin = async (): Promise<void> => {
10+
const document: OpenApi.IDocument = {
11+
openapi: "3.1.0",
12+
"x-samchon-emended-v4": true,
13+
paths: {
14+
"/items": {
15+
get: {
16+
description: "Retrieve a list of items.",
17+
...{
18+
"x-autobe-specification": [
19+
"Hello everyone!",
20+
"",
21+
"Nice to to meet you all.",
22+
].join("\n"),
23+
},
24+
},
25+
},
26+
},
27+
components: {},
28+
};
29+
const migrate: IHttpMigrateApplication = HttpMigration.application(document);
30+
const route: IHttpMigrateRoute = migrate.routes[0];
31+
TestValidator.equals("plugin")(route.comment())(
32+
[
33+
"Retrieve a list of items.",
34+
"",
35+
"@param connection",
36+
"@x-autobe-specification Hello everyone!",
37+
"",
38+
"Nice to to meet you all.",
39+
].join("\n"),
40+
);
41+
};

0 commit comments

Comments
 (0)