@typia/utils 12.0.1 → 12.1.0-dev.20260325
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 +21 -21
- package/README.md +85 -85
- package/lib/http/internal/HttpLlmApplicationComposer.mjs +1 -5
- package/lib/http/internal/HttpLlmApplicationComposer.mjs.map +1 -1
- package/lib/index.mjs +10 -10
- package/lib/utils/LlmJson.mjs +1 -8
- package/lib/utils/LlmJson.mjs.map +1 -1
- package/lib/validators/internal/OpenApiOneOfValidator.mjs +1 -5
- package/lib/validators/internal/OpenApiOneOfValidator.mjs.map +1 -1
- package/package.json +3 -3
- package/src/converters/OpenApiConverter.ts +375 -375
- package/src/converters/internal/OpenApiV3Downgrader.ts +381 -381
- package/src/converters/internal/OpenApiV3Upgrader.ts +494 -494
- package/src/converters/internal/OpenApiV3_1Downgrader.ts +318 -318
- package/src/converters/internal/OpenApiV3_1Upgrader.ts +710 -710
- package/src/converters/internal/OpenApiV3_2Upgrader.ts +342 -342
- package/src/converters/internal/SwaggerV2Downgrader.ts +450 -450
- package/src/converters/internal/SwaggerV2Upgrader.ts +547 -547
- package/src/http/HttpError.ts +114 -114
- package/src/http/HttpLlm.ts +169 -169
- package/src/http/HttpMigration.ts +94 -94
- package/src/http/internal/HttpMigrateApplicationComposer.ts +56 -56
- package/src/http/internal/HttpMigrateRouteComposer.ts +505 -505
- package/src/utils/LlmJson.ts +173 -173
- package/src/utils/internal/parseLenientJson.ts +919 -919
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IHttpConnection,
|
|
3
|
-
IHttpMigrateApplication,
|
|
4
|
-
IHttpMigrateRoute,
|
|
5
|
-
IHttpResponse,
|
|
6
|
-
OpenApi,
|
|
7
|
-
OpenApiV3,
|
|
8
|
-
OpenApiV3_1,
|
|
9
|
-
OpenApiV3_2,
|
|
10
|
-
SwaggerV2,
|
|
11
|
-
} from "@typia/interface";
|
|
12
|
-
|
|
13
|
-
import { OpenApiConverter } from "../converters/OpenApiConverter";
|
|
14
|
-
import { HttpMigrateApplicationComposer } from "./internal/HttpMigrateApplicationComposer";
|
|
15
|
-
import { HttpMigrateRouteFetcher } from "./internal/HttpMigrateRouteFetcher";
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* OpenAPI to HTTP migration utilities.
|
|
19
|
-
*
|
|
20
|
-
* `HttpMigration` converts OpenAPI documents into executable HTTP routes
|
|
21
|
-
* ({@link IHttpMigrateApplication}). Unlike {@link HttpLlm} which targets LLM
|
|
22
|
-
* function calling, this focuses on SDK/client code generation.
|
|
23
|
-
*
|
|
24
|
-
* Supports all OpenAPI versions (Swagger 2.0, OpenAPI 3.0, 3.1) through
|
|
25
|
-
* automatic conversion to normalized {@link OpenApi} format.
|
|
26
|
-
*
|
|
27
|
-
* Main functions:
|
|
28
|
-
*
|
|
29
|
-
* - {@link application}: Convert OpenAPI document to
|
|
30
|
-
* {@link IHttpMigrateApplication}
|
|
31
|
-
* - {@link execute}: Call a route and return response body
|
|
32
|
-
* - {@link propagate}: Call a route and return full HTTP response (including
|
|
33
|
-
* non-2xx)
|
|
34
|
-
*
|
|
35
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
36
|
-
*/
|
|
37
|
-
export namespace HttpMigration {
|
|
38
|
-
/**
|
|
39
|
-
* Convert OpenAPI document to migration application.
|
|
40
|
-
*
|
|
41
|
-
* @param document OpenAPI document (any version)
|
|
42
|
-
* @returns Migration application with callable routes
|
|
43
|
-
*/
|
|
44
|
-
export const application = (
|
|
45
|
-
document:
|
|
46
|
-
| OpenApi.IDocument
|
|
47
|
-
| SwaggerV2.IDocument
|
|
48
|
-
| OpenApiV3.IDocument
|
|
49
|
-
| OpenApiV3_1.IDocument
|
|
50
|
-
| OpenApiV3_2.IDocument,
|
|
51
|
-
): IHttpMigrateApplication =>
|
|
52
|
-
HttpMigrateApplicationComposer.compose(
|
|
53
|
-
OpenApiConverter.upgradeDocument(document),
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Execute HTTP route.
|
|
58
|
-
*
|
|
59
|
-
* @param props Fetch properties
|
|
60
|
-
* @returns Response body
|
|
61
|
-
* @throws HttpError on non-2xx status
|
|
62
|
-
*/
|
|
63
|
-
export const execute = (props: IFetchProps): Promise<unknown> =>
|
|
64
|
-
HttpMigrateRouteFetcher.execute(props);
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Execute HTTP route and return full response.
|
|
68
|
-
*
|
|
69
|
-
* @param props Fetch properties
|
|
70
|
-
* @returns Full HTTP response including non-2xx
|
|
71
|
-
*/
|
|
72
|
-
export const propagate = (props: IFetchProps): Promise<IHttpResponse> =>
|
|
73
|
-
HttpMigrateRouteFetcher.propagate(props);
|
|
74
|
-
|
|
75
|
-
/** Properties for HTTP route execution. */
|
|
76
|
-
export interface IFetchProps {
|
|
77
|
-
/** HTTP connection info. */
|
|
78
|
-
connection: IHttpConnection;
|
|
79
|
-
|
|
80
|
-
/** Route to execute. */
|
|
81
|
-
route: IHttpMigrateRoute;
|
|
82
|
-
|
|
83
|
-
/** Path parameters. */
|
|
84
|
-
parameters:
|
|
85
|
-
| Array<string | number | boolean | bigint | null>
|
|
86
|
-
| Record<string, string | number | boolean | bigint | null>;
|
|
87
|
-
|
|
88
|
-
/** Query parameters. */
|
|
89
|
-
query?: object | undefined;
|
|
90
|
-
|
|
91
|
-
/** Request body. */
|
|
92
|
-
body?: object | undefined;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
IHttpConnection,
|
|
3
|
+
IHttpMigrateApplication,
|
|
4
|
+
IHttpMigrateRoute,
|
|
5
|
+
IHttpResponse,
|
|
6
|
+
OpenApi,
|
|
7
|
+
OpenApiV3,
|
|
8
|
+
OpenApiV3_1,
|
|
9
|
+
OpenApiV3_2,
|
|
10
|
+
SwaggerV2,
|
|
11
|
+
} from "@typia/interface";
|
|
12
|
+
|
|
13
|
+
import { OpenApiConverter } from "../converters/OpenApiConverter";
|
|
14
|
+
import { HttpMigrateApplicationComposer } from "./internal/HttpMigrateApplicationComposer";
|
|
15
|
+
import { HttpMigrateRouteFetcher } from "./internal/HttpMigrateRouteFetcher";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* OpenAPI to HTTP migration utilities.
|
|
19
|
+
*
|
|
20
|
+
* `HttpMigration` converts OpenAPI documents into executable HTTP routes
|
|
21
|
+
* ({@link IHttpMigrateApplication}). Unlike {@link HttpLlm} which targets LLM
|
|
22
|
+
* function calling, this focuses on SDK/client code generation.
|
|
23
|
+
*
|
|
24
|
+
* Supports all OpenAPI versions (Swagger 2.0, OpenAPI 3.0, 3.1) through
|
|
25
|
+
* automatic conversion to normalized {@link OpenApi} format.
|
|
26
|
+
*
|
|
27
|
+
* Main functions:
|
|
28
|
+
*
|
|
29
|
+
* - {@link application}: Convert OpenAPI document to
|
|
30
|
+
* {@link IHttpMigrateApplication}
|
|
31
|
+
* - {@link execute}: Call a route and return response body
|
|
32
|
+
* - {@link propagate}: Call a route and return full HTTP response (including
|
|
33
|
+
* non-2xx)
|
|
34
|
+
*
|
|
35
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
36
|
+
*/
|
|
37
|
+
export namespace HttpMigration {
|
|
38
|
+
/**
|
|
39
|
+
* Convert OpenAPI document to migration application.
|
|
40
|
+
*
|
|
41
|
+
* @param document OpenAPI document (any version)
|
|
42
|
+
* @returns Migration application with callable routes
|
|
43
|
+
*/
|
|
44
|
+
export const application = (
|
|
45
|
+
document:
|
|
46
|
+
| OpenApi.IDocument
|
|
47
|
+
| SwaggerV2.IDocument
|
|
48
|
+
| OpenApiV3.IDocument
|
|
49
|
+
| OpenApiV3_1.IDocument
|
|
50
|
+
| OpenApiV3_2.IDocument,
|
|
51
|
+
): IHttpMigrateApplication =>
|
|
52
|
+
HttpMigrateApplicationComposer.compose(
|
|
53
|
+
OpenApiConverter.upgradeDocument(document),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Execute HTTP route.
|
|
58
|
+
*
|
|
59
|
+
* @param props Fetch properties
|
|
60
|
+
* @returns Response body
|
|
61
|
+
* @throws HttpError on non-2xx status
|
|
62
|
+
*/
|
|
63
|
+
export const execute = (props: IFetchProps): Promise<unknown> =>
|
|
64
|
+
HttpMigrateRouteFetcher.execute(props);
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Execute HTTP route and return full response.
|
|
68
|
+
*
|
|
69
|
+
* @param props Fetch properties
|
|
70
|
+
* @returns Full HTTP response including non-2xx
|
|
71
|
+
*/
|
|
72
|
+
export const propagate = (props: IFetchProps): Promise<IHttpResponse> =>
|
|
73
|
+
HttpMigrateRouteFetcher.propagate(props);
|
|
74
|
+
|
|
75
|
+
/** Properties for HTTP route execution. */
|
|
76
|
+
export interface IFetchProps {
|
|
77
|
+
/** HTTP connection info. */
|
|
78
|
+
connection: IHttpConnection;
|
|
79
|
+
|
|
80
|
+
/** Route to execute. */
|
|
81
|
+
route: IHttpMigrateRoute;
|
|
82
|
+
|
|
83
|
+
/** Path parameters. */
|
|
84
|
+
parameters:
|
|
85
|
+
| Array<string | number | boolean | bigint | null>
|
|
86
|
+
| Record<string, string | number | boolean | bigint | null>;
|
|
87
|
+
|
|
88
|
+
/** Query parameters. */
|
|
89
|
+
query?: object | undefined;
|
|
90
|
+
|
|
91
|
+
/** Request body. */
|
|
92
|
+
body?: object | undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IHttpMigrateApplication,
|
|
3
|
-
IHttpMigrateRoute,
|
|
4
|
-
OpenApi,
|
|
5
|
-
} from "@typia/interface";
|
|
6
|
-
|
|
7
|
-
import { EndpointUtil } from "../../utils/internal/EndpointUtil";
|
|
8
|
-
import { HttpMigrateRouteAccessor } from "./HttpMigrateRouteAccessor";
|
|
9
|
-
import { HttpMigrateRouteComposer } from "./HttpMigrateRouteComposer";
|
|
10
|
-
|
|
11
|
-
export namespace HttpMigrateApplicationComposer {
|
|
12
|
-
export const compose = (
|
|
13
|
-
document: OpenApi.IDocument,
|
|
14
|
-
): IHttpMigrateApplication => {
|
|
15
|
-
const errors: IHttpMigrateApplication.IError[] = [];
|
|
16
|
-
const entire: Array<IHttpMigrateRoute | null> = Object.entries({
|
|
17
|
-
...(document.paths ?? {}),
|
|
18
|
-
...(document.webhooks ?? {}),
|
|
19
|
-
})
|
|
20
|
-
.map(([path, collection]) =>
|
|
21
|
-
(["head", "get", "post", "put", "patch", "delete", "query"] as const)
|
|
22
|
-
.filter((method) => collection[method] !== undefined)
|
|
23
|
-
.map((method) => {
|
|
24
|
-
const operation: OpenApi.IOperation = collection[method]!;
|
|
25
|
-
const migrated: IHttpMigrateRoute | string[] =
|
|
26
|
-
HttpMigrateRouteComposer.compose({
|
|
27
|
-
document,
|
|
28
|
-
method,
|
|
29
|
-
path,
|
|
30
|
-
emendedPath: EndpointUtil.reJoinWithDecimalParameters(path),
|
|
31
|
-
operation,
|
|
32
|
-
});
|
|
33
|
-
if (Array.isArray(migrated)) {
|
|
34
|
-
errors.push({
|
|
35
|
-
method,
|
|
36
|
-
path,
|
|
37
|
-
operation: () => operation,
|
|
38
|
-
messages: migrated,
|
|
39
|
-
});
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
return migrated;
|
|
43
|
-
}),
|
|
44
|
-
)
|
|
45
|
-
.flat();
|
|
46
|
-
const operations: IHttpMigrateRoute[] = entire.filter(
|
|
47
|
-
(o): o is IHttpMigrateRoute => !!o,
|
|
48
|
-
);
|
|
49
|
-
HttpMigrateRouteAccessor.overwrite(operations);
|
|
50
|
-
return {
|
|
51
|
-
document: () => document,
|
|
52
|
-
routes: operations,
|
|
53
|
-
errors,
|
|
54
|
-
} satisfies IHttpMigrateApplication as IHttpMigrateApplication;
|
|
55
|
-
};
|
|
56
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
IHttpMigrateApplication,
|
|
3
|
+
IHttpMigrateRoute,
|
|
4
|
+
OpenApi,
|
|
5
|
+
} from "@typia/interface";
|
|
6
|
+
|
|
7
|
+
import { EndpointUtil } from "../../utils/internal/EndpointUtil";
|
|
8
|
+
import { HttpMigrateRouteAccessor } from "./HttpMigrateRouteAccessor";
|
|
9
|
+
import { HttpMigrateRouteComposer } from "./HttpMigrateRouteComposer";
|
|
10
|
+
|
|
11
|
+
export namespace HttpMigrateApplicationComposer {
|
|
12
|
+
export const compose = (
|
|
13
|
+
document: OpenApi.IDocument,
|
|
14
|
+
): IHttpMigrateApplication => {
|
|
15
|
+
const errors: IHttpMigrateApplication.IError[] = [];
|
|
16
|
+
const entire: Array<IHttpMigrateRoute | null> = Object.entries({
|
|
17
|
+
...(document.paths ?? {}),
|
|
18
|
+
...(document.webhooks ?? {}),
|
|
19
|
+
})
|
|
20
|
+
.map(([path, collection]) =>
|
|
21
|
+
(["head", "get", "post", "put", "patch", "delete", "query"] as const)
|
|
22
|
+
.filter((method) => collection[method] !== undefined)
|
|
23
|
+
.map((method) => {
|
|
24
|
+
const operation: OpenApi.IOperation = collection[method]!;
|
|
25
|
+
const migrated: IHttpMigrateRoute | string[] =
|
|
26
|
+
HttpMigrateRouteComposer.compose({
|
|
27
|
+
document,
|
|
28
|
+
method,
|
|
29
|
+
path,
|
|
30
|
+
emendedPath: EndpointUtil.reJoinWithDecimalParameters(path),
|
|
31
|
+
operation,
|
|
32
|
+
});
|
|
33
|
+
if (Array.isArray(migrated)) {
|
|
34
|
+
errors.push({
|
|
35
|
+
method,
|
|
36
|
+
path,
|
|
37
|
+
operation: () => operation,
|
|
38
|
+
messages: migrated,
|
|
39
|
+
});
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return migrated;
|
|
43
|
+
}),
|
|
44
|
+
)
|
|
45
|
+
.flat();
|
|
46
|
+
const operations: IHttpMigrateRoute[] = entire.filter(
|
|
47
|
+
(o): o is IHttpMigrateRoute => !!o,
|
|
48
|
+
);
|
|
49
|
+
HttpMigrateRouteAccessor.overwrite(operations);
|
|
50
|
+
return {
|
|
51
|
+
document: () => document,
|
|
52
|
+
routes: operations,
|
|
53
|
+
errors,
|
|
54
|
+
} satisfies IHttpMigrateApplication as IHttpMigrateApplication;
|
|
55
|
+
};
|
|
56
|
+
}
|