@nestia/sdk 13.0.4 → 14.0.1
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 +1 -1
- package/assets/bundle/distribute/package.json +2 -2
- package/assets/bundle/distribute/tsconfig.json +15 -105
- package/lib/INestiaConfig.d.ts +19 -10
- package/lib/NestiaSdkApplication.js +58 -27
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/NestiaSwaggerComposer.js +11 -10
- package/lib/NestiaSwaggerComposer.js.map +1 -1
- package/lib/analyses/ConfigAnalyzer.js +4 -4
- package/lib/analyses/ConfigAnalyzer.js.map +1 -1
- package/lib/analyses/ParameterNameAnalyzer.d.ts +20 -0
- package/lib/analyses/ParameterNameAnalyzer.js +48 -0
- package/lib/analyses/ParameterNameAnalyzer.js.map +1 -0
- package/lib/analyses/PathAnalyzer.d.ts +30 -0
- package/lib/analyses/PathAnalyzer.js +108 -16
- package/lib/analyses/PathAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectControllerAnalyzer.js +2 -1
- package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationAnalyzer.js +7 -7
- package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +122 -23
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +5 -2
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectMcpOperationAnalyzer.js +5 -2
- package/lib/analyses/ReflectMcpOperationAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +6 -3
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -1
- package/lib/analyses/SecurityAnalyzer.d.ts +10 -0
- package/lib/analyses/SecurityAnalyzer.js +24 -19
- package/lib/analyses/SecurityAnalyzer.js.map +1 -1
- package/lib/analyses/SwaggerExampleAnalyzer.d.ts +15 -0
- package/lib/analyses/SwaggerExampleAnalyzer.js +20 -0
- package/lib/analyses/SwaggerExampleAnalyzer.js.map +1 -0
- package/lib/analyses/TypedHttpRouteAnalyzer.js +30 -21
- package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -1
- package/lib/analyses/TypedWebSocketRouteAnalyzer.js +1 -1
- package/lib/analyses/TypedWebSocketRouteAnalyzer.js.map +1 -1
- package/lib/executable/internal/NestiaSdkWatcher.js +3 -3
- package/lib/executable/internal/NestiaSdkWatcher.js.map +1 -1
- package/lib/executable/sdk.js +16 -1
- package/lib/executable/sdk.js.map +1 -1
- package/lib/factories/ExpressionFactory.d.ts +3 -0
- package/lib/factories/ExpressionFactory.js +6 -2
- package/lib/factories/ExpressionFactory.js.map +1 -1
- package/lib/factories/LiteralFactory.js +3 -1
- package/lib/factories/LiteralFactory.js.map +1 -1
- package/lib/generates/SdkGenerator.js +3 -3
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +135 -27
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/FilePrinter.d.ts +14 -0
- package/lib/generates/internal/FilePrinter.js +31 -0
- package/lib/generates/internal/FilePrinter.js.map +1 -1
- package/lib/generates/internal/ImportDictionary.d.ts +2 -0
- package/lib/generates/internal/ImportDictionary.js +13 -0
- package/lib/generates/internal/ImportDictionary.js.map +1 -1
- package/lib/generates/internal/SdkAliasCollection.d.ts +2 -1
- package/lib/generates/internal/SdkAliasCollection.js +8 -4
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
- package/lib/generates/internal/SdkDistributionComposer.js +72 -14
- package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.js +83 -12
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js +21 -23
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +27 -34
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpParameterProgrammer.d.ts +40 -1
- package/lib/generates/internal/SdkHttpParameterProgrammer.js +105 -6
- package/lib/generates/internal/SdkHttpParameterProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpRouteProgrammer.js +16 -32
- package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js +18 -14
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkMcpRouteProgrammer.js +39 -11
- package/lib/generates/internal/SdkMcpRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkPathTemplate.d.ts +21 -0
- package/lib/generates/internal/SdkPathTemplate.js +50 -0
- package/lib/generates/internal/SdkPathTemplate.js.map +1 -0
- package/lib/generates/internal/SdkTypeProgrammer.js +15 -15
- package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkTypeTagProgrammer.d.ts +20 -1
- package/lib/generates/internal/SdkTypeTagProgrammer.js +386 -67
- package/lib/generates/internal/SdkTypeTagProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +27 -36
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.d.ts +35 -1
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.js +72 -5
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +57 -33
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationComposer.js +19 -8
- package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.d.ts +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.js +201 -19
- package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +2 -0
- package/lib/generates/internal/SwaggerOperationResponseComposer.js +39 -7
- package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -1
- package/lib/internal/legacy.d.ts +49 -18
- package/lib/internal/legacy.js +84 -25
- package/lib/internal/legacy.js.map +1 -1
- package/lib/structures/IOperationMetadata.d.ts +22 -0
- package/lib/structures/IReflectHttpOperationException.d.ts +3 -2
- package/lib/structures/IReflectHttpOperationParameter.d.ts +8 -3
- package/lib/structures/IReflectHttpOperationSuccess.d.ts +4 -3
- package/lib/structures/ITypedHttpRoute.d.ts +8 -0
- package/lib/structures/ITypedHttpRouteException.d.ts +3 -1
- package/lib/structures/ITypedHttpRouteParameter.d.ts +3 -1
- package/lib/structures/ITypedHttpRouteSuccess.d.ts +3 -1
- package/lib/structures/ITypedWebSocketRoute.d.ts +8 -0
- package/lib/utils/SourceFinder.d.ts +10 -0
- package/lib/utils/SourceFinder.js +27 -4
- package/lib/utils/SourceFinder.js.map +1 -1
- package/lib/utils/VersioningStrategy.d.ts +13 -1
- package/lib/utils/VersioningStrategy.js +24 -12
- package/lib/utils/VersioningStrategy.js.map +1 -1
- package/native/go.mod +1 -1
- package/native/go.sum +2 -2
- package/native/sdk/sdk_http_rules.go +210 -0
- package/native/sdk/sdk_metadata_json.go +73 -3
- package/native/sdk/sdk_transform.go +801 -49
- package/package.json +8 -8
- package/src/INestiaConfig.ts +19 -10
- package/src/NestiaSdkApplication.ts +63 -34
- package/src/NestiaSwaggerComposer.ts +11 -8
- package/src/analyses/ConfigAnalyzer.ts +3 -3
- package/src/analyses/ParameterNameAnalyzer.ts +51 -0
- package/src/analyses/PathAnalyzer.ts +106 -14
- package/src/analyses/ReflectControllerAnalyzer.ts +2 -1
- package/src/analyses/ReflectHttpOperationAnalyzer.ts +4 -4
- package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +122 -39
- package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +6 -7
- package/src/analyses/ReflectMcpOperationAnalyzer.ts +6 -2
- package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +7 -3
- package/src/analyses/SecurityAnalyzer.ts +30 -20
- package/src/analyses/SwaggerExampleAnalyzer.ts +23 -0
- package/src/analyses/TypedHttpRouteAnalyzer.ts +29 -20
- package/src/analyses/TypedWebSocketRouteAnalyzer.ts +1 -0
- package/src/executable/internal/NestiaSdkWatcher.ts +2 -2
- package/src/executable/sdk.ts +24 -1
- package/src/factories/ExpressionFactory.ts +8 -2
- package/src/factories/LiteralFactory.ts +7 -2
- package/src/generates/SdkGenerator.ts +3 -3
- package/src/generates/SwaggerGenerator.ts +173 -32
- package/src/generates/internal/FilePrinter.ts +28 -0
- package/src/generates/internal/ImportDictionary.ts +11 -0
- package/src/generates/internal/SdkAliasCollection.ts +11 -4
- package/src/generates/internal/SdkDistributionComposer.ts +89 -15
- package/src/generates/internal/SdkFileProgrammer.ts +108 -16
- package/src/generates/internal/SdkHttpFunctionProgrammer.ts +28 -30
- package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +34 -64
- package/src/generates/internal/SdkHttpParameterProgrammer.ts +193 -13
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +17 -31
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +51 -14
- package/src/generates/internal/SdkMcpRouteProgrammer.ts +112 -15
- package/src/generates/internal/SdkPathTemplate.ts +73 -0
- package/src/generates/internal/SdkTypeProgrammer.ts +19 -22
- package/src/generates/internal/SdkTypeTagProgrammer.ts +506 -78
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +43 -68
- package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +126 -5
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +71 -48
- package/src/generates/internal/SwaggerOperationComposer.ts +20 -6
- package/src/generates/internal/SwaggerOperationParameterComposer.ts +279 -30
- package/src/generates/internal/SwaggerOperationResponseComposer.ts +55 -11
- package/src/internal/legacy.ts +114 -26
- package/src/structures/IOperationMetadata.ts +28 -0
- package/src/structures/IReflectHttpOperationException.ts +7 -2
- package/src/structures/IReflectHttpOperationParameter.ts +9 -2
- package/src/structures/IReflectHttpOperationSuccess.ts +8 -3
- package/src/structures/ITypedHttpRoute.ts +8 -0
- package/src/structures/ITypedHttpRouteException.ts +4 -1
- package/src/structures/ITypedHttpRouteParameter.ts +3 -1
- package/src/structures/ITypedHttpRouteSuccess.ts +4 -1
- package/src/structures/ITypedWebSocketRoute.ts +8 -0
- package/src/utils/SourceFinder.ts +25 -4
- package/src/utils/VersioningStrategy.ts +28 -13
- package/lib/validators/HttpHeadersValidator.d.ts +0 -11
- package/lib/validators/HttpHeadersValidator.js +0 -15
- package/lib/validators/HttpHeadersValidator.js.map +0 -1
- package/lib/validators/HttpQueryValidator.d.ts +0 -10
- package/lib/validators/HttpQueryValidator.js +0 -14
- package/lib/validators/HttpQueryValidator.js.map +0 -1
- package/src/validators/HttpHeadersValidator.ts +0 -12
- package/src/validators/HttpQueryValidator.ts +0 -11
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
package sdk
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"encoding/json"
|
|
5
|
+
"regexp"
|
|
6
|
+
|
|
7
|
+
shimchecker "github.com/microsoft/typescript-go/shim/checker"
|
|
8
|
+
|
|
9
|
+
nativefactories "github.com/samchon/typia/packages/typia/native/core/factories"
|
|
10
|
+
nativehelpers "github.com/samchon/typia/packages/typia/native/core/programmers/helpers"
|
|
11
|
+
nativehttp "github.com/samchon/typia/packages/typia/native/core/programmers/http"
|
|
12
|
+
schemametadata "github.com/samchon/typia/packages/typia/native/core/schemas/metadata"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
// nestiaSDKHttpRules bakes, for one route parameter, the violations of each
|
|
16
|
+
// HTTP input category's rules, keyed by the category.
|
|
17
|
+
//
|
|
18
|
+
// The SDK generators read a parameter's type from this metadata and write it
|
|
19
|
+
// onto the wire as a query string, headers, a path segment, or a form. Only a
|
|
20
|
+
// type those rules accept survives that: an object nested in a query object
|
|
21
|
+
// is sent as `[object Object]`, a path parameter object as its `toString()`.
|
|
22
|
+
// `@TypedQuery()`, `@TypedHeaders()`, and `@TypedParam()` are held to the
|
|
23
|
+
// rules by the core transform, which runs typia's HTTP programmers on them,
|
|
24
|
+
// but a vanilla `@Query()`, `@Headers()`, or `@Param()` reaches no transform,
|
|
25
|
+
// so the SDK checks it here. Which decorator a parameter carries is runtime
|
|
26
|
+
// metadata this contributor cannot see, so every category is baked and the
|
|
27
|
+
// SDK picks the one the decorator selects.
|
|
28
|
+
//
|
|
29
|
+
// The rules are typia's own validators where typia exports them (query,
|
|
30
|
+
// headers, form data), walked with typia's `MetadataFactory.Validate` over
|
|
31
|
+
// the type analyzed as typia's HTTP programmers analyze it, so they cannot
|
|
32
|
+
// drift from what the transform enforces on the typed decorators. That is its
|
|
33
|
+
// own analysis: the SDK's metadata shares one component collection with the
|
|
34
|
+
// escaped analysis of the same types, where a `Date` property is already the
|
|
35
|
+
// string its JSON holds, which a query string cannot send either. typia keeps
|
|
36
|
+
// the path parameter rule unexported, and a field-named `@Query("x")` or
|
|
37
|
+
// `@Headers("x")` is nestia's own case, so those two are written here.
|
|
38
|
+
func nestiaSDKHttpRules(checker *shimchecker.Checker, typ *shimchecker.Type) map[string]any {
|
|
39
|
+
output := map[string]any{}
|
|
40
|
+
analyzed := nativefactories.MetadataFactory.Analyze(nativefactories.MetadataFactory_IProps{
|
|
41
|
+
Checker: checker,
|
|
42
|
+
Options: nativefactories.MetadataFactory_IOptions{
|
|
43
|
+
Escape: false,
|
|
44
|
+
Constant: true,
|
|
45
|
+
Absorb: true,
|
|
46
|
+
},
|
|
47
|
+
Components: schemametadata.NewMetadataCollection(),
|
|
48
|
+
Type: typ,
|
|
49
|
+
})
|
|
50
|
+
if analyzed.Success == false {
|
|
51
|
+
// no rule can judge a type typia cannot analyze; every category
|
|
52
|
+
// reports why
|
|
53
|
+
errors := nestiaSDKHttpRuleErrors(analyzed.Errors)
|
|
54
|
+
for _, category := range []string{"query", "headers", "param", "field", "formData"} {
|
|
55
|
+
output[category] = errors
|
|
56
|
+
}
|
|
57
|
+
return output
|
|
58
|
+
}
|
|
59
|
+
metadata := analyzed.Data
|
|
60
|
+
for _, rule := range []struct {
|
|
61
|
+
category string
|
|
62
|
+
functor nativefactories.MetadataFactory_Validator
|
|
63
|
+
}{
|
|
64
|
+
{"query", nestiaSDKHttpQueryRule},
|
|
65
|
+
{"headers", nativehttp.HttpHeadersProgrammer.Validate},
|
|
66
|
+
{"param", nestiaSDKHttpParamRule},
|
|
67
|
+
{"field", nestiaSDKHttpFieldRule},
|
|
68
|
+
{"formData", nativehttp.HttpFormDataProgrammer.Validate},
|
|
69
|
+
} {
|
|
70
|
+
errors := nativefactories.MetadataFactory.Validate(struct {
|
|
71
|
+
Options nativefactories.MetadataFactory_IOptions
|
|
72
|
+
Functor nativefactories.MetadataFactory_Validator
|
|
73
|
+
Metadata *schemametadata.MetadataSchema
|
|
74
|
+
}{
|
|
75
|
+
Options: nativefactories.MetadataFactory_IOptions{
|
|
76
|
+
Escape: false,
|
|
77
|
+
Constant: true,
|
|
78
|
+
Absorb: true,
|
|
79
|
+
Validate: rule.functor,
|
|
80
|
+
},
|
|
81
|
+
Functor: rule.functor,
|
|
82
|
+
Metadata: metadata,
|
|
83
|
+
})
|
|
84
|
+
output[rule.category] = nestiaSDKHttpRuleErrors(errors)
|
|
85
|
+
}
|
|
86
|
+
return output
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// nestiaSDKHttpQueryRule is typia's query rule as `@TypedQuery()` applies it,
|
|
90
|
+
// which admits an optional query object whose properties are all optional.
|
|
91
|
+
func nestiaSDKHttpQueryRule(props struct {
|
|
92
|
+
Metadata *schemametadata.MetadataSchema
|
|
93
|
+
Explore nativefactories.MetadataFactory_IExplore
|
|
94
|
+
Top *schemametadata.MetadataSchema
|
|
95
|
+
}) []string {
|
|
96
|
+
return nativehttp.HttpQueryProgrammer.Validate(struct {
|
|
97
|
+
Metadata *schemametadata.MetadataSchema
|
|
98
|
+
Explore nativefactories.MetadataFactory_IExplore
|
|
99
|
+
Top *schemametadata.MetadataSchema
|
|
100
|
+
AllowOptional bool
|
|
101
|
+
}{
|
|
102
|
+
Metadata: props.Metadata,
|
|
103
|
+
Explore: props.Explore,
|
|
104
|
+
Top: props.Top,
|
|
105
|
+
AllowOptional: true,
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// nestiaSDKHttpParamRule is typia's path parameter rule
|
|
110
|
+
// (`httpParameterProgrammer_validate`, which typia does not export): one
|
|
111
|
+
// required atomic or constant type, and nothing `any`.
|
|
112
|
+
func nestiaSDKHttpParamRule(props struct {
|
|
113
|
+
Metadata *schemametadata.MetadataSchema
|
|
114
|
+
Explore nativefactories.MetadataFactory_IExplore
|
|
115
|
+
Top *schemametadata.MetadataSchema
|
|
116
|
+
}) []string {
|
|
117
|
+
errors := []string{}
|
|
118
|
+
if props.Metadata.Any {
|
|
119
|
+
errors = append(errors, "do not allow any type")
|
|
120
|
+
}
|
|
121
|
+
if props.Metadata.IsRequired() == false {
|
|
122
|
+
errors = append(errors, "do not allow undefined type")
|
|
123
|
+
}
|
|
124
|
+
atomics := nativehelpers.HttpMetadataUtil.Atomics(props.Metadata)
|
|
125
|
+
if props.Metadata.Size() != nestiaSDKHttpAtomicSize(props.Metadata) || len(atomics) == 0 {
|
|
126
|
+
errors = append(errors, "only atomic or constant types are allowed")
|
|
127
|
+
}
|
|
128
|
+
if len(atomics) > 1 {
|
|
129
|
+
errors = append(errors, "do not allow union type")
|
|
130
|
+
}
|
|
131
|
+
return errors
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// nestiaSDKHttpFieldRule is the rule of a field-named `@Query("key")` or
|
|
135
|
+
// `@Headers("key")`, which carries one query key or header rather than an
|
|
136
|
+
// object: an atomic, constant, or template type, or an array of those.
|
|
137
|
+
func nestiaSDKHttpFieldRule(props struct {
|
|
138
|
+
Metadata *schemametadata.MetadataSchema
|
|
139
|
+
Explore nativefactories.MetadataFactory_IExplore
|
|
140
|
+
Top *schemametadata.MetadataSchema
|
|
141
|
+
}) []string {
|
|
142
|
+
if props.Explore.Top {
|
|
143
|
+
if props.Metadata.Size() != nestiaSDKHttpAtomicSize(props.Metadata)+len(props.Metadata.Arrays) {
|
|
144
|
+
return []string{"only atomic or array of atomic types are allowed."}
|
|
145
|
+
}
|
|
146
|
+
} else if _, ok := props.Explore.Nested.(*schemametadata.MetadataArrayType); ok {
|
|
147
|
+
if props.Metadata.Size() != nestiaSDKHttpAtomicSize(props.Metadata) {
|
|
148
|
+
return []string{"only atomic types are allowed in array."}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return nil
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
func nestiaSDKHttpAtomicSize(metadata *schemametadata.MetadataSchema) int {
|
|
155
|
+
size := len(metadata.Atomics) + len(metadata.Templates)
|
|
156
|
+
for _, constant := range metadata.Constants {
|
|
157
|
+
size += len(constant.Values)
|
|
158
|
+
}
|
|
159
|
+
return size
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// nestiaSDKHttpRuleErrors writes rule violations the way the SDK reports a
|
|
163
|
+
// failed metadata pipe: the type's name, the property it was found at, and the
|
|
164
|
+
// messages.
|
|
165
|
+
func nestiaSDKHttpRuleErrors(errors []nativefactories.MetadataFactory_IError) []any {
|
|
166
|
+
output := make([]any, 0, len(errors))
|
|
167
|
+
for _, err := range errors {
|
|
168
|
+
output = append(output, map[string]any{
|
|
169
|
+
"name": err.Name,
|
|
170
|
+
"accessor": nestiaSDKHttpRuleAccessor(err.Explore),
|
|
171
|
+
"messages": err.Messages,
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
return output
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
var nestiaSDKVariableName = regexp.MustCompile(`^[A-Za-z_$][A-Za-z0-9_$]*$`)
|
|
178
|
+
|
|
179
|
+
// nestiaSDKHttpRuleAccessor names the property a violation was found at:
|
|
180
|
+
// `IType.key`, `IType["x-key"]`, or `IType[key]` for a dynamic one. typia
|
|
181
|
+
// hands over the key, or, for a violation in the property's comment tags, the
|
|
182
|
+
// property itself.
|
|
183
|
+
func nestiaSDKHttpRuleAccessor(explore nativefactories.MetadataFactory_IExplore) any {
|
|
184
|
+
if explore.Object == nil {
|
|
185
|
+
return nestiaSDKLiteralNull
|
|
186
|
+
}
|
|
187
|
+
key := explore.Property
|
|
188
|
+
if property, ok := key.(*schemametadata.MetadataProperty); ok && property != nil {
|
|
189
|
+
key = nil
|
|
190
|
+
if property.Key != nil &&
|
|
191
|
+
len(property.Key.Constants) == 1 &&
|
|
192
|
+
len(property.Key.Constants[0].Values) == 1 {
|
|
193
|
+
key = property.Key.Constants[0].Values[0].Value
|
|
194
|
+
}
|
|
195
|
+
if key == nil {
|
|
196
|
+
return explore.Object.Name + "[key]"
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
switch key := key.(type) {
|
|
200
|
+
case nil:
|
|
201
|
+
return explore.Object.Name
|
|
202
|
+
case string:
|
|
203
|
+
if nestiaSDKVariableName.MatchString(key) {
|
|
204
|
+
return explore.Object.Name + "." + key
|
|
205
|
+
}
|
|
206
|
+
text, _ := json.Marshal(key)
|
|
207
|
+
return explore.Object.Name + "[" + string(text) + "]"
|
|
208
|
+
}
|
|
209
|
+
return explore.Object.Name + "[key]"
|
|
210
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
package sdk
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import (
|
|
4
|
+
"math"
|
|
5
|
+
"reflect"
|
|
6
|
+
|
|
7
|
+
schemametadata "github.com/samchon/typia/packages/typia/native/core/schemas/metadata"
|
|
8
|
+
)
|
|
4
9
|
|
|
5
10
|
func nestiaSDKMetadataComponentsLiteral(
|
|
6
11
|
components schemametadata.IMetadataComponents,
|
|
@@ -94,7 +99,7 @@ func nestiaSDKMetadataConstants(
|
|
|
94
99
|
values := []any{}
|
|
95
100
|
for _, value := range constant.Values {
|
|
96
101
|
values = append(values, map[string]any{
|
|
97
|
-
"value": value.Value,
|
|
102
|
+
"value": nestiaSDKMetadataConstantValue(value.Value),
|
|
98
103
|
"tags": nestiaSDKMetadataTagMatrix(value.Tags),
|
|
99
104
|
"description": nestiaSDKOptionalString(value.Description),
|
|
100
105
|
"jsDocTags": nestiaSDKJSDocTags(value.JsDocTags),
|
|
@@ -272,14 +277,21 @@ func nestiaSDKMetadataTagMatrix(
|
|
|
272
277
|
}
|
|
273
278
|
|
|
274
279
|
func nestiaSDKMetadataTypeTag(tag schemametadata.IMetadataTypeTag) map[string]any {
|
|
280
|
+
value, encoding := nestiaSDKMetadataValue(tag.Value)
|
|
275
281
|
output := map[string]any{
|
|
276
282
|
"target": tag.Target,
|
|
277
283
|
"name": tag.Name,
|
|
278
284
|
"kind": tag.Kind,
|
|
279
285
|
"exclusive": tag.Exclusive,
|
|
280
|
-
"value":
|
|
286
|
+
"value": value,
|
|
281
287
|
"schema": tag.Schema,
|
|
282
288
|
}
|
|
289
|
+
// A tag's target is the type it tags, not its value's: `tags.Sequence<1>`
|
|
290
|
+
// on a bigint holds a number, `tags.Example<"Infinity">` on a number a
|
|
291
|
+
// string. So an encoded value names the type it stands for.
|
|
292
|
+
if encoding != "" {
|
|
293
|
+
output["encoding"] = encoding
|
|
294
|
+
}
|
|
283
295
|
if tag.Validate != "" {
|
|
284
296
|
output["validate"] = tag.Validate
|
|
285
297
|
}
|
|
@@ -325,3 +337,61 @@ func nestiaSDKOptionalInt(input *int) any {
|
|
|
325
337
|
}
|
|
326
338
|
return *input
|
|
327
339
|
}
|
|
340
|
+
|
|
341
|
+
// nestiaSDKMetadataConstantValue writes a constant's value for the metadata
|
|
342
|
+
// literal. The constant's type is its value's own, so a string the value is
|
|
343
|
+
// encoded as is read back by that type.
|
|
344
|
+
func nestiaSDKMetadataConstantValue(input any) any {
|
|
345
|
+
value, _ := nestiaSDKMetadataValue(input)
|
|
346
|
+
return value
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// nestiaSDKMetadataValue writes a constant's or a type tag's value for the
|
|
350
|
+
// metadata literal, keeping what a JSON number cannot hold, and returns the
|
|
351
|
+
// type an encoded value stands for.
|
|
352
|
+
//
|
|
353
|
+
// The SDK generator reads these values to write types back, the literal type
|
|
354
|
+
// `5n` or the tag `tags.Minimum<1e999>` of a cloned DTO, so a lossy value
|
|
355
|
+
// becomes a wrong or uncompilable type. typia marshals a bigint as a bare JSON
|
|
356
|
+
// number, which the generator's `JSON.parse` rounds past 2^53, and JSON has no
|
|
357
|
+
// NaN or ±Infinity at all. So a bigint is written as its decimal digits and a
|
|
358
|
+
// non-finite number by its JavaScript name (`"NaN"`, `"Infinity"`,
|
|
359
|
+
// `"-Infinity"`), as strings the generator reads back as `"bigint"` or
|
|
360
|
+
// `"number"`.
|
|
361
|
+
//
|
|
362
|
+
// Only the value itself is encoded. A composite one, such as the object
|
|
363
|
+
// `tags.Examples` or `tags.JsonSchemaPlugin` takes, may hold any string, so
|
|
364
|
+
// an encoded member could not be told apart; its members keep what a JSON
|
|
365
|
+
// document holds, as the tag's `schema` and the baked JSON schemas do
|
|
366
|
+
// (nestiaSDKFiniteLiteral).
|
|
367
|
+
func nestiaSDKMetadataValue(input any) (any, string) {
|
|
368
|
+
switch value := input.(type) {
|
|
369
|
+
case schemametadata.MetadataBigint:
|
|
370
|
+
return nestiaSDKBigintText(value), "bigint"
|
|
371
|
+
case *schemametadata.MetadataBigint:
|
|
372
|
+
if value != nil {
|
|
373
|
+
return nestiaSDKBigintText(*value), "bigint"
|
|
374
|
+
}
|
|
375
|
+
return input, ""
|
|
376
|
+
}
|
|
377
|
+
reflected := reflect.ValueOf(input)
|
|
378
|
+
if reflected.Kind() != reflect.Float32 && reflected.Kind() != reflect.Float64 {
|
|
379
|
+
return input, ""
|
|
380
|
+
}
|
|
381
|
+
number := reflected.Float()
|
|
382
|
+
if math.IsNaN(number) {
|
|
383
|
+
return "NaN", "number"
|
|
384
|
+
} else if math.IsInf(number, 1) {
|
|
385
|
+
return "Infinity", "number"
|
|
386
|
+
} else if math.IsInf(number, -1) {
|
|
387
|
+
return "-Infinity", "number"
|
|
388
|
+
}
|
|
389
|
+
return input, ""
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
func nestiaSDKBigintText(value schemametadata.MetadataBigint) string {
|
|
393
|
+
if value.Text == "" {
|
|
394
|
+
return "0"
|
|
395
|
+
}
|
|
396
|
+
return value.Text
|
|
397
|
+
}
|