@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.
- package/LICENSE +661 -661
- package/README.md +261 -0
- package/lib/AutoBeEscaper.d.ts +4 -0
- package/lib/AutoBeEscaper.js +85 -0
- package/lib/AutoBeEscaper.js.map +1 -0
- package/lib/StringUtil.d.ts +1 -0
- package/lib/StringUtil.js +15 -36
- package/lib/StringUtil.js.map +1 -1
- package/lib/aggregate/AutoBeProcessAggregateFactory.js +9 -0
- package/lib/aggregate/AutoBeProcessAggregateFactory.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/interface/AutoBeOpenApiEndpointComparator.d.ts +1 -0
- package/lib/interface/AutoBeOpenApiEndpointComparator.js +4 -0
- package/lib/interface/AutoBeOpenApiEndpointComparator.js.map +1 -1
- package/lib/interface/AutoBeOpenApiTypeChecker.d.ts +14 -0
- package/lib/interface/AutoBeOpenApiTypeChecker.js +67 -0
- package/lib/interface/AutoBeOpenApiTypeChecker.js.map +1 -1
- package/lib/interface/invertOpenApiDocument.d.ts +1 -1
- package/lib/interface/invertOpenApiDocument.js +22 -7
- package/lib/interface/invertOpenApiDocument.js.map +1 -1
- package/lib/interface/missedOpenApiSchemas.js +3 -3
- package/lib/interface/missedOpenApiSchemas.js.map +1 -1
- package/lib/interface/revertOpenApiAccessor.js +2 -2
- package/lib/interface/revertOpenApiAccessor.js.map +1 -1
- package/lib/interface/transformOpenApiDocument.d.ts +2 -2
- package/lib/interface/transformOpenApiDocument.js +14 -11
- package/lib/interface/transformOpenApiDocument.js.map +1 -1
- package/lib/prisma/writePrismaApplication.d.ts +2 -2
- package/lib/prisma/writePrismaApplication.js +75 -66
- package/lib/prisma/writePrismaApplication.js.map +1 -1
- package/lib/test/validateTestExpression.js +3 -1
- package/lib/test/validateTestExpression.js.map +1 -1
- package/lib/test/validateTestStatement.js +3 -1
- package/lib/test/validateTestStatement.js.map +1 -1
- package/package.json +5 -5
- package/src/ArrayUtil.ts +21 -21
- package/src/AutoBeEscaper.ts +83 -0
- package/src/MapUtil.ts +10 -10
- package/src/StringUtil.ts +34 -59
- package/src/aggregate/AutoBeFunctionCallingMetricFactory.ts +44 -44
- package/src/aggregate/AutoBeProcessAggregateFactory.ts +161 -152
- package/src/aggregate/TokenUsageComputer.ts +49 -49
- package/src/aggregate/index.ts +3 -3
- package/src/index.ts +10 -9
- package/src/interface/AutoBeOpenApiEndpointComparator.ts +27 -20
- package/src/interface/AutoBeOpenApiTypeChecker.ts +127 -43
- package/src/interface/index.ts +6 -6
- package/src/interface/invertOpenApiDocument.ts +80 -68
- package/src/interface/missedOpenApiSchemas.ts +25 -25
- package/src/interface/revertOpenApiAccessor.ts +25 -25
- package/src/interface/transformOpenApiDocument.ts +94 -91
- package/src/prisma/index.ts +1 -1
- package/src/prisma/writePrismaApplication.ts +456 -439
- package/src/test/AutoBeTestExpressionValidator.ts +253 -253
- package/src/test/AutoBeTestStatementValidator.ts +72 -72
- package/src/test/IAutoBeTextValidateContext.ts +10 -10
- package/src/test/index.ts +2 -2
- package/src/test/validateTestApiOperateStatement.ts +92 -92
- package/src/test/validateTestExpression.ts +16 -10
- package/src/test/validateTestFunction.ts +7 -7
- package/src/test/validateTestStatement.ts +16 -10
|
@@ -1,43 +1,127 @@
|
|
|
1
|
-
import { AutoBeOpenApi } from "@autobe/interface";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
(schema
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
schema
|
|
11
|
-
|
|
12
|
-
(schema
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
schema
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
+
}
|
package/src/interface/index.ts
CHANGED
|
@@ -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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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 "@
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "@
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "@
|
|
8
|
-
import { HashMap } from "tstl";
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
AutoBeOpenApiEndpointComparator.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
paths[op.path]
|
|
25
|
-
|
|
26
|
-
description
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
op.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
required: true,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"x-autobe-
|
|
69
|
-
"x-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
+
}
|
package/src/prisma/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./writePrismaApplication";
|
|
1
|
+
export * from "./writePrismaApplication";
|