@autobe/utils 0.29.1 → 0.30.0-dev.20260315

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.
Files changed (63) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +261 -0
  3. package/lib/AutoBeEscaper.d.ts +4 -0
  4. package/lib/AutoBeEscaper.js +85 -0
  5. package/lib/AutoBeEscaper.js.map +1 -0
  6. package/lib/StringUtil.d.ts +1 -0
  7. package/lib/StringUtil.js +15 -36
  8. package/lib/StringUtil.js.map +1 -1
  9. package/lib/aggregate/AutoBeProcessAggregateFactory.js +9 -0
  10. package/lib/aggregate/AutoBeProcessAggregateFactory.js.map +1 -1
  11. package/lib/index.d.ts +1 -0
  12. package/lib/index.js +1 -0
  13. package/lib/index.js.map +1 -1
  14. package/lib/interface/AutoBeOpenApiEndpointComparator.d.ts +1 -0
  15. package/lib/interface/AutoBeOpenApiEndpointComparator.js +4 -0
  16. package/lib/interface/AutoBeOpenApiEndpointComparator.js.map +1 -1
  17. package/lib/interface/AutoBeOpenApiTypeChecker.d.ts +14 -0
  18. package/lib/interface/AutoBeOpenApiTypeChecker.js +67 -0
  19. package/lib/interface/AutoBeOpenApiTypeChecker.js.map +1 -1
  20. package/lib/interface/invertOpenApiDocument.d.ts +1 -1
  21. package/lib/interface/invertOpenApiDocument.js +22 -7
  22. package/lib/interface/invertOpenApiDocument.js.map +1 -1
  23. package/lib/interface/missedOpenApiSchemas.js +3 -3
  24. package/lib/interface/missedOpenApiSchemas.js.map +1 -1
  25. package/lib/interface/revertOpenApiAccessor.js +2 -2
  26. package/lib/interface/revertOpenApiAccessor.js.map +1 -1
  27. package/lib/interface/transformOpenApiDocument.d.ts +2 -2
  28. package/lib/interface/transformOpenApiDocument.js +14 -11
  29. package/lib/interface/transformOpenApiDocument.js.map +1 -1
  30. package/lib/prisma/writePrismaApplication.d.ts +2 -2
  31. package/lib/prisma/writePrismaApplication.js +75 -66
  32. package/lib/prisma/writePrismaApplication.js.map +1 -1
  33. package/lib/test/validateTestExpression.js +3 -1
  34. package/lib/test/validateTestExpression.js.map +1 -1
  35. package/lib/test/validateTestStatement.js +3 -1
  36. package/lib/test/validateTestStatement.js.map +1 -1
  37. package/package.json +5 -5
  38. package/src/ArrayUtil.ts +21 -21
  39. package/src/AutoBeEscaper.ts +83 -0
  40. package/src/MapUtil.ts +10 -10
  41. package/src/StringUtil.ts +34 -59
  42. package/src/aggregate/AutoBeFunctionCallingMetricFactory.ts +44 -44
  43. package/src/aggregate/AutoBeProcessAggregateFactory.ts +161 -152
  44. package/src/aggregate/TokenUsageComputer.ts +49 -49
  45. package/src/aggregate/index.ts +3 -3
  46. package/src/index.ts +10 -9
  47. package/src/interface/AutoBeOpenApiEndpointComparator.ts +27 -20
  48. package/src/interface/AutoBeOpenApiTypeChecker.ts +127 -43
  49. package/src/interface/index.ts +6 -6
  50. package/src/interface/invertOpenApiDocument.ts +80 -68
  51. package/src/interface/missedOpenApiSchemas.ts +25 -25
  52. package/src/interface/revertOpenApiAccessor.ts +25 -25
  53. package/src/interface/transformOpenApiDocument.ts +94 -91
  54. package/src/prisma/index.ts +1 -1
  55. package/src/prisma/writePrismaApplication.ts +456 -439
  56. package/src/test/AutoBeTestExpressionValidator.ts +253 -253
  57. package/src/test/AutoBeTestStatementValidator.ts +72 -72
  58. package/src/test/IAutoBeTextValidateContext.ts +10 -10
  59. package/src/test/index.ts +2 -2
  60. package/src/test/validateTestApiOperateStatement.ts +92 -92
  61. package/src/test/validateTestExpression.ts +16 -10
  62. package/src/test/validateTestFunction.ts +7 -7
  63. package/src/test/validateTestStatement.ts +16 -10
