typia 10.0.0 → 10.0.2
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/README.md +4 -2
- package/lib/index.mjs +2 -2
- package/lib/json.d.mts +108 -21
- package/lib/json.d.ts +108 -21
- package/lib/json.js +8 -3
- package/lib/json.js.map +1 -1
- package/lib/json.mjs +7 -3
- package/lib/module.d.mts +1 -1
- package/lib/module.d.ts +1 -1
- package/lib/module.js +1 -1
- package/lib/module.js.map +1 -1
- package/lib/programmers/json/JsonApplicationProgrammer.d.mts +2 -2
- package/lib/programmers/json/JsonApplicationProgrammer.d.ts +2 -2
- package/lib/programmers/json/JsonApplicationProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonAssertStringifyProgrammer.js +1 -1
- package/lib/programmers/json/JsonAssertStringifyProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonAssertStringifyProgrammer.mjs +1 -1
- package/lib/programmers/json/JsonIsStringifyProgrammer.js +1 -1
- package/lib/programmers/json/JsonIsStringifyProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonIsStringifyProgrammer.mjs +1 -1
- package/lib/programmers/json/JsonValidateStringifyProgrammer.js +1 -1
- package/lib/programmers/json/JsonValidateStringifyProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonValidateStringifyProgrammer.mjs +1 -1
- package/lib/programmers/protobuf/ProtobufAssertEncodeProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufAssertEncodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufAssertEncodeProgrammer.mjs +1 -1
- package/lib/programmers/protobuf/ProtobufIsEncodeProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufIsEncodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufIsEncodeProgrammer.mjs +1 -1
- package/lib/programmers/protobuf/ProtobufValidateEncodeProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufValidateEncodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufValidateEncodeProgrammer.mjs +1 -1
- package/lib/schemas/json/{__IJsonApplication.d.mts → IJsonSchemaApplication.d.mts} +4 -4
- package/lib/schemas/json/{__IJsonApplication.d.ts → IJsonSchemaApplication.d.ts} +4 -4
- package/lib/schemas/json/{__IJsonApplication.js → IJsonSchemaApplication.js} +1 -1
- package/lib/schemas/json/IJsonSchemaApplication.js.map +1 -0
- package/lib/schemas/json/IJsonSchemaApplication.mjs +2 -0
- package/lib/schemas/json/IJsonSchemaApplication.mjs.map +1 -0
- package/lib/transformers/CallExpressionTransformer.js +3 -1
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.mjs +3 -1
- package/lib/transformers/features/json/JsonApplicationTransformer.d.mts +5 -0
- package/lib/transformers/features/json/JsonApplicationTransformer.d.ts +5 -0
- package/lib/transformers/features/json/JsonApplicationTransformer.js +85 -92
- package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/json/JsonApplicationTransformer.mjs +81 -0
- package/package.json +2 -2
- package/src/json.ts +122 -25
- package/src/module.ts +1 -1
- package/src/programmers/json/JsonApplicationProgrammer.ts +17 -14
- package/src/programmers/json/JsonAssertStringifyProgrammer.ts +1 -1
- package/src/programmers/json/JsonIsStringifyProgrammer.ts +1 -1
- package/src/programmers/json/JsonValidateStringifyProgrammer.ts +1 -1
- package/src/programmers/llm/LlmApplicationProgrammer.ts +4 -4
- package/src/programmers/protobuf/ProtobufAssertEncodeProgrammer.ts +1 -1
- package/src/programmers/protobuf/ProtobufIsEncodeProgrammer.ts +1 -1
- package/src/programmers/protobuf/ProtobufValidateEncodeProgrammer.ts +1 -1
- package/src/schemas/json/{__IJsonApplication.ts → IJsonSchemaApplication.ts} +7 -5
- package/src/transformers/CallExpressionTransformer.ts +3 -1
- package/src/transformers/features/json/JsonApplicationTransformer.ts +92 -92
- package/lib/schemas/json/IJsonApplication.d.mts +0 -16
- package/lib/schemas/json/IJsonApplication.d.ts +0 -16
- package/lib/schemas/json/IJsonApplication.js +0 -58
- package/lib/schemas/json/IJsonApplication.js.map +0 -1
- package/lib/schemas/json/IJsonApplication.mjs +0 -2
- package/lib/schemas/json/IJsonApplication.mjs.map +0 -1
- package/lib/schemas/json/__IJsonApplication.js.map +0 -1
- package/lib/schemas/json/__IJsonApplication.mjs +0 -2
- package/lib/schemas/json/__IJsonApplication.mjs.map +0 -1
- package/src/schemas/json/IJsonApplication.ts +0 -77
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typia",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.2",
|
|
4
4
|
"description": "Superfast runtime validators with only one line",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"homepage": "https://typia.io",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@samchon/openapi": "^5.0.
|
|
44
|
+
"@samchon/openapi": "^5.0.1",
|
|
45
45
|
"@standard-schema/spec": "^1.0.0",
|
|
46
46
|
"commander": "^10.0.0",
|
|
47
47
|
"comment-json": "^4.2.3",
|
package/src/json.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IJsonSchemaApplication } from "./schemas/json/IJsonSchemaApplication";
|
|
1
2
|
import { IJsonSchemaCollection } from "./schemas/json/IJsonSchemaCollection";
|
|
2
3
|
import { IJsonSchemaUnit } from "./schemas/json/IJsonSchemaUnit";
|
|
3
4
|
|
|
@@ -16,6 +17,54 @@ import { TypeGuardError } from "./TypeGuardError";
|
|
|
16
17
|
==============================================================
|
|
17
18
|
METADATA
|
|
18
19
|
----------------------------------------------------------- */
|
|
20
|
+
/**
|
|
21
|
+
* > You must configure the generic argument `Type`.
|
|
22
|
+
*
|
|
23
|
+
* JSON schema generator.
|
|
24
|
+
*
|
|
25
|
+
* Creates a JSON schema unit which contains a main JSON schema and its
|
|
26
|
+
* components. Note that, all of the named types are stored in the
|
|
27
|
+
* {@link IJsonSchemaUnit.components} property for the `$ref` referencing.
|
|
28
|
+
*
|
|
29
|
+
* Also, you can specify the OpenAPI version by configuring the second generic
|
|
30
|
+
* argument `Version`. For reference, the default version is `"3.1"`, and key
|
|
31
|
+
* different of `"3.0"` and `"3.1"` is whether supporting the tuple type or
|
|
32
|
+
* not.
|
|
33
|
+
*
|
|
34
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
35
|
+
* @template Type Target type
|
|
36
|
+
* @template Version Version of OpenAPI specification. Default is 3.1
|
|
37
|
+
* @returns JSON schema unit
|
|
38
|
+
*/
|
|
39
|
+
export function schema(): never;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* JSON schema generator.
|
|
43
|
+
*
|
|
44
|
+
* Creates a JSON schema unit which contains a main JSON schema and its
|
|
45
|
+
* components. Note that, all of the named types are stored in the
|
|
46
|
+
* {@link IJsonSchemaUnit.components} property for the `$ref` referencing.
|
|
47
|
+
*
|
|
48
|
+
* Also, you can specify the OpenAPI version by configuring the second generic
|
|
49
|
+
* argument `Version`. For reference, the default version is `"3.1"`, and key
|
|
50
|
+
* different of `"3.0"` and `"3.1"` is whether supporting the tuple type or
|
|
51
|
+
* not.
|
|
52
|
+
*
|
|
53
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
54
|
+
* @template Type Target type
|
|
55
|
+
* @template Version Version of OpenAPI specification. Default is 3.1
|
|
56
|
+
* @returns JSON schema unit
|
|
57
|
+
*/
|
|
58
|
+
export function schema<
|
|
59
|
+
Type extends unknown,
|
|
60
|
+
Version extends "3.0" | "3.1" = "3.1",
|
|
61
|
+
>(): IJsonSchemaUnit<Version, Type>;
|
|
62
|
+
|
|
63
|
+
/** @internal */
|
|
64
|
+
export function schema(): never {
|
|
65
|
+
NoTransformConfigurationError("json.schema");
|
|
66
|
+
}
|
|
67
|
+
|
|
19
68
|
/**
|
|
20
69
|
* > You must configure the generic argument `Types`.
|
|
21
70
|
*
|
|
@@ -65,51 +114,99 @@ export function schemas(): never {
|
|
|
65
114
|
}
|
|
66
115
|
|
|
67
116
|
/**
|
|
68
|
-
* > You must configure the generic argument `
|
|
117
|
+
* > You must configure the generic argument `Class`.
|
|
69
118
|
*
|
|
70
|
-
* JSON schema
|
|
119
|
+
* TypeScript class to JSON function schema application.
|
|
71
120
|
*
|
|
72
|
-
* Creates a JSON schema
|
|
73
|
-
*
|
|
74
|
-
*
|
|
121
|
+
* Creates a JSON function schema application from a TypeScript class or
|
|
122
|
+
* interface type containing the target functions. This is an intermediate-level
|
|
123
|
+
* function designed for professional developers who want to build custom LLM
|
|
124
|
+
* function calling schemas or need to transform class methods into structured
|
|
125
|
+
* JSON schema representations.
|
|
126
|
+
*
|
|
127
|
+
* Unlike {@link schema} which creates a schema for a single type, this function
|
|
128
|
+
* analyzes an entire class/interface and generates JSON schemas for all its
|
|
129
|
+
* methods, their parameters, and return types. The returned
|
|
130
|
+
* {@link IJsonSchemaApplication} contains:
|
|
131
|
+
*
|
|
132
|
+
* - {@link IJsonSchemaApplication.functions}: Array of function metadata with
|
|
133
|
+
* parameter and return type schemas
|
|
134
|
+
* - {@link IJsonSchemaApplication.components}: Shared schema components for `$ref`
|
|
135
|
+
* referencing
|
|
136
|
+
*
|
|
137
|
+
* This function serves as the underlying implementation for
|
|
138
|
+
* {@link llm.application}, and can be used when you need to:
|
|
139
|
+
*
|
|
140
|
+
* - Create your own custom LLM function calling schema format
|
|
141
|
+
* - Transform class methods into structured JSON schema format
|
|
142
|
+
* - Build API documentation or code generation tools
|
|
143
|
+
* - Develop alternative LLM integrations beyond the built-in providers
|
|
144
|
+
*
|
|
145
|
+
* For direct LLM function calling implementations, consider using
|
|
146
|
+
* {@link llm.application} instead, which provides provider-specific schemas for
|
|
147
|
+
* ChatGPT, Claude, Gemini, and other LLM providers.
|
|
75
148
|
*
|
|
76
149
|
* Also, you can specify the OpenAPI version by configuring the second generic
|
|
77
|
-
* argument `Version`. For reference, the default version is `"3.1"`, and
|
|
78
|
-
*
|
|
79
|
-
* not.
|
|
150
|
+
* argument `Version`. For reference, the default version is `"3.1"`, and the
|
|
151
|
+
* key difference between `"3.0"` and `"3.1"` is whether supporting the tuple
|
|
152
|
+
* type or not.
|
|
80
153
|
*
|
|
81
154
|
* @author Jeongho Nam - https://github.com/samchon
|
|
82
|
-
* @template
|
|
155
|
+
* @template Class Target class or interface type containing the functions
|
|
83
156
|
* @template Version Version of OpenAPI specification. Default is 3.1
|
|
84
|
-
* @returns JSON schema
|
|
157
|
+
* @returns JSON function schema application
|
|
85
158
|
*/
|
|
86
|
-
export function
|
|
159
|
+
export function application(): never;
|
|
87
160
|
|
|
88
161
|
/**
|
|
89
|
-
* JSON schema
|
|
162
|
+
* TypeScript class to JSON function schema application.
|
|
90
163
|
*
|
|
91
|
-
* Creates a JSON schema
|
|
92
|
-
*
|
|
93
|
-
*
|
|
164
|
+
* Creates a JSON function schema application from a TypeScript class or
|
|
165
|
+
* interface type containing the target functions. This is an intermediate-level
|
|
166
|
+
* function designed for professional developers who want to build custom LLM
|
|
167
|
+
* function calling schemas or need to transform class methods into structured
|
|
168
|
+
* JSON schema representations.
|
|
169
|
+
*
|
|
170
|
+
* Unlike {@link schema} which creates a schema for a single type, this function
|
|
171
|
+
* analyzes an entire class/interface and generates JSON schemas for all its
|
|
172
|
+
* methods, their parameters, and return types. The returned
|
|
173
|
+
* {@link IJsonSchemaApplication} contains:
|
|
174
|
+
*
|
|
175
|
+
* - {@link IJsonSchemaApplication.functions}: Array of function metadata with
|
|
176
|
+
* parameter and return type schemas
|
|
177
|
+
* - {@link IJsonSchemaApplication.components}: Shared schema components for `$ref`
|
|
178
|
+
* referencing
|
|
179
|
+
*
|
|
180
|
+
* This function serves as the underlying implementation for
|
|
181
|
+
* {@link llm.application}, and can be used when you need to:
|
|
182
|
+
*
|
|
183
|
+
* - Create your own custom LLM function calling schema format
|
|
184
|
+
* - Transform class methods into structured JSON schema format
|
|
185
|
+
* - Build API documentation or code generation tools
|
|
186
|
+
* - Develop alternative LLM integrations beyond the built-in providers
|
|
187
|
+
*
|
|
188
|
+
* For direct LLM function calling implementations, consider using
|
|
189
|
+
* {@link llm.application} instead, which provides provider-specific schemas for
|
|
190
|
+
* ChatGPT, Claude, Gemini, and other LLM providers.
|
|
94
191
|
*
|
|
95
192
|
* Also, you can specify the OpenAPI version by configuring the second generic
|
|
96
|
-
* argument `Version`. For reference, the default version is `"3.1"`, and
|
|
97
|
-
*
|
|
98
|
-
* not.
|
|
193
|
+
* argument `Version`. For reference, the default version is `"3.1"`, and the
|
|
194
|
+
* key difference between `"3.0"` and `"3.1"` is whether supporting the tuple
|
|
195
|
+
* type or not.
|
|
99
196
|
*
|
|
100
197
|
* @author Jeongho Nam - https://github.com/samchon
|
|
101
|
-
* @template
|
|
198
|
+
* @template Class Target class or interface type containing the functions
|
|
102
199
|
* @template Version Version of OpenAPI specification. Default is 3.1
|
|
103
|
-
* @returns JSON schema
|
|
200
|
+
* @returns JSON function schema application
|
|
104
201
|
*/
|
|
105
|
-
export function
|
|
106
|
-
|
|
202
|
+
export function application<
|
|
203
|
+
Class extends object,
|
|
107
204
|
Version extends "3.0" | "3.1" = "3.1",
|
|
108
|
-
>():
|
|
205
|
+
>(): IJsonSchemaApplication<Version, Class>;
|
|
109
206
|
|
|
110
207
|
/** @internal */
|
|
111
|
-
export function
|
|
112
|
-
NoTransformConfigurationError("json.
|
|
208
|
+
export function application(): never {
|
|
209
|
+
NoTransformConfigurationError("json.application");
|
|
113
210
|
}
|
|
114
211
|
|
|
115
212
|
/* -----------------------------------------------------------
|
package/src/module.ts
CHANGED
|
@@ -19,7 +19,7 @@ export * as reflect from "./reflect";
|
|
|
19
19
|
export * as tags from "./tags";
|
|
20
20
|
|
|
21
21
|
export * from "./schemas/metadata/IJsDocTagInfo";
|
|
22
|
-
export * from "./schemas/json/
|
|
22
|
+
export * from "./schemas/json/IJsonSchemaApplication";
|
|
23
23
|
export * from "./schemas/json/IJsonSchemaCollection";
|
|
24
24
|
export * from "./schemas/json/IJsonSchemaUnit";
|
|
25
25
|
export * from "./AssertionGuard";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MetadataFactory } from "../../factories/MetadataFactory";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { IJsonSchemaApplication } from "../../schemas/json/IJsonSchemaApplication";
|
|
4
4
|
import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
|
|
5
5
|
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
6
6
|
import { MetadataFunction } from "../../schemas/metadata/MetadataFunction";
|
|
@@ -62,21 +62,22 @@ export namespace JsonApplicationProgrammer {
|
|
|
62
62
|
version: Version;
|
|
63
63
|
metadata: Metadata;
|
|
64
64
|
filter?: (prop: MetadataProperty) => boolean;
|
|
65
|
-
}):
|
|
65
|
+
}): IJsonSchemaApplication<Version> => {
|
|
66
66
|
const object: MetadataObjectType = props.metadata.objects[0]!.type;
|
|
67
67
|
const definitions: Metadata[] = [];
|
|
68
|
-
const setters: Array<
|
|
69
|
-
|
|
68
|
+
const setters: Array<
|
|
69
|
+
(schema: IJsonSchemaApplication.Schema<Version>) => void
|
|
70
|
+
> = [];
|
|
70
71
|
const collect = (
|
|
71
72
|
metadata: Metadata,
|
|
72
|
-
setter: (schema:
|
|
73
|
+
setter: (schema: IJsonSchemaApplication.Schema<Version>) => void,
|
|
73
74
|
): void => {
|
|
74
75
|
definitions.push(metadata);
|
|
75
76
|
setters.push(setter);
|
|
76
77
|
};
|
|
77
78
|
|
|
78
|
-
const functions:
|
|
79
|
-
|
|
79
|
+
const functions: IJsonSchemaApplication.IFunction<
|
|
80
|
+
IJsonSchemaApplication.Schema<Version>
|
|
80
81
|
>[] = object.properties
|
|
81
82
|
.filter(
|
|
82
83
|
(p) =>
|
|
@@ -108,7 +109,7 @@ export namespace JsonApplicationProgrammer {
|
|
|
108
109
|
metadatas: definitions,
|
|
109
110
|
});
|
|
110
111
|
schemas.forEach((s, i) =>
|
|
111
|
-
setters[i]?.(s as
|
|
112
|
+
setters[i]?.(s as IJsonSchemaApplication.Schema<Version>),
|
|
112
113
|
);
|
|
113
114
|
return {
|
|
114
115
|
version: props.version,
|
|
@@ -152,9 +153,11 @@ export namespace JsonApplicationProgrammer {
|
|
|
152
153
|
jsDocTags: IJsDocTagInfo[];
|
|
153
154
|
collect: (
|
|
154
155
|
metadata: Metadata,
|
|
155
|
-
setter: (schema:
|
|
156
|
+
setter: (schema: IJsonSchemaApplication.Schema<Version>) => void,
|
|
156
157
|
) => void;
|
|
157
|
-
}):
|
|
158
|
+
}): IJsonSchemaApplication.IFunction<
|
|
159
|
+
IJsonSchemaApplication.Schema<Version>
|
|
160
|
+
> => {
|
|
158
161
|
const deprecated: boolean = props.jsDocTags.some(
|
|
159
162
|
(tag) => tag.name === "deprecated",
|
|
160
163
|
);
|
|
@@ -172,8 +175,8 @@ export namespace JsonApplicationProgrammer {
|
|
|
172
175
|
name: props.name,
|
|
173
176
|
async: props.function.async,
|
|
174
177
|
parameters: props.function.parameters.map((param) => {
|
|
175
|
-
const appParam:
|
|
176
|
-
|
|
178
|
+
const appParam: IJsonSchemaApplication.IParameter<
|
|
179
|
+
IJsonSchemaApplication.Schema<Version>
|
|
177
180
|
> = {
|
|
178
181
|
name: param.name,
|
|
179
182
|
...writeDescription({
|
|
@@ -201,8 +204,8 @@ export namespace JsonApplicationProgrammer {
|
|
|
201
204
|
}),
|
|
202
205
|
output: props.function.output.size()
|
|
203
206
|
? (() => {
|
|
204
|
-
const appOutput:
|
|
205
|
-
|
|
207
|
+
const appOutput: IJsonSchemaApplication.IOutput<
|
|
208
|
+
IJsonSchemaApplication.Schema<Version>
|
|
206
209
|
> = {
|
|
207
210
|
schema: null!,
|
|
208
211
|
required: props.function.output.isRequired(),
|
|
@@ -14,7 +14,7 @@ import ts from "typescript";
|
|
|
14
14
|
import { MetadataFactory } from "../../factories/MetadataFactory";
|
|
15
15
|
import { TypeFactory } from "../../factories/TypeFactory";
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { IJsonSchemaApplication } from "../../schemas/json/IJsonSchemaApplication";
|
|
18
18
|
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
19
19
|
import { MetadataFunction } from "../../schemas/metadata/MetadataFunction";
|
|
20
20
|
import { MetadataObjectType } from "../../schemas/metadata/MetadataObjectType";
|
|
@@ -191,7 +191,7 @@ export namespace LlmApplicationProgrammer {
|
|
|
191
191
|
);
|
|
192
192
|
|
|
193
193
|
const errorMessages: string[] = [];
|
|
194
|
-
const application:
|
|
194
|
+
const application: IJsonSchemaApplication<"3.1"> =
|
|
195
195
|
JsonApplicationProgrammer.write({
|
|
196
196
|
version: "3.1",
|
|
197
197
|
metadata,
|
|
@@ -233,7 +233,7 @@ export namespace LlmApplicationProgrammer {
|
|
|
233
233
|
context: ITypiaContext;
|
|
234
234
|
modulo: ts.LeftHandSideExpression;
|
|
235
235
|
components: OpenApi.IComponents;
|
|
236
|
-
function:
|
|
236
|
+
function: IJsonSchemaApplication.IFunction<OpenApi.IJsonSchema>;
|
|
237
237
|
parameter: MetadataParameter | null;
|
|
238
238
|
errors: string[];
|
|
239
239
|
className?: string;
|
|
@@ -309,7 +309,7 @@ export namespace LlmApplicationProgrammer {
|
|
|
309
309
|
const writeParameters = <Model extends ILlmSchema.Model>(props: {
|
|
310
310
|
model: Model;
|
|
311
311
|
components: OpenApi.IComponents;
|
|
312
|
-
function:
|
|
312
|
+
function: IJsonSchemaApplication.IFunction<OpenApi.IJsonSchema>;
|
|
313
313
|
errors: string[];
|
|
314
314
|
accessor: string;
|
|
315
315
|
}): ILlmSchema.ModelParameters[Model] | null => {
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { OpenApi, OpenApiV3 } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
export interface
|
|
3
|
+
export interface IJsonSchemaApplication<
|
|
4
4
|
Version extends "3.0" | "3.1" = "3.1",
|
|
5
5
|
App extends any = object,
|
|
6
6
|
> {
|
|
7
7
|
version: Version;
|
|
8
|
-
components:
|
|
9
|
-
|
|
8
|
+
components: IJsonSchemaApplication.IComponents<
|
|
9
|
+
IJsonSchemaApplication.Schema<Version>
|
|
10
10
|
>;
|
|
11
|
-
functions:
|
|
11
|
+
functions: IJsonSchemaApplication.IFunction<
|
|
12
|
+
IJsonSchemaApplication.Schema<Version>
|
|
13
|
+
>[];
|
|
12
14
|
__application?: App | undefined;
|
|
13
15
|
}
|
|
14
|
-
export namespace
|
|
16
|
+
export namespace IJsonSchemaApplication {
|
|
15
17
|
export type Schema<Version extends "3.0" | "3.1"> = Version extends "3.1"
|
|
16
18
|
? OpenApi.IJsonSchema
|
|
17
19
|
: OpenApiV3.IJsonSchema;
|
|
@@ -50,6 +50,7 @@ import { HttpQueryTransformer } from "./features/http/HttpQueryTransformer";
|
|
|
50
50
|
import { HttpValidateFormDataTransformer } from "./features/http/HttpValidateFormDataTransformer";
|
|
51
51
|
import { HttpValidateHeadersTransformer } from "./features/http/HttpValidateHeadersTransformer";
|
|
52
52
|
import { HttpValidateQueryTransformer } from "./features/http/HttpValidateQueryTransformer";
|
|
53
|
+
import { JsonApplicationTransformer } from "./features/json/JsonApplicationTransformer";
|
|
53
54
|
// import { JsonApplicationTransformer } from "./features/json/JsonApplicationTransformer";
|
|
54
55
|
import { JsonAssertParseTransformer } from "./features/json/JsonAssertParseTransformer";
|
|
55
56
|
import { JsonAssertStringifyTransformer } from "./features/json/JsonAssertStringifyTransformer";
|
|
@@ -410,8 +411,9 @@ const FUNCTORS: Record<string, Record<string, () => Task>> = {
|
|
|
410
411
|
},
|
|
411
412
|
json: {
|
|
412
413
|
// METADATA
|
|
413
|
-
schemas: () => JsonSchemasTransformer.transform,
|
|
414
414
|
schema: () => JsonSchemaTransformer.transform,
|
|
415
|
+
schemas: () => JsonSchemasTransformer.transform,
|
|
416
|
+
application: () => JsonApplicationTransformer.transform,
|
|
415
417
|
|
|
416
418
|
// PARSER
|
|
417
419
|
isParse: () => JsonIsParseTransformer.transform,
|
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
|
|
1
|
+
import ts from "typescript";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { LiteralFactory } from "../../../factories/LiteralFactory";
|
|
4
|
+
import { MetadataCollection } from "../../../factories/MetadataCollection";
|
|
5
|
+
import { MetadataFactory } from "../../../factories/MetadataFactory";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import { IJsonSchemaApplication } from "../../../schemas/json/IJsonSchemaApplication";
|
|
8
|
+
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
import { JsonApplicationProgrammer } from "../../../programmers/json/JsonApplicationProgrammer";
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
import { ValidationPipe } from "../../../typings/ValidationPipe";
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
import { ITransformProps } from "../../ITransformProps";
|
|
15
|
+
import { TransformerError } from "../../TransformerError";
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
export namespace JsonApplicationTransformer {
|
|
18
|
+
export const transform = (props: ITransformProps): ts.Expression => {
|
|
19
|
+
// GET GENERIC ARGUMENT
|
|
20
|
+
if (!props.expression.typeArguments?.length)
|
|
21
|
+
throw new TransformerError({
|
|
22
|
+
code: "typia.json.application",
|
|
23
|
+
message: "no generic argument.",
|
|
24
|
+
});
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
27
|
+
if (ts.isTypeNode(top) === false) return props.expression;
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
const version: "3.0" | "3.1" = get_parameter<"3.0" | "3.1">({
|
|
30
|
+
checker: props.context.checker,
|
|
31
|
+
name: "Version",
|
|
32
|
+
is: (str) => str === "3.0" || str === "3.1",
|
|
33
|
+
cast: (str) => str as "3.0" | "3.1",
|
|
34
|
+
default: () => "3.1",
|
|
35
|
+
})(props.expression.typeArguments[1]);
|
|
36
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
|
-
|
|
37
|
+
// GET TYPE
|
|
38
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
39
|
+
const collection: MetadataCollection = new MetadataCollection({
|
|
40
|
+
replace: MetadataCollection.replace,
|
|
41
|
+
});
|
|
42
|
+
const result: ValidationPipe<Metadata, MetadataFactory.IError> =
|
|
43
|
+
MetadataFactory.analyze({
|
|
44
|
+
checker: props.context.checker,
|
|
45
|
+
transformer: props.context.transformer,
|
|
46
|
+
options: {
|
|
47
|
+
escape: true,
|
|
48
|
+
constant: true,
|
|
49
|
+
absorb: false,
|
|
50
|
+
functional: true,
|
|
51
|
+
validate: JsonApplicationProgrammer.validate,
|
|
52
|
+
},
|
|
53
|
+
collection,
|
|
54
|
+
type,
|
|
55
|
+
});
|
|
56
|
+
if (result.success === false)
|
|
57
|
+
throw TransformerError.from({
|
|
58
|
+
code: "typia.json.application",
|
|
59
|
+
errors: result.errors,
|
|
60
|
+
});
|
|
61
61
|
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
// GENERATE LLM APPLICATION
|
|
63
|
+
const app: IJsonSchemaApplication<"3.0" | "3.1"> =
|
|
64
|
+
JsonApplicationProgrammer.write({
|
|
65
|
+
version,
|
|
66
|
+
metadata: result.data,
|
|
67
|
+
});
|
|
68
|
+
const literal: ts.Expression = LiteralFactory.write(app);
|
|
69
|
+
return literal;
|
|
70
|
+
};
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
const get_parameter =
|
|
73
|
+
<Value>(props: {
|
|
74
|
+
checker: ts.TypeChecker;
|
|
75
|
+
name: string;
|
|
76
|
+
is: (value: string) => boolean;
|
|
77
|
+
cast: (value: string) => Value;
|
|
78
|
+
default: () => Value;
|
|
79
|
+
}) =>
|
|
80
|
+
(node: ts.TypeNode | undefined): Value => {
|
|
81
|
+
if (!node) return props.default();
|
|
82
82
|
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
83
|
+
// CHECK LITERAL TYPE
|
|
84
|
+
const type: ts.Type = props.checker.getTypeFromTypeNode(node);
|
|
85
|
+
if (
|
|
86
|
+
!type.isLiteral() &&
|
|
87
|
+
(type.getFlags() & ts.TypeFlags.BooleanLiteral) === 0
|
|
88
|
+
)
|
|
89
|
+
throw new TransformerError({
|
|
90
|
+
code: "typia.json.application",
|
|
91
|
+
message: `generic argument "${props.name}" must be constant.`,
|
|
92
|
+
});
|
|
93
93
|
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
94
|
+
// GET VALUE AND VALIDATE IT
|
|
95
|
+
const value = type.isLiteral()
|
|
96
|
+
? type.value
|
|
97
|
+
: props.checker.typeToString(type);
|
|
98
|
+
if (typeof value !== "string" || props.is(value) === false)
|
|
99
|
+
throw new TransformerError({
|
|
100
|
+
code: "typia.json.application",
|
|
101
|
+
message: `invalid value on generic argument "${props.name}".`,
|
|
102
|
+
});
|
|
103
|
+
return props.cast(value);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { IJsonSchemaCollection } from "./IJsonSchemaCollection";
|
|
2
|
-
/**
|
|
3
|
-
* Collection of JSON schemas.
|
|
4
|
-
*
|
|
5
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
6
|
-
* @deprecated Use {@link IJsonSchemaCollection} instead please. This interface
|
|
7
|
-
* type would be changed to {@link ILlmApplication} like structure in the
|
|
8
|
-
* future version (maybe next v8 major update).
|
|
9
|
-
* @template Version Version of the OpenAPI specification.
|
|
10
|
-
* @template Types Original TypeScript types used in the JSON schemas.
|
|
11
|
-
*/
|
|
12
|
-
export type IJsonApplication = IJsonSchemaCollection;
|
|
13
|
-
export declare namespace IJsonApplication {
|
|
14
|
-
type IV3_0 = IJsonSchemaCollection.IV3_0;
|
|
15
|
-
type IV3_1 = IJsonSchemaCollection.IV3_1;
|
|
16
|
-
}
|