@nestia/sdk 3.1.0-dev.20240426 → 3.1.0-dev.20240430
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/lib/analyses/TypedWebSocketOperationAnalyzer.js +1 -1
- package/lib/analyses/TypedWebSocketOperationAnalyzer.js.map +1 -1
- package/lib/executable/sdk.js +11 -11
- package/lib/generates/SwaggerGenerator.js +1 -1
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js +18 -20
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +30 -1
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
- package/lib/structures/ITypedWebSocketRoute.d.ts +1 -0
- package/package.json +4 -4
- package/src/NestiaSdkApplication.ts +257 -257
- package/src/analyses/AccessorAnalyzer.ts +67 -67
- package/src/analyses/ConfigAnalyzer.ts +147 -147
- package/src/analyses/GenericAnalyzer.ts +51 -51
- package/src/analyses/PathAnalyzer.ts +69 -69
- package/src/analyses/SecurityAnalyzer.ts +25 -25
- package/src/analyses/TypedWebSocketOperationAnalyzer.ts +1 -0
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/executable/internal/NestiaConfigLoader.ts +67 -67
- package/src/executable/internal/NestiaSdkCommand.ts +60 -60
- package/src/executable/sdk.ts +73 -73
- package/src/generates/CloneGenerator.ts +64 -64
- package/src/generates/E2eGenerator.ts +64 -64
- package/src/generates/SdkGenerator.ts +91 -91
- package/src/generates/SwaggerGenerator.ts +1 -1
- package/src/generates/internal/E2eFileProgrammer.ts +178 -178
- package/src/generates/internal/FilePrinter.ts +53 -53
- package/src/generates/internal/SdkAliasCollection.ts +157 -157
- package/src/generates/internal/SdkDistributionComposer.ts +100 -100
- package/src/generates/internal/SdkFileProgrammer.ts +119 -119
- package/src/generates/internal/SdkHttpCloneProgrammer.ts +154 -154
- package/src/generates/internal/SdkHttpFunctionProgrammer.ts +298 -299
- package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +505 -505
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +82 -82
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +363 -363
- package/src/generates/internal/SdkImportWizard.ts +55 -55
- package/src/generates/internal/SdkRouteDirectory.ts +18 -18
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +42 -1
- package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
- package/src/index.ts +4 -4
- package/src/module.ts +2 -2
- package/src/structures/IErrorReport.ts +6 -6
- package/src/structures/INestiaProject.ts +13 -13
- package/src/structures/INormalizedInput.ts +20 -20
- package/src/structures/IReflectController.ts +17 -17
- package/src/structures/ITypeTuple.ts +6 -6
- package/src/structures/ITypedHttpRoute.ts +55 -55
- package/src/structures/ITypedWebSocketRoute.ts +1 -0
- package/src/structures/MethodType.ts +5 -5
- package/src/structures/ParamCategory.ts +1 -1
- package/src/utils/ArrayUtil.ts +26 -26
- package/src/utils/FileRetriever.ts +22 -22
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PathUtil.ts +10 -10
- package/src/utils/SourceFinder.ts +66 -66
- package/src/utils/StringUtil.ts +6 -6
- package/src/utils/StripEnums.ts +5 -5
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { ImportDictionary } from "./ImportDictionary";
|
|
2
|
-
|
|
3
|
-
export namespace SdkImportWizard {
|
|
4
|
-
export const Fetcher = (encrypted: boolean) =>
|
|
5
|
-
encrypted ? EncryptedFetcher : PlainFetcher;
|
|
6
|
-
|
|
7
|
-
export const HttpError = (importer: ImportDictionary) =>
|
|
8
|
-
importer.external({
|
|
9
|
-
type: true,
|
|
10
|
-
library: "@nestia/fetcher",
|
|
11
|
-
instance: "HttpError",
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export const IConnection = (importer: ImportDictionary) =>
|
|
15
|
-
importer.external({
|
|
16
|
-
type: true,
|
|
17
|
-
library: "@nestia/fetcher",
|
|
18
|
-
instance: "IConnection",
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export const Primitive = (importer: ImportDictionary) =>
|
|
22
|
-
importer.external({
|
|
23
|
-
type: true,
|
|
24
|
-
library: "@nestia/fetcher",
|
|
25
|
-
instance: "Primitive",
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
export const Resolved = (importer: ImportDictionary) =>
|
|
29
|
-
importer.external({
|
|
30
|
-
type: true,
|
|
31
|
-
library: "@nestia/fetcher",
|
|
32
|
-
instance: "Resolved",
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
export const typia = (importer: ImportDictionary) =>
|
|
36
|
-
importer.external({
|
|
37
|
-
type: false,
|
|
38
|
-
library: "typia",
|
|
39
|
-
instance: null,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const PlainFetcher = (importer: ImportDictionary) =>
|
|
44
|
-
importer.external({
|
|
45
|
-
type: false,
|
|
46
|
-
library: "@nestia/fetcher/lib/PlainFetcher",
|
|
47
|
-
instance: "PlainFetcher",
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const EncryptedFetcher = (importer: ImportDictionary) =>
|
|
51
|
-
importer.external({
|
|
52
|
-
type: false,
|
|
53
|
-
library: "@nestia/fetcher/lib/EncryptedFetcher",
|
|
54
|
-
instance: "EncryptedFetcher",
|
|
55
|
-
});
|
|
1
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
2
|
+
|
|
3
|
+
export namespace SdkImportWizard {
|
|
4
|
+
export const Fetcher = (encrypted: boolean) =>
|
|
5
|
+
encrypted ? EncryptedFetcher : PlainFetcher;
|
|
6
|
+
|
|
7
|
+
export const HttpError = (importer: ImportDictionary) =>
|
|
8
|
+
importer.external({
|
|
9
|
+
type: true,
|
|
10
|
+
library: "@nestia/fetcher",
|
|
11
|
+
instance: "HttpError",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const IConnection = (importer: ImportDictionary) =>
|
|
15
|
+
importer.external({
|
|
16
|
+
type: true,
|
|
17
|
+
library: "@nestia/fetcher",
|
|
18
|
+
instance: "IConnection",
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const Primitive = (importer: ImportDictionary) =>
|
|
22
|
+
importer.external({
|
|
23
|
+
type: true,
|
|
24
|
+
library: "@nestia/fetcher",
|
|
25
|
+
instance: "Primitive",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const Resolved = (importer: ImportDictionary) =>
|
|
29
|
+
importer.external({
|
|
30
|
+
type: true,
|
|
31
|
+
library: "@nestia/fetcher",
|
|
32
|
+
instance: "Resolved",
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export const typia = (importer: ImportDictionary) =>
|
|
36
|
+
importer.external({
|
|
37
|
+
type: false,
|
|
38
|
+
library: "typia",
|
|
39
|
+
instance: null,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const PlainFetcher = (importer: ImportDictionary) =>
|
|
44
|
+
importer.external({
|
|
45
|
+
type: false,
|
|
46
|
+
library: "@nestia/fetcher/lib/PlainFetcher",
|
|
47
|
+
instance: "PlainFetcher",
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const EncryptedFetcher = (importer: ImportDictionary) =>
|
|
51
|
+
importer.external({
|
|
52
|
+
type: false,
|
|
53
|
+
library: "@nestia/fetcher/lib/EncryptedFetcher",
|
|
54
|
+
instance: "EncryptedFetcher",
|
|
55
|
+
});
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
2
|
-
import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
|
|
3
|
-
|
|
4
|
-
export class SdkRouteDirectory {
|
|
5
|
-
public readonly module: string;
|
|
6
|
-
public readonly children: Map<string, SdkRouteDirectory>;
|
|
7
|
-
public readonly routes: Array<ITypedHttpRoute | ITypedWebSocketRoute>;
|
|
8
|
-
|
|
9
|
-
public constructor(
|
|
10
|
-
readonly parent: SdkRouteDirectory | null,
|
|
11
|
-
readonly name: string,
|
|
12
|
-
) {
|
|
13
|
-
this.children = new Map();
|
|
14
|
-
this.routes = [];
|
|
15
|
-
this.module =
|
|
16
|
-
this.parent !== null ? `${this.parent.module}.${name}` : `api.${name}`;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
2
|
+
import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
|
|
3
|
+
|
|
4
|
+
export class SdkRouteDirectory {
|
|
5
|
+
public readonly module: string;
|
|
6
|
+
public readonly children: Map<string, SdkRouteDirectory>;
|
|
7
|
+
public readonly routes: Array<ITypedHttpRoute | ITypedWebSocketRoute>;
|
|
8
|
+
|
|
9
|
+
public constructor(
|
|
10
|
+
readonly parent: SdkRouteDirectory | null,
|
|
11
|
+
readonly name: string,
|
|
12
|
+
) {
|
|
13
|
+
this.children = new Map();
|
|
14
|
+
this.routes = [];
|
|
15
|
+
this.module =
|
|
16
|
+
this.parent !== null ? `${this.parent.module}.${name}` : `api.${name}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
+
import { IJsDocTagInfo } from "typia";
|
|
2
3
|
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
3
4
|
|
|
4
5
|
import { INestiaProject } from "../../structures/INestiaProject";
|
|
5
6
|
import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
|
|
7
|
+
import { FilePrinter } from "./FilePrinter";
|
|
6
8
|
import { ImportDictionary } from "./ImportDictionary";
|
|
7
9
|
import { SdkImportWizard } from "./SdkImportWizard";
|
|
8
10
|
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
@@ -13,10 +15,49 @@ export namespace SdkWebSocketRouteProgrammer {
|
|
|
13
15
|
(project: INestiaProject) =>
|
|
14
16
|
(importer: ImportDictionary) =>
|
|
15
17
|
(route: ITypedWebSocketRoute): ts.Statement[] => [
|
|
16
|
-
|
|
18
|
+
FilePrinter.description(
|
|
19
|
+
writeFunction(project)(importer)(route),
|
|
20
|
+
writeDescription(route),
|
|
21
|
+
),
|
|
17
22
|
SdkWebSocketNamespaceProgrammer.write(project)(importer)(route),
|
|
18
23
|
];
|
|
19
24
|
|
|
25
|
+
const writeDescription = (route: ITypedWebSocketRoute): string => {
|
|
26
|
+
// MAIN DESCRIPTION
|
|
27
|
+
const comments: string[] = route.description
|
|
28
|
+
? route.description.split("\n")
|
|
29
|
+
: [];
|
|
30
|
+
|
|
31
|
+
// COMMENT TAGS
|
|
32
|
+
const tags: IJsDocTagInfo[] = route.jsDocTags.filter(
|
|
33
|
+
(tag) =>
|
|
34
|
+
tag.name !== "return" &&
|
|
35
|
+
tag.name !== "returns" &&
|
|
36
|
+
(tag.name !== "param" ||
|
|
37
|
+
route.parameters
|
|
38
|
+
.filter((p) => p.category === "param" || p.category === "query")
|
|
39
|
+
.some((p) => p.name === tag.text?.[0]?.text)),
|
|
40
|
+
);
|
|
41
|
+
if (tags.length !== 0) {
|
|
42
|
+
const content: string[] = tags.map((t) =>
|
|
43
|
+
t.text?.length
|
|
44
|
+
? `@${t.name} ${t.text.map((e) => e.text).join("")}`
|
|
45
|
+
: `@${t.name}`,
|
|
46
|
+
);
|
|
47
|
+
comments.push("", ...new Set(content));
|
|
48
|
+
}
|
|
49
|
+
comments.push("@returns Pair of connector and driver");
|
|
50
|
+
|
|
51
|
+
// POSTFIX
|
|
52
|
+
if (!!comments.length) comments.push("");
|
|
53
|
+
comments.push(
|
|
54
|
+
`@controller ${route.controller.name}.${route.name}`,
|
|
55
|
+
`@path ${route.path}`,
|
|
56
|
+
`@nestia Generated by Nestia - https://github.com/samchon/nestia`,
|
|
57
|
+
);
|
|
58
|
+
return comments.join("\n");
|
|
59
|
+
};
|
|
60
|
+
|
|
20
61
|
const writeFunction =
|
|
21
62
|
(project: INestiaProject) =>
|
|
22
63
|
(importer: ImportDictionary) =>
|
|
@@ -1,198 +1,198 @@
|
|
|
1
|
-
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
2
|
-
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
3
|
-
import { MetadataArray } from "typia/lib/schemas/metadata/MetadataArray";
|
|
4
|
-
|
|
5
|
-
export namespace SwaggerSchemaValidator {
|
|
6
|
-
export const path = (meta: Metadata): string[] => {
|
|
7
|
-
const errors: string[] = [];
|
|
8
|
-
const insert = (msg: string) => errors.push(msg);
|
|
9
|
-
|
|
10
|
-
if (meta.any) insert("do not allow any type");
|
|
11
|
-
if (meta.isRequired() === false) insert("do not allow undefindable type");
|
|
12
|
-
|
|
13
|
-
const atomics = CoreMetadataUtil.atomics(meta);
|
|
14
|
-
const expected: number =
|
|
15
|
-
meta.atomics.length +
|
|
16
|
-
meta.templates.length +
|
|
17
|
-
meta.constants.map((c) => c.values.length).reduce((a, b) => a + b, 0);
|
|
18
|
-
if (meta.size() !== expected || atomics.size === 0)
|
|
19
|
-
insert("only atomic or constant types are allowed");
|
|
20
|
-
if (atomics.size > 1) insert("do not allow union type");
|
|
21
|
-
|
|
22
|
-
return errors;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const query = (
|
|
26
|
-
meta: Metadata,
|
|
27
|
-
explore: MetadataFactory.IExplore,
|
|
28
|
-
): string[] => {
|
|
29
|
-
const errors: string[] = [];
|
|
30
|
-
const insert = (msg: string) => errors.push(msg);
|
|
31
|
-
|
|
32
|
-
if (explore.top === true) {
|
|
33
|
-
// TOP MUST BE ONLY OBJECT
|
|
34
|
-
if (meta.objects.length !== 1 || meta.bucket() !== 1)
|
|
35
|
-
insert("only one object type is allowed.");
|
|
36
|
-
if (meta.nullable === true) insert("query parameters cannot be null.");
|
|
37
|
-
if (meta.isRequired() === false)
|
|
38
|
-
insert("query parameters cannot be undefined.");
|
|
39
|
-
} else if (
|
|
40
|
-
explore.nested !== null &&
|
|
41
|
-
explore.nested instanceof MetadataArray
|
|
42
|
-
) {
|
|
43
|
-
const atomics = CoreMetadataUtil.atomics(meta);
|
|
44
|
-
const expected: number =
|
|
45
|
-
meta.atomics.length +
|
|
46
|
-
meta.templates.length +
|
|
47
|
-
meta.constants.map((c) => c.values.length).reduce((a, b) => a + b, 0);
|
|
48
|
-
if (atomics.size > 1) insert("union type is not allowed in array.");
|
|
49
|
-
if (meta.nullable) insert("nullable type is not allowed in array.");
|
|
50
|
-
if (meta.isRequired() === false)
|
|
51
|
-
insert("optional type is not allowed in array.");
|
|
52
|
-
if (meta.size() !== expected)
|
|
53
|
-
insert("only atomic or constant types are allowed in array.");
|
|
54
|
-
} else if (explore.object && explore.property !== null) {
|
|
55
|
-
//----
|
|
56
|
-
// COMMON
|
|
57
|
-
//----
|
|
58
|
-
// PROPERTY MUST BE SOLE
|
|
59
|
-
if (typeof explore.property === "object")
|
|
60
|
-
insert("dynamic property is not allowed.");
|
|
61
|
-
// DO NOT ALLOW TUPLE TYPE
|
|
62
|
-
if (meta.tuples.length) insert("tuple type is not allowed.");
|
|
63
|
-
// DO NOT ALLOW UNION TYPE
|
|
64
|
-
if (CoreMetadataUtil.isUnion(meta)) insert("union type is not allowed.");
|
|
65
|
-
// DO NOT ALLOW NESTED OBJECT
|
|
66
|
-
if (
|
|
67
|
-
meta.objects.length ||
|
|
68
|
-
meta.sets.length ||
|
|
69
|
-
meta.maps.length ||
|
|
70
|
-
meta.natives.length
|
|
71
|
-
)
|
|
72
|
-
insert("nested object type is not allowed.");
|
|
73
|
-
|
|
74
|
-
//----
|
|
75
|
-
// ARRAY CASES
|
|
76
|
-
//----
|
|
77
|
-
const isArray: boolean = meta.arrays.length > 1 || meta.tuples.length > 1;
|
|
78
|
-
// ARRAY TYPE MUST BE REQUIRED
|
|
79
|
-
if (isArray && meta.isRequired() === false)
|
|
80
|
-
insert("optional type is not allowed when array.");
|
|
81
|
-
// SET-COOKIE MUST BE ARRAY
|
|
82
|
-
if (explore.property === "set-cookie" && !isArray)
|
|
83
|
-
insert("set-cookie property must be array.");
|
|
84
|
-
}
|
|
85
|
-
return errors;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export const headers = (
|
|
89
|
-
meta: Metadata,
|
|
90
|
-
explore: MetadataFactory.IExplore,
|
|
91
|
-
): string[] => {
|
|
92
|
-
const errors: string[] = [];
|
|
93
|
-
const insert = (msg: string) => errors.push(msg);
|
|
94
|
-
|
|
95
|
-
if (explore.top === true) {
|
|
96
|
-
// TOP MUST BE ONLY OBJECT
|
|
97
|
-
if (meta.objects.length !== 1 || meta.bucket() !== 1)
|
|
98
|
-
insert("only one object type is allowed.");
|
|
99
|
-
if (meta.nullable === true) insert("headers cannot be null.");
|
|
100
|
-
if (meta.isRequired() === false) insert("headers cannot be null.");
|
|
101
|
-
} else if (
|
|
102
|
-
explore.nested !== null &&
|
|
103
|
-
explore.nested instanceof MetadataArray
|
|
104
|
-
) {
|
|
105
|
-
const atomics = CoreMetadataUtil.atomics(meta);
|
|
106
|
-
const expected: number =
|
|
107
|
-
meta.atomics.length +
|
|
108
|
-
meta.templates.length +
|
|
109
|
-
meta.constants.map((c) => c.values.length).reduce((a, b) => a + b, 0);
|
|
110
|
-
if (atomics.size > 1) insert("union type is not allowed in array.");
|
|
111
|
-
if (meta.nullable) insert("nullable type is not allowed in array.");
|
|
112
|
-
if (meta.isRequired() === false) insert("optional type is not allowed.");
|
|
113
|
-
if (meta.size() !== expected)
|
|
114
|
-
insert("only atomic or constant types are allowed in array.");
|
|
115
|
-
} else if (explore.object && explore.property !== null) {
|
|
116
|
-
//----
|
|
117
|
-
// COMMON
|
|
118
|
-
//----
|
|
119
|
-
// PROPERTY MUST BE SOLE
|
|
120
|
-
if (typeof explore.property === "object")
|
|
121
|
-
insert("dynamic property is not allowed.");
|
|
122
|
-
// DO NOT ALLOW TUPLE TYPE
|
|
123
|
-
if (meta.tuples.length) insert("tuple type is not allowed.");
|
|
124
|
-
// DO NOT ALLOW UNION TYPE
|
|
125
|
-
if (CoreMetadataUtil.isUnion(meta)) insert("union type is not allowed.");
|
|
126
|
-
// DO NOT ALLOW NESTED OBJECT
|
|
127
|
-
if (
|
|
128
|
-
meta.objects.length ||
|
|
129
|
-
meta.sets.length ||
|
|
130
|
-
meta.maps.length ||
|
|
131
|
-
meta.natives.length
|
|
132
|
-
)
|
|
133
|
-
insert("nested object type is not allowed.");
|
|
134
|
-
// DO NOT ALLOW NULLABLE
|
|
135
|
-
if (meta.nullable) insert("nullable type is not allowed.");
|
|
136
|
-
|
|
137
|
-
//----
|
|
138
|
-
// ARRAY CASES
|
|
139
|
-
//----
|
|
140
|
-
const isArray: boolean = meta.arrays.length > 1;
|
|
141
|
-
// ARRAY TYPE MUST BE REQUIRED
|
|
142
|
-
if (isArray && meta.isRequired() === false)
|
|
143
|
-
insert("optional type is not allowed when array.");
|
|
144
|
-
// SET-COOKIE MUST BE ARRAY
|
|
145
|
-
if (explore.property === "set-cookie" && !isArray)
|
|
146
|
-
insert("set-cookie property must be array.");
|
|
147
|
-
// MUST BE SINGULAR CASE
|
|
148
|
-
if (
|
|
149
|
-
typeof explore.property === "string" &&
|
|
150
|
-
SINGULAR.has(explore.property) &&
|
|
151
|
-
isArray
|
|
152
|
-
)
|
|
153
|
-
insert("property cannot be array.");
|
|
154
|
-
}
|
|
155
|
-
return errors;
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
namespace CoreMetadataUtil {
|
|
160
|
-
export const atomics = (
|
|
161
|
-
meta: Metadata,
|
|
162
|
-
): Set<"boolean" | "bigint" | "number" | "string"> =>
|
|
163
|
-
new Set([
|
|
164
|
-
...meta.atomics.map((a) => a.type),
|
|
165
|
-
...meta.constants.map((c) => c.type),
|
|
166
|
-
...(meta.templates.length ? (["string"] as const) : []),
|
|
167
|
-
]);
|
|
168
|
-
|
|
169
|
-
export const isUnion = (meta: Metadata): boolean =>
|
|
170
|
-
atomics(meta).size +
|
|
171
|
-
meta.arrays.length +
|
|
172
|
-
meta.tuples.length +
|
|
173
|
-
meta.natives.length +
|
|
174
|
-
meta.maps.length +
|
|
175
|
-
meta.objects.length >
|
|
176
|
-
1;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const SINGULAR: Set<string> = new Set([
|
|
180
|
-
"age",
|
|
181
|
-
"authorization",
|
|
182
|
-
"content-length",
|
|
183
|
-
"content-type",
|
|
184
|
-
"etag",
|
|
185
|
-
"expires",
|
|
186
|
-
"from",
|
|
187
|
-
"host",
|
|
188
|
-
"if-modified-since",
|
|
189
|
-
"if-unmodified-since",
|
|
190
|
-
"last-modified",
|
|
191
|
-
"location",
|
|
192
|
-
"max-forwards",
|
|
193
|
-
"proxy-authorization",
|
|
194
|
-
"referer",
|
|
195
|
-
"retry-after",
|
|
196
|
-
"server",
|
|
197
|
-
"user-agent",
|
|
198
|
-
]);
|
|
1
|
+
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
2
|
+
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
3
|
+
import { MetadataArray } from "typia/lib/schemas/metadata/MetadataArray";
|
|
4
|
+
|
|
5
|
+
export namespace SwaggerSchemaValidator {
|
|
6
|
+
export const path = (meta: Metadata): string[] => {
|
|
7
|
+
const errors: string[] = [];
|
|
8
|
+
const insert = (msg: string) => errors.push(msg);
|
|
9
|
+
|
|
10
|
+
if (meta.any) insert("do not allow any type");
|
|
11
|
+
if (meta.isRequired() === false) insert("do not allow undefindable type");
|
|
12
|
+
|
|
13
|
+
const atomics = CoreMetadataUtil.atomics(meta);
|
|
14
|
+
const expected: number =
|
|
15
|
+
meta.atomics.length +
|
|
16
|
+
meta.templates.length +
|
|
17
|
+
meta.constants.map((c) => c.values.length).reduce((a, b) => a + b, 0);
|
|
18
|
+
if (meta.size() !== expected || atomics.size === 0)
|
|
19
|
+
insert("only atomic or constant types are allowed");
|
|
20
|
+
if (atomics.size > 1) insert("do not allow union type");
|
|
21
|
+
|
|
22
|
+
return errors;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const query = (
|
|
26
|
+
meta: Metadata,
|
|
27
|
+
explore: MetadataFactory.IExplore,
|
|
28
|
+
): string[] => {
|
|
29
|
+
const errors: string[] = [];
|
|
30
|
+
const insert = (msg: string) => errors.push(msg);
|
|
31
|
+
|
|
32
|
+
if (explore.top === true) {
|
|
33
|
+
// TOP MUST BE ONLY OBJECT
|
|
34
|
+
if (meta.objects.length !== 1 || meta.bucket() !== 1)
|
|
35
|
+
insert("only one object type is allowed.");
|
|
36
|
+
if (meta.nullable === true) insert("query parameters cannot be null.");
|
|
37
|
+
if (meta.isRequired() === false)
|
|
38
|
+
insert("query parameters cannot be undefined.");
|
|
39
|
+
} else if (
|
|
40
|
+
explore.nested !== null &&
|
|
41
|
+
explore.nested instanceof MetadataArray
|
|
42
|
+
) {
|
|
43
|
+
const atomics = CoreMetadataUtil.atomics(meta);
|
|
44
|
+
const expected: number =
|
|
45
|
+
meta.atomics.length +
|
|
46
|
+
meta.templates.length +
|
|
47
|
+
meta.constants.map((c) => c.values.length).reduce((a, b) => a + b, 0);
|
|
48
|
+
if (atomics.size > 1) insert("union type is not allowed in array.");
|
|
49
|
+
if (meta.nullable) insert("nullable type is not allowed in array.");
|
|
50
|
+
if (meta.isRequired() === false)
|
|
51
|
+
insert("optional type is not allowed in array.");
|
|
52
|
+
if (meta.size() !== expected)
|
|
53
|
+
insert("only atomic or constant types are allowed in array.");
|
|
54
|
+
} else if (explore.object && explore.property !== null) {
|
|
55
|
+
//----
|
|
56
|
+
// COMMON
|
|
57
|
+
//----
|
|
58
|
+
// PROPERTY MUST BE SOLE
|
|
59
|
+
if (typeof explore.property === "object")
|
|
60
|
+
insert("dynamic property is not allowed.");
|
|
61
|
+
// DO NOT ALLOW TUPLE TYPE
|
|
62
|
+
if (meta.tuples.length) insert("tuple type is not allowed.");
|
|
63
|
+
// DO NOT ALLOW UNION TYPE
|
|
64
|
+
if (CoreMetadataUtil.isUnion(meta)) insert("union type is not allowed.");
|
|
65
|
+
// DO NOT ALLOW NESTED OBJECT
|
|
66
|
+
if (
|
|
67
|
+
meta.objects.length ||
|
|
68
|
+
meta.sets.length ||
|
|
69
|
+
meta.maps.length ||
|
|
70
|
+
meta.natives.length
|
|
71
|
+
)
|
|
72
|
+
insert("nested object type is not allowed.");
|
|
73
|
+
|
|
74
|
+
//----
|
|
75
|
+
// ARRAY CASES
|
|
76
|
+
//----
|
|
77
|
+
const isArray: boolean = meta.arrays.length > 1 || meta.tuples.length > 1;
|
|
78
|
+
// ARRAY TYPE MUST BE REQUIRED
|
|
79
|
+
if (isArray && meta.isRequired() === false)
|
|
80
|
+
insert("optional type is not allowed when array.");
|
|
81
|
+
// SET-COOKIE MUST BE ARRAY
|
|
82
|
+
if (explore.property === "set-cookie" && !isArray)
|
|
83
|
+
insert("set-cookie property must be array.");
|
|
84
|
+
}
|
|
85
|
+
return errors;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const headers = (
|
|
89
|
+
meta: Metadata,
|
|
90
|
+
explore: MetadataFactory.IExplore,
|
|
91
|
+
): string[] => {
|
|
92
|
+
const errors: string[] = [];
|
|
93
|
+
const insert = (msg: string) => errors.push(msg);
|
|
94
|
+
|
|
95
|
+
if (explore.top === true) {
|
|
96
|
+
// TOP MUST BE ONLY OBJECT
|
|
97
|
+
if (meta.objects.length !== 1 || meta.bucket() !== 1)
|
|
98
|
+
insert("only one object type is allowed.");
|
|
99
|
+
if (meta.nullable === true) insert("headers cannot be null.");
|
|
100
|
+
if (meta.isRequired() === false) insert("headers cannot be null.");
|
|
101
|
+
} else if (
|
|
102
|
+
explore.nested !== null &&
|
|
103
|
+
explore.nested instanceof MetadataArray
|
|
104
|
+
) {
|
|
105
|
+
const atomics = CoreMetadataUtil.atomics(meta);
|
|
106
|
+
const expected: number =
|
|
107
|
+
meta.atomics.length +
|
|
108
|
+
meta.templates.length +
|
|
109
|
+
meta.constants.map((c) => c.values.length).reduce((a, b) => a + b, 0);
|
|
110
|
+
if (atomics.size > 1) insert("union type is not allowed in array.");
|
|
111
|
+
if (meta.nullable) insert("nullable type is not allowed in array.");
|
|
112
|
+
if (meta.isRequired() === false) insert("optional type is not allowed.");
|
|
113
|
+
if (meta.size() !== expected)
|
|
114
|
+
insert("only atomic or constant types are allowed in array.");
|
|
115
|
+
} else if (explore.object && explore.property !== null) {
|
|
116
|
+
//----
|
|
117
|
+
// COMMON
|
|
118
|
+
//----
|
|
119
|
+
// PROPERTY MUST BE SOLE
|
|
120
|
+
if (typeof explore.property === "object")
|
|
121
|
+
insert("dynamic property is not allowed.");
|
|
122
|
+
// DO NOT ALLOW TUPLE TYPE
|
|
123
|
+
if (meta.tuples.length) insert("tuple type is not allowed.");
|
|
124
|
+
// DO NOT ALLOW UNION TYPE
|
|
125
|
+
if (CoreMetadataUtil.isUnion(meta)) insert("union type is not allowed.");
|
|
126
|
+
// DO NOT ALLOW NESTED OBJECT
|
|
127
|
+
if (
|
|
128
|
+
meta.objects.length ||
|
|
129
|
+
meta.sets.length ||
|
|
130
|
+
meta.maps.length ||
|
|
131
|
+
meta.natives.length
|
|
132
|
+
)
|
|
133
|
+
insert("nested object type is not allowed.");
|
|
134
|
+
// DO NOT ALLOW NULLABLE
|
|
135
|
+
if (meta.nullable) insert("nullable type is not allowed.");
|
|
136
|
+
|
|
137
|
+
//----
|
|
138
|
+
// ARRAY CASES
|
|
139
|
+
//----
|
|
140
|
+
const isArray: boolean = meta.arrays.length > 1;
|
|
141
|
+
// ARRAY TYPE MUST BE REQUIRED
|
|
142
|
+
if (isArray && meta.isRequired() === false)
|
|
143
|
+
insert("optional type is not allowed when array.");
|
|
144
|
+
// SET-COOKIE MUST BE ARRAY
|
|
145
|
+
if (explore.property === "set-cookie" && !isArray)
|
|
146
|
+
insert("set-cookie property must be array.");
|
|
147
|
+
// MUST BE SINGULAR CASE
|
|
148
|
+
if (
|
|
149
|
+
typeof explore.property === "string" &&
|
|
150
|
+
SINGULAR.has(explore.property) &&
|
|
151
|
+
isArray
|
|
152
|
+
)
|
|
153
|
+
insert("property cannot be array.");
|
|
154
|
+
}
|
|
155
|
+
return errors;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
namespace CoreMetadataUtil {
|
|
160
|
+
export const atomics = (
|
|
161
|
+
meta: Metadata,
|
|
162
|
+
): Set<"boolean" | "bigint" | "number" | "string"> =>
|
|
163
|
+
new Set([
|
|
164
|
+
...meta.atomics.map((a) => a.type),
|
|
165
|
+
...meta.constants.map((c) => c.type),
|
|
166
|
+
...(meta.templates.length ? (["string"] as const) : []),
|
|
167
|
+
]);
|
|
168
|
+
|
|
169
|
+
export const isUnion = (meta: Metadata): boolean =>
|
|
170
|
+
atomics(meta).size +
|
|
171
|
+
meta.arrays.length +
|
|
172
|
+
meta.tuples.length +
|
|
173
|
+
meta.natives.length +
|
|
174
|
+
meta.maps.length +
|
|
175
|
+
meta.objects.length >
|
|
176
|
+
1;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const SINGULAR: Set<string> = new Set([
|
|
180
|
+
"age",
|
|
181
|
+
"authorization",
|
|
182
|
+
"content-length",
|
|
183
|
+
"content-type",
|
|
184
|
+
"etag",
|
|
185
|
+
"expires",
|
|
186
|
+
"from",
|
|
187
|
+
"host",
|
|
188
|
+
"if-modified-since",
|
|
189
|
+
"if-unmodified-since",
|
|
190
|
+
"last-modified",
|
|
191
|
+
"location",
|
|
192
|
+
"max-forwards",
|
|
193
|
+
"proxy-authorization",
|
|
194
|
+
"referer",
|
|
195
|
+
"retry-after",
|
|
196
|
+
"server",
|
|
197
|
+
"user-agent",
|
|
198
|
+
]);
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as nestia from "./module";
|
|
2
|
-
|
|
3
|
-
export * from "./module";
|
|
4
|
-
export default nestia;
|
|
1
|
+
import * as nestia from "./module";
|
|
2
|
+
|
|
3
|
+
export * from "./module";
|
|
4
|
+
export default nestia;
|
package/src/module.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./INestiaConfig";
|
|
2
|
-
export * from "./NestiaSdkApplication";
|
|
1
|
+
export * from "./INestiaConfig";
|
|
2
|
+
export * from "./NestiaSdkApplication";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export interface IErrorReport {
|
|
2
|
-
file: string;
|
|
3
|
-
controller: string;
|
|
4
|
-
function: string | null;
|
|
5
|
-
message: string;
|
|
6
|
-
}
|
|
1
|
+
export interface IErrorReport {
|
|
2
|
+
file: string;
|
|
3
|
+
controller: string;
|
|
4
|
+
function: string | null;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { INestiaConfig } from "../INestiaConfig";
|
|
4
|
-
import { IErrorReport } from "./IErrorReport";
|
|
5
|
-
import { INormalizedInput } from "./INormalizedInput";
|
|
6
|
-
|
|
7
|
-
export interface INestiaProject {
|
|
8
|
-
config: INestiaConfig;
|
|
9
|
-
input: INormalizedInput;
|
|
10
|
-
checker: ts.TypeChecker;
|
|
11
|
-
errors: IErrorReport[];
|
|
12
|
-
warnings: IErrorReport[];
|
|
13
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { INestiaConfig } from "../INestiaConfig";
|
|
4
|
+
import { IErrorReport } from "./IErrorReport";
|
|
5
|
+
import { INormalizedInput } from "./INormalizedInput";
|
|
6
|
+
|
|
7
|
+
export interface INestiaProject {
|
|
8
|
+
config: INestiaConfig;
|
|
9
|
+
input: INormalizedInput;
|
|
10
|
+
checker: ts.TypeChecker;
|
|
11
|
+
errors: IErrorReport[];
|
|
12
|
+
warnings: IErrorReport[];
|
|
13
|
+
}
|