@@ -1,43 +1,127 @@
1
- import { AutoBeOpenApi } from "@autobe/interface";
2
-
3
- export namespace AutoBeOpenApiTypeChecker {
4
- export const isArray = (
5
- schema: AutoBeOpenApi.IJsonSchema,
6
- ): schema is AutoBeOpenApi.IJsonSchema.IArray =>
7
- (schema as AutoBeOpenApi.IJsonSchema.IArray).type === "array";
8
-
9
- export const isObject = (
10
- schema: AutoBeOpenApi.IJsonSchema,
11
- ): schema is AutoBeOpenApi.IJsonSchema.IObject =>
12
- (schema as AutoBeOpenApi.IJsonSchema.IObject).type === "object";
13
-
14
- export const isOneOf = (
15
- schema: AutoBeOpenApi.IJsonSchema,
16
- ): schema is AutoBeOpenApi.IJsonSchema.IOneOf =>
17
- (schema as AutoBeOpenApi.IJsonSchema.IOneOf).oneOf !== undefined;
18
-
19
- export const isReference = (
20
- schema: AutoBeOpenApi.IJsonSchema,
21
- ): schema is AutoBeOpenApi.IJsonSchema.IReference =>
22
- (schema as AutoBeOpenApi.IJsonSchema.IReference).$ref !== undefined;
23
-
24
- export const isConstant = (
25
- schema: AutoBeOpenApi.IJsonSchema,
26
- ): schema is AutoBeOpenApi.IJsonSchema.IConstant =>
27
- (schema as AutoBeOpenApi.IJsonSchema.IConstant).const !== undefined;
28
-
29
- export const isInteger = (
30
- schema: AutoBeOpenApi.IJsonSchema,
31
- ): schema is AutoBeOpenApi.IJsonSchema.IInteger =>
32
- (schema as AutoBeOpenApi.IJsonSchema.IInteger).type === "integer";
33
-
34
- export const isNumber = (
35
- schema: AutoBeOpenApi.IJsonSchema,
36
- ): schema is AutoBeOpenApi.IJsonSchema.INumber =>
37
- (schema as AutoBeOpenApi.IJsonSchema.INumber).type === "number";
38
-
39
- export const isString = (
40
- schema: AutoBeOpenApi.IJsonSchema,
41
- ): schema is AutoBeOpenApi.IJsonSchema.IString =>
42
- (schema as AutoBeOpenApi.IJsonSchema.IString).type === "string";
43
- }
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+ import { OpenApiTypeChecker } from "@typia/utils";
3
+
4
+ export namespace AutoBeOpenApiTypeChecker {
5
+ export const getKind = (schema: AutoBeOpenApi.IJsonSchema): string => {
6
+ if (isReference(schema)) return "$ref";
7
+ else if (isConstant(schema)) return JSON.stringify(schema.const);
8
+ else if (isOneOf(schema))
9
+ return schema.oneOf.map((s) => getKind(s)).join(" | ");
10
+ else if (isArray(schema)) return `Array<${getKind(schema.items)}>`;
11
+ else if (isObject(schema)) return "object";
12
+ else if (isString(schema)) return "string";
13
+ else if (isInteger(schema)) return "integer";
14
+ else if (isNumber(schema)) return "number";
15
+ else if (isBoolean(schema)) return "boolean";
16
+ else if (isNull(schema)) return "null";
17
+ schema satisfies never;
18
+ return "unknown";
19
+ };
20
+
21
+ export const isArray = (
22
+ schema: AutoBeOpenApi.IJsonSchema,
23
+ ): schema is AutoBeOpenApi.IJsonSchema.IArray =>
24
+ (schema as AutoBeOpenApi.IJsonSchema.IArray).type === "array";
25
+
26
+ export const isObject = (
27
+ schema: AutoBeOpenApi.IJsonSchema,
28
+ ): schema is AutoBeOpenApi.IJsonSchema.IObject =>
29
+ (schema as AutoBeOpenApi.IJsonSchema.IObject).type === "object";
30
+
31
+ export const isOneOf = (
32
+ schema: AutoBeOpenApi.IJsonSchema,
33
+ ): schema is AutoBeOpenApi.IJsonSchema.IOneOf =>
34
+ (schema as AutoBeOpenApi.IJsonSchema.IOneOf).oneOf !== undefined;
35
+
36
+ export const isReference = (
37
+ schema: AutoBeOpenApi.IJsonSchema,
38
+ ): schema is AutoBeOpenApi.IJsonSchema.IReference =>
39
+ (schema as AutoBeOpenApi.IJsonSchema.IReference).$ref !== undefined;
40
+
41
+ export const isConstant = (
42
+ schema: AutoBeOpenApi.IJsonSchema,
43
+ ): schema is AutoBeOpenApi.IJsonSchema.IConstant =>
44
+ (schema as AutoBeOpenApi.IJsonSchema.IConstant).const !== undefined;
45
+
46
+ export const isBoolean = (
47
+ schema: AutoBeOpenApi.IJsonSchema,
48
+ ): schema is AutoBeOpenApi.IJsonSchema.IBoolean =>
49
+ (schema as AutoBeOpenApi.IJsonSchema.IBoolean).type === "boolean";
50
+
51
+ export const isInteger = (
52
+ schema: AutoBeOpenApi.IJsonSchema,
53
+ ): schema is AutoBeOpenApi.IJsonSchema.IInteger =>
54
+ (schema as AutoBeOpenApi.IJsonSchema.IInteger).type === "integer";
55
+
56
+ export const isNumber = (
57
+ schema: AutoBeOpenApi.IJsonSchema,
58
+ ): schema is AutoBeOpenApi.IJsonSchema.INumber =>
59
+ (schema as AutoBeOpenApi.IJsonSchema.INumber).type === "number";
60
+
61
+ export const isString = (
62
+ schema: AutoBeOpenApi.IJsonSchema,
63
+ ): schema is AutoBeOpenApi.IJsonSchema.IString =>
64
+ (schema as AutoBeOpenApi.IJsonSchema.IString).type === "string";
65
+
66
+ export const isNull = (
67
+ schema: AutoBeOpenApi.IJsonSchema,
68
+ ): schema is AutoBeOpenApi.IJsonSchema.INull =>
69
+ (schema as AutoBeOpenApi.IJsonSchema.INull).type === "null";
70
+
71
+ export const isNullable = (schema: AutoBeOpenApi.IJsonSchema): boolean =>
72
+ isNull(schema) ||
73
+ (isOneOf(schema) && schema.oneOf.some((sub) => isNull(sub)));
74
+
75
+ export const visit = (props: {
76
+ components: AutoBeOpenApi.IComponents;
77
+ schema: AutoBeOpenApi.IJsonSchema;
78
+ closure: (schema: AutoBeOpenApi.IJsonSchema, accessor: string) => void;
79
+ }): void =>
80
+ OpenApiTypeChecker.visit({
81
+ components: props.components,
82
+ schema: props.schema,
83
+ closure: (schema, accessor) => {
84
+ props.closure(schema as AutoBeOpenApi.IJsonSchema, accessor);
85
+ },
86
+ });
87
+
88
+ export const skim = (props: {
89
+ closure: (schema: AutoBeOpenApi.IJsonSchema, accessor: string) => void;
90
+ schema: AutoBeOpenApi.IJsonSchema;
91
+ accessor: string;
92
+ }): void => {
93
+ props.closure(props.schema, props.accessor);
94
+ if (isOneOf(props.schema))
95
+ props.schema.oneOf.forEach((sub, index) =>
96
+ skim({
97
+ closure: props.closure,
98
+ schema: sub,
99
+ accessor: `${props.accessor}.oneOf[${index}]`,
100
+ }),
101
+ );
102
+ else if (isArray(props.schema))
103
+ skim({
104
+ closure: props.closure,
105
+ schema: props.schema.items,
106
+ accessor: `${props.accessor}.items`,
107
+ });
108
+ else if (isObject(props.schema)) {
109
+ if (
110
+ typeof props.schema.additionalProperties === "object" &&
111
+ props.schema.additionalProperties !== null
112
+ )
113
+ skim({
114
+ closure: props.closure,
115
+ schema: props.schema.additionalProperties,
116
+ accessor: `${props.accessor}.additionalProperties`,
117
+ });
118
+ for (const [key, value] of Object.entries(props.schema.properties))
119
+ if (value)
120
+ skim({
121
+ closure: props.closure,
122
+ schema: value,
123
+ accessor: `${props.accessor}.properties[${JSON.stringify(key)}]`,
124
+ });
125
+ }
126
+ };
127
+ }
@@ -1,6 +1,6 @@
1
- export * from "./AutoBeOpenApiEndpointComparator";
2
- export * from "./AutoBeOpenApiTypeChecker";
3
- export * from "./invertOpenApiDocument";
4
- export * from "./revertOpenApiAccessor";
5
- export * from "./transformOpenApiDocument";
6
- export * from "./missedOpenApiSchemas";
1
+ export * from "./AutoBeOpenApiEndpointComparator";
2
+ export * from "./AutoBeOpenApiTypeChecker";
3
+ export * from "./invertOpenApiDocument";
4
+ export * from "./revertOpenApiAccessor";
5
+ export * from "./transformOpenApiDocument";
6
+ export * from "./missedOpenApiSchemas";
@@ -1,68 +1,80 @@
1
- import { AutoBeOpenApi } from "@autobe/interface";
2
- import {
3
- HttpMigration,
4
- IHttpMigrateApplication,
5
- OpenApi,
6
- OpenApiTypeChecker,
7
- } from "@samchon/openapi";
8
-
9
- export function invertOpenApiDocument(
10
- document: OpenApi.IDocument,
11
- ): AutoBeOpenApi.IDocument {
12
- const app: IHttpMigrateApplication = HttpMigration.application(document);
13
- return {
14
- operations: app.routes
15
- .filter((r) => r.query === null)
16
- .map(
17
- (r) =>
18
- ({
19
- specification: empty("specification"),
20
- authorizationType: null,
21
- method: r.method as "post",
22
- path: r.path,
23
- summary: r.operation().summary ?? empty("summary"),
24
- description: r.operation().description ?? empty("description"),
25
- parameters: r.parameters.map(
26
- (p) =>
27
- ({
28
- name: p.name,
29
- description:
30
- p.parameter().description ?? empty("description"),
31
- schema: p.schema as any,
32
- }) satisfies AutoBeOpenApi.IParameter,
33
- ),
34
- requestBody:
35
- r.body?.type === "application/json" &&
36
- OpenApiTypeChecker.isReference(r.body.schema)
37
- ? {
38
- description: r.body.description() ?? empty("description"),
39
- typeName: r.body.schema.$ref.split("/").pop()!,
40
- }
41
- : null,
42
- responseBody:
43
- r.success?.type === "application/json" &&
44
- OpenApiTypeChecker.isReference(r.success.schema)
45
- ? {
46
- description:
47
- r.success.description() ?? empty("description"),
48
- typeName: r.success.schema.$ref.split("/").pop()!,
49
- }
50
- : null,
51
- authorizationActor: null,
52
- name: r.accessor.at(-1)!,
53
- prerequisites: [],
54
- }) satisfies AutoBeOpenApi.IOperation,
55
- ),
56
- components: {
57
- schemas: (document.components?.schemas ?? {}) as Record<
58
- string,
59
- AutoBeOpenApi.IJsonSchemaDescriptive
60
- >,
61
- authorizations: [],
62
- },
63
- };
64
- }
65
-
66
- function empty(key: string): string {
67
- return `Describe ${key} as much as possible with clear and concise words.`;
68
- }
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+ import { IHttpMigrateApplication, OpenApi } from "@typia/interface";
3
+ import { HttpMigration, OpenApiTypeChecker } from "@typia/utils";
4
+
5
+ export function invertOpenApiDocument(
6
+ document: OpenApi.IDocument,
7
+ ): AutoBeOpenApi.IDocument {
8
+ const app: IHttpMigrateApplication = HttpMigration.application(document);
9
+ return {
10
+ operations: app.routes
11
+ .filter((r) => r.query === null)
12
+ .map(
13
+ (r) =>
14
+ ({
15
+ authorizationType: null,
16
+ method: r.method as "post",
17
+ path: r.path,
18
+ description:
19
+ writeDescription(r.operation()) ?? empty("description"),
20
+ specification: r.operation()
21
+ ? // biome-ignore lint: intended
22
+ ((r.operation() as any)["x-autobe-specification"] ??
23
+ empty("x-autobe-specification"))
24
+ : empty("x-autobe-specification"),
25
+ accessor: r.accessor,
26
+ parameters: r.parameters.map(
27
+ (p) =>
28
+ ({
29
+ name: p.name,
30
+ description:
31
+ p.parameter().description ?? empty("description"),
32
+ // biome-ignore lint: intended
33
+ schema: p.schema as any,
34
+ }) satisfies AutoBeOpenApi.IParameter,
35
+ ),
36
+ requestBody:
37
+ r.body?.type === "application/json" &&
38
+ OpenApiTypeChecker.isReference(r.body.schema)
39
+ ? {
40
+ description: r.body.description() ?? empty("description"),
41
+ typeName: r.body.schema.$ref.split("/").pop()!,
42
+ }
43
+ : null,
44
+ responseBody:
45
+ r.success?.type === "application/json" &&
46
+ OpenApiTypeChecker.isReference(r.success.schema)
47
+ ? {
48
+ description:
49
+ r.success.description() ?? empty("description"),
50
+ typeName: r.success.schema.$ref.split("/").pop()!,
51
+ }
52
+ : null,
53
+ authorizationActor: null,
54
+ name: r.accessor.at(-1)!,
55
+ prerequisites: [],
56
+ }) satisfies AutoBeOpenApi.IOperation,
57
+ ),
58
+ components: {
59
+ schemas: (document.components?.schemas ?? {}) as Record<
60
+ string,
61
+ AutoBeOpenApi.IJsonSchemaDescriptive
62
+ >,
63
+ authorizations: [],
64
+ },
65
+ };
66
+ }
67
+
68
+ function writeDescription(operation: OpenApi.IOperation): string | undefined {
69
+ if (operation.summary === undefined && operation.description === undefined)
70
+ return undefined;
71
+ if (operation.summary === undefined) return operation.description;
72
+ else if (operation.description === undefined) return operation.summary;
73
+ else if (operation.description.startsWith(operation.summary))
74
+ return operation.description;
75
+ return `${operation.summary}${operation.summary.endsWith(".") ? "" : "."}\n\n${operation.description}`;
76
+ }
77
+
78
+ function empty(key: string): string {
79
+ return `Describe ${key} as much as possible with clear and concise words.`;
80
+ }
@@ -1,25 +1,25 @@
1
- import { AutoBeOpenApi } from "@autobe/interface";
2
- import { OpenApiTypeChecker } from "@samchon/openapi";
3
-
4
- export const missedOpenApiSchemas = (
5
- document: AutoBeOpenApi.IDocument,
6
- ): string[] => {
7
- const missed: Set<string> = new Set();
8
- const check = (name: string) => {
9
- if (document.components.schemas[name] === undefined) missed.add(name);
10
- };
11
- for (const op of document.operations) {
12
- if (op.requestBody !== null) check(op.requestBody.typeName);
13
- if (op.responseBody !== null) check(op.responseBody.typeName);
14
- }
15
- for (const value of Object.values(document.components.schemas))
16
- OpenApiTypeChecker.visit({
17
- components: document.components,
18
- schema: value,
19
- closure: (next) => {
20
- if (OpenApiTypeChecker.isReference(next))
21
- check(next.$ref.split("/").pop()!);
22
- },
23
- });
24
- return Array.from(missed);
25
- };
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+ import { OpenApiTypeChecker } from "@typia/utils";
3
+
4
+ export const missedOpenApiSchemas = (
5
+ document: AutoBeOpenApi.IDocument,
6
+ ): string[] => {
7
+ const missed: Set<string> = new Set();
8
+ const check = (name: string) => {
9
+ if (document.components.schemas[name] === undefined) missed.add(name);
10
+ };
11
+ for (const op of document.operations) {
12
+ if (op.requestBody !== null) check(op.requestBody.typeName);
13
+ if (op.responseBody !== null) check(op.responseBody.typeName);
14
+ }
15
+ for (const value of Object.values(document.components.schemas))
16
+ OpenApiTypeChecker.visit({
17
+ components: document.components,
18
+ schema: value,
19
+ closure: (next) => {
20
+ if (OpenApiTypeChecker.isReference(next))
21
+ check(next.$ref.split("/").pop()!);
22
+ },
23
+ });
24
+ return Array.from(missed);
25
+ };
@@ -1,25 +1,25 @@
1
- import { AutoBeOpenApi } from "@autobe/interface";
2
- import {
3
- HttpMigration,
4
- IHttpMigrateApplication,
5
- IHttpMigrateRoute,
6
- OpenApi,
7
- } from "@samchon/openapi";
8
-
9
- import { transformOpenApiDocument } from "./transformOpenApiDocument";
10
-
11
- export const revertOpenApiAccessor = (
12
- document: AutoBeOpenApi.IDocument,
13
- ): void => {
14
- const regular: OpenApi.IDocument = transformOpenApiDocument(document);
15
- const migrate: IHttpMigrateApplication = HttpMigration.application(regular);
16
- for (const op of document.operations) {
17
- const route: IHttpMigrateRoute | undefined = migrate.routes.find(
18
- (r) => r.method === op.method && r.path === op.path,
19
- );
20
- if (route === undefined) continue;
21
- if (route.accessor.length !== 0 && route.accessor.at(-1) !== op.name)
22
- op.name = route.accessor.at(-1)!;
23
- op.accessor = route.accessor;
24
- }
25
- };
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+ import {
3
+ IHttpMigrateApplication,
4
+ IHttpMigrateRoute,
5
+ OpenApi,
6
+ } from "@typia/interface";
7
+ import { HttpMigration } from "@typia/utils";
8
+
9
+ import { transformOpenApiDocument } from "./transformOpenApiDocument";
10
+
11
+ export const revertOpenApiAccessor = (
12
+ document: AutoBeOpenApi.IDocument,
13
+ ): void => {
14
+ const regular: OpenApi.IDocument = transformOpenApiDocument(document);
15
+ const migrate: IHttpMigrateApplication = HttpMigration.application(regular);
16
+ for (const op of document.operations) {
17
+ const route: IHttpMigrateRoute | undefined = migrate.routes.find(
18
+ (r) => r.method === op.method && r.path === op.path,
19
+ );
20
+ if (route === undefined) continue;
21
+ if (route.accessor.length !== 0 && route.accessor.at(-1) !== op.name)
22
+ op.name = route.accessor.at(-1)!;
23
+ op.accessor = route.accessor;
24
+ }
25
+ };
@@ -1,91 +1,94 @@
1
- import { AutoBeOpenApi } from "@autobe/interface";
2
- import {
3
- HttpMigration,
4
- IHttpMigrateApplication,
5
- OpenApi,
6
- OpenApiV3_1,
7
- } from "@samchon/openapi";
8
- import { HashMap } from "tstl";
9
-
10
- import { AutoBeOpenApiEndpointComparator } from "./AutoBeOpenApiEndpointComparator";
11
-
12
- export function transformOpenApiDocument(
13
- document: AutoBeOpenApi.IDocument,
14
- ): OpenApi.IDocument {
15
- const dict: HashMap<AutoBeOpenApi.IEndpoint, string> = new HashMap(
16
- AutoBeOpenApiEndpointComparator.hashCode,
17
- AutoBeOpenApiEndpointComparator.equals,
18
- );
19
- const paths: Record<string, OpenApi.IPath> = {};
20
-
21
- for (const op of document.operations) {
22
- dict.set(op, op.name);
23
- paths[op.path] ??= {};
24
- paths[op.path][op.method] = {
25
- summary: op.summary,
26
- description:
27
- op.description +
28
- (op.authorizationType !== null &&
29
- op.responseBody?.typeName.endsWith(".IAuthorized") === true
30
- ? "\n\n@setHeader token.access Authorization"
31
- : ""),
32
- parameters: op.parameters.map((p) => ({
33
- name: p.name,
34
- in: "path",
35
- schema: p.schema,
36
- description: p.description,
37
- required: true,
38
- })),
39
- requestBody: op.requestBody
40
- ? {
41
- content: {
42
- "application/json": {
43
- schema: {
44
- $ref: `#/components/schemas/${op.requestBody.typeName}`,
45
- },
46
- },
47
- },
48
- description: op.requestBody.description,
49
- required: true,
50
- }
51
- : undefined,
52
- responses: op.responseBody
53
- ? {
54
- [op.method === "post" ? 201 : 200]: {
55
- content: {
56
- "application/json": {
57
- schema: {
58
- $ref: `#/components/schemas/${op.responseBody.typeName}`,
59
- },
60
- },
61
- },
62
- description: op.responseBody.description,
63
- },
64
- }
65
- : undefined,
66
- ...{
67
- "x-autobe-prerequisites": op.prerequisites,
68
- "x-autobe-specification": op.specification,
69
- "x-samchon-accessor": op.accessor,
70
- },
71
- };
72
- }
73
-
74
- const result: OpenApi.IDocument = OpenApi.convert({
75
- openapi: "3.1.0",
76
- paths,
77
- components: document.components,
78
- } as OpenApiV3_1.IDocument);
79
- const migrate: IHttpMigrateApplication = HttpMigration.application(result);
80
- migrate.routes.forEach((r) => {
81
- if (r.method === "head") return;
82
- const name: string = dict.get({
83
- method: r.method,
84
- path: r.path,
85
- });
86
- if (r.accessor.length >= 2 && r.accessor.at(-2) === name) r.accessor.pop();
87
- r.accessor[r.accessor.length - 1] = name;
88
- r.operation()["x-samchon-accessor"] = r.accessor;
89
- });
90
- return result;
91
- }
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";