@autobe/utils 0.30.0-dev.20260315 → 0.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,94 +1,94 @@
1
- import { AutoBeOpenApi } from "@autobe/interface";
2
- import {
3
- IHttpMigrateApplication,
4
- OpenApi,
5
- OpenApiV3_2,
6
- } from "@typia/interface";
7
- import { HttpMigration, OpenApiConverter } from "@typia/utils";
8
- import { HashMap } from "tstl";
9
-
10
- import { StringUtil } from "../StringUtil";
11
- import { AutoBeOpenApiEndpointComparator } from "./AutoBeOpenApiEndpointComparator";
12
-
13
- export function transformOpenApiDocument(
14
- input: AutoBeOpenApi.IDocument,
15
- ): OpenApi.IDocument {
16
- const dict: HashMap<AutoBeOpenApi.IEndpoint, string> = new HashMap(
17
- AutoBeOpenApiEndpointComparator.hashCode,
18
- AutoBeOpenApiEndpointComparator.equals,
19
- );
20
- const paths: Record<string, OpenApi.IPath> = {};
21
-
22
- for (const op of input.operations) {
23
- dict.set(op, op.name);
24
- paths[op.path] ??= {};
25
- paths[op.path][op.method] = {
26
- summary: StringUtil.summary(op.description),
27
- description:
28
- op.description +
29
- (op.authorizationType !== null &&
30
- op.responseBody?.typeName.endsWith(".IAuthorized") === true
31
- ? "\n\n@setHeader token.access Authorization"
32
- : ""),
33
- parameters: op.parameters.map((p) => ({
34
- name: p.name,
35
- in: "path",
36
- schema: p.schema,
37
- required: true,
38
- description: p.description,
39
- })),
40
- requestBody: op.requestBody
41
- ? {
42
- content: {
43
- "application/json": {
44
- schema: {
45
- $ref: `#/components/schemas/${op.requestBody.typeName}`,
46
- },
47
- },
48
- },
49
- description: op.requestBody.description,
50
- required: true,
51
- }
52
- : undefined,
53
- responses: op.responseBody
54
- ? {
55
- [op.method === "post" ? 201 : 200]: {
56
- content: {
57
- "application/json": {
58
- schema: {
59
- $ref: `#/components/schemas/${op.responseBody.typeName}`,
60
- },
61
- },
62
- },
63
- description: op.responseBody.description,
64
- },
65
- }
66
- : undefined,
67
- ...{
68
- "x-autobe-authorization-type": op.authorizationType,
69
- "x-autobe-authorization-actor": op.authorizationActor,
70
- "x-autobe-prerequisites": op.prerequisites,
71
- "x-samchon-accessor": op.accessor,
72
- "x-autobe-specification": op.specification,
73
- },
74
- };
75
- }
76
-
77
- const document: OpenApi.IDocument = OpenApiConverter.upgradeDocument({
78
- openapi: "3.2.0",
79
- paths,
80
- components: input.components,
81
- } as OpenApiV3_2.IDocument);
82
- const migrate: IHttpMigrateApplication = HttpMigration.application(document);
83
- migrate.routes.forEach((r) => {
84
- if (r.method === "head") return;
85
- const name: string = dict.get({
86
- method: r.method as "post",
87
- path: r.path,
88
- });
89
- if (r.accessor.length >= 2 && r.accessor.at(-2) === name) r.accessor.pop();
90
- r.accessor[r.accessor.length - 1] = name;
91
- r.operation()["x-samchon-accessor"] = r.accessor;
92
- });
93
- return document;
94
- }
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+ import {
3
+ IHttpMigrateApplication,
4
+ OpenApi,
5
+ OpenApiV3_2,
6
+ } from "@typia/interface";
7
+ import { HttpMigration, OpenApiConverter } from "@typia/utils";
8
+ import { HashMap } from "tstl";
9
+
10
+ import { StringUtil } from "../StringUtil";
11
+ import { AutoBeOpenApiEndpointComparator } from "./AutoBeOpenApiEndpointComparator";
12
+
13
+ export function transformOpenApiDocument(
14
+ input: AutoBeOpenApi.IDocument,
15
+ ): OpenApi.IDocument {
16
+ const dict: HashMap<AutoBeOpenApi.IEndpoint, string> = new HashMap(
17
+ AutoBeOpenApiEndpointComparator.hashCode,
18
+ AutoBeOpenApiEndpointComparator.equals,
19
+ );
20
+ const paths: Record<string, OpenApi.IPath> = {};
21
+
22
+ for (const op of input.operations) {
23
+ dict.set(op, op.name);
24
+ paths[op.path] ??= {};
25
+ paths[op.path][op.method] = {
26
+ summary: StringUtil.summary(op.description),
27
+ description:
28
+ op.description +
29
+ (op.authorizationType !== null &&
30
+ op.responseBody?.typeName.endsWith(".IAuthorized") === true
31
+ ? "\n\n@setHeader token.access Authorization"
32
+ : ""),
33
+ parameters: op.parameters.map((p) => ({
34
+ name: p.name,
35
+ in: "path",
36
+ schema: p.schema,
37
+ required: true,
38
+ description: p.description,
39
+ })),
40
+ requestBody: op.requestBody
41
+ ? {
42
+ content: {
43
+ "application/json": {
44
+ schema: {
45
+ $ref: `#/components/schemas/${op.requestBody.typeName}`,
46
+ },
47
+ },
48
+ },
49
+ description: op.requestBody.description,
50
+ required: true,
51
+ }
52
+ : undefined,
53
+ responses: op.responseBody
54
+ ? {
55
+ [op.method === "post" ? 201 : 200]: {
56
+ content: {
57
+ "application/json": {
58
+ schema: {
59
+ $ref: `#/components/schemas/${op.responseBody.typeName}`,
60
+ },
61
+ },
62
+ },
63
+ description: op.responseBody.description,
64
+ },
65
+ }
66
+ : undefined,
67
+ ...{
68
+ "x-autobe-authorization-type": op.authorizationType,
69
+ "x-autobe-authorization-actor": op.authorizationActor,
70
+ "x-autobe-prerequisites": op.prerequisites,
71
+ "x-samchon-accessor": op.accessor,
72
+ "x-autobe-specification": op.specification,
73
+ },
74
+ };
75
+ }
76
+
77
+ const document: OpenApi.IDocument = OpenApiConverter.upgradeDocument({
78
+ openapi: "3.2.0",
79
+ paths,
80
+ components: input.components,
81
+ } as OpenApiV3_2.IDocument);
82
+ const migrate: IHttpMigrateApplication = HttpMigration.application(document);
83
+ migrate.routes.forEach((r) => {
84
+ if (r.method === "head") return;
85
+ const name: string = dict.get({
86
+ method: r.method as "post",
87
+ path: r.path,
88
+ });
89
+ if (r.accessor.length >= 2 && r.accessor.at(-2) === name) r.accessor.pop();
90
+ r.accessor[r.accessor.length - 1] = name;
91
+ r.operation()["x-samchon-accessor"] = r.accessor;
92
+ });
93
+ return document;
94
+ }
@@ -1 +1 @@
1
- export * from "./writePrismaApplication";
1
+ export * from "./writePrismaApplication";