@tsed/schema 8.0.0 → 8.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/package.json +11 -10
- package/src/components/async-api/channelsMapper.ts +81 -0
- package/src/components/async-api/generate.ts +24 -0
- package/src/components/async-api/messageMapper.ts +62 -0
- package/src/components/async-api/payloadMapper.ts +61 -0
- package/src/components/async-api/responseMapper.ts +70 -0
- package/src/components/default/anyMapper.spec.ts +7 -0
- package/src/components/default/anyMapper.ts +33 -0
- package/src/components/default/classMapper.ts +55 -0
- package/src/components/default/discriminatorMappingMapper.ts +36 -0
- package/src/components/default/enumsMapper.spec.ts +64 -0
- package/src/components/default/enumsMapper.ts +17 -0
- package/src/components/default/genericsMapper.ts +70 -0
- package/src/components/default/inheritedClassMapper.ts +24 -0
- package/src/components/default/itemMapper.ts +8 -0
- package/src/components/default/lazyRefMapper.ts +21 -0
- package/src/components/default/mapMapper.ts +25 -0
- package/src/components/default/nullableMapper.ts +55 -0
- package/src/components/default/objectMapper.ts +36 -0
- package/src/components/default/ofMapper.ts +16 -0
- package/src/components/default/propertiesMapper.ts +25 -0
- package/src/components/default/requiredMapper.ts +69 -0
- package/src/components/default/schemaMapper.ts +151 -0
- package/src/components/index.ts +36 -0
- package/src/components/open-spec/discriminatorMappingMapper.ts +7 -0
- package/src/components/open-spec/enumsMapper.ts +20 -0
- package/src/components/open-spec/generate.ts +29 -0
- package/src/components/open-spec/nullableMapper.ts +51 -0
- package/src/components/open-spec/operationInFilesMapper.ts +32 -0
- package/src/components/open-spec/operationInParameterMapper.ts +56 -0
- package/src/components/open-spec/operationInParametersMapper.ts +9 -0
- package/src/components/open-spec/operationInQueryMapper.ts +74 -0
- package/src/components/open-spec/operationMapper.ts +65 -0
- package/src/components/open-spec/operationMediaMapper.ts +11 -0
- package/src/components/open-spec/operationRequestBodyMapper.ts +82 -0
- package/src/components/open-spec/operationResponseMapper.ts +26 -0
- package/src/components/open-spec/pathsMapper.ts +132 -0
- package/src/constants/OperationVerbs.ts +29 -0
- package/src/constants/httpStatusMessages.ts +21 -0
- package/src/constants/jsonSchemaProperties.ts +17 -0
- package/src/decorators/class/children.ts +22 -0
- package/src/decorators/class/discriminatorValue.ts +53 -0
- package/src/decorators/collections/collectionContains.ts +25 -0
- package/src/decorators/collections/collectionOf.spec.ts +327 -0
- package/src/decorators/collections/collectionOf.ts +182 -0
- package/src/decorators/collections/maxItems.spec.ts +40 -0
- package/src/decorators/collections/maxItems.ts +59 -0
- package/src/decorators/collections/maxProperties.spec.ts +109 -0
- package/src/decorators/collections/maxProperties.ts +82 -0
- package/src/decorators/collections/minItems.spec.ts +40 -0
- package/src/decorators/collections/minItems.ts +63 -0
- package/src/decorators/collections/minProperties.spec.ts +109 -0
- package/src/decorators/collections/minProperties.ts +81 -0
- package/src/decorators/collections/uniqueItems.spec.ts +28 -0
- package/src/decorators/collections/uniqueItems.ts +59 -0
- package/src/decorators/common/__snapshots__/groups.spec.ts.snap +321 -0
- package/src/decorators/common/additionalProperties.spec.ts +133 -0
- package/src/decorators/common/additionalProperties.ts +17 -0
- package/src/decorators/common/allOf.spec.ts +276 -0
- package/src/decorators/common/allOf.ts +19 -0
- package/src/decorators/common/allow.spec.ts +130 -0
- package/src/decorators/common/allow.ts +50 -0
- package/src/decorators/common/any.spec.ts +109 -0
- package/src/decorators/common/any.ts +45 -0
- package/src/decorators/common/anyOf.spec.ts +270 -0
- package/src/decorators/common/anyOf.ts +23 -0
- package/src/decorators/common/const.spec.ts +98 -0
- package/src/decorators/common/const.ts +68 -0
- package/src/decorators/common/customKey.spec.ts +105 -0
- package/src/decorators/common/customKey.ts +39 -0
- package/src/decorators/common/default.spec.ts +25 -0
- package/src/decorators/common/default.ts +47 -0
- package/src/decorators/common/defaultMsg.spec.ts +22 -0
- package/src/decorators/common/defaultMsg.ts +38 -0
- package/src/decorators/common/description.spec.ts +166 -0
- package/src/decorators/common/description.ts +77 -0
- package/src/decorators/common/discriminatorKey.ts +14 -0
- package/src/decorators/common/enum.spec.ts +305 -0
- package/src/decorators/common/enum.ts +111 -0
- package/src/decorators/common/errorMsg.spec.ts +57 -0
- package/src/decorators/common/errorMsg.ts +14 -0
- package/src/decorators/common/example.spec.ts +93 -0
- package/src/decorators/common/example.ts +18 -0
- package/src/decorators/common/examples.spec.ts +101 -0
- package/src/decorators/common/examples.ts +20 -0
- package/src/decorators/common/exclusiveMaximum.spec.ts +47 -0
- package/src/decorators/common/exclusiveMaximum.ts +75 -0
- package/src/decorators/common/exclusiveMinimum.spec.ts +47 -0
- package/src/decorators/common/exclusiveMinimum.ts +75 -0
- package/src/decorators/common/format.spec.ts +149 -0
- package/src/decorators/common/format.ts +486 -0
- package/src/decorators/common/forwardGroups.spec.ts +270 -0
- package/src/decorators/common/forwardGroups.ts +16 -0
- package/src/decorators/common/groups.spec.ts +968 -0
- package/src/decorators/common/groups.ts +66 -0
- package/src/decorators/common/hidden.spec.ts +52 -0
- package/src/decorators/common/hidden.ts +36 -0
- package/src/decorators/common/ignore.spec.ts +88 -0
- package/src/decorators/common/ignore.ts +66 -0
- package/src/decorators/common/integer.spec.ts +110 -0
- package/src/decorators/common/integer.ts +69 -0
- package/src/decorators/common/jsonEntityFn.spec.ts +16 -0
- package/src/decorators/common/jsonEntityFn.ts +33 -0
- package/src/decorators/common/maxLength.spec.ts +61 -0
- package/src/decorators/common/maxLength.ts +88 -0
- package/src/decorators/common/maximum.spec.ts +73 -0
- package/src/decorators/common/maximum.ts +146 -0
- package/src/decorators/common/minLength.spec.ts +186 -0
- package/src/decorators/common/minLength.ts +89 -0
- package/src/decorators/common/minimum.spec.ts +74 -0
- package/src/decorators/common/minimum.ts +145 -0
- package/src/decorators/common/multipleOf.spec.ts +33 -0
- package/src/decorators/common/multipleOf.ts +80 -0
- package/src/decorators/common/name.spec.ts +56 -0
- package/src/decorators/common/name.ts +50 -0
- package/src/decorators/common/nullable.spec.ts +818 -0
- package/src/decorators/common/nullable.ts +32 -0
- package/src/decorators/common/oneOf.spec.ts +301 -0
- package/src/decorators/common/oneOf.ts +24 -0
- package/src/decorators/common/optional.spec.ts +43 -0
- package/src/decorators/common/optional.ts +26 -0
- package/src/decorators/common/pattern.spec.ts +27 -0
- package/src/decorators/common/pattern.ts +102 -0
- package/src/decorators/common/property.ts +24 -0
- package/src/decorators/common/readOnly.spec.ts +135 -0
- package/src/decorators/common/readOnly.ts +17 -0
- package/src/decorators/common/recordOf.spec.ts +41 -0
- package/src/decorators/common/recordOf.ts +59 -0
- package/src/decorators/common/required.spec.ts +188 -0
- package/src/decorators/common/required.ts +50 -0
- package/src/decorators/common/requiredGroups.spec.ts +127 -0
- package/src/decorators/common/requiredGroups.ts +23 -0
- package/src/decorators/common/schema.spec.ts +23 -0
- package/src/decorators/common/schema.ts +64 -0
- package/src/decorators/common/title.spec.ts +20 -0
- package/src/decorators/common/title.ts +45 -0
- package/src/decorators/common/typeError.spec.ts +22 -0
- package/src/decorators/common/typeError.ts +15 -0
- package/src/decorators/common/writeOnly.spec.ts +105 -0
- package/src/decorators/common/writeOnly.ts +17 -0
- package/src/decorators/config/jsonEntityComponent.ts +16 -0
- package/src/decorators/generics/genericOf.spec.ts +246 -0
- package/src/decorators/generics/genericOf.ts +112 -0
- package/src/decorators/generics/generics.ts +22 -0
- package/src/decorators/operations/acceptMime.spec.ts +39 -0
- package/src/decorators/operations/acceptMime.ts +25 -0
- package/src/decorators/operations/consumes.spec.ts +89 -0
- package/src/decorators/operations/consumes.ts +37 -0
- package/src/decorators/operations/contentType.spec.ts +40 -0
- package/src/decorators/operations/contentType.ts +24 -0
- package/src/decorators/operations/deprecated.spec.ts +223 -0
- package/src/decorators/operations/deprecated.ts +49 -0
- package/src/decorators/operations/header.spec.ts +214 -0
- package/src/decorators/operations/header.ts +62 -0
- package/src/decorators/operations/in.spec.ts +321 -0
- package/src/decorators/operations/in.ts +141 -0
- package/src/decorators/operations/inFile.spec.ts +209 -0
- package/src/decorators/operations/inFile.ts +55 -0
- package/src/decorators/operations/location.spec.ts +51 -0
- package/src/decorators/operations/location.ts +26 -0
- package/src/decorators/operations/operation.ts +119 -0
- package/src/decorators/operations/operationId.spec.ts +43 -0
- package/src/decorators/operations/operationId.ts +22 -0
- package/src/decorators/operations/operationPath.spec.ts +42 -0
- package/src/decorators/operations/operationPath.ts +33 -0
- package/src/decorators/operations/partial.spec.ts +249 -0
- package/src/decorators/operations/partial.ts +14 -0
- package/src/decorators/operations/path.spec.ts +47 -0
- package/src/decorators/operations/path.ts +27 -0
- package/src/decorators/operations/produces.spec.ts +89 -0
- package/src/decorators/operations/produces.ts +44 -0
- package/src/decorators/operations/publish.spec.ts +26 -0
- package/src/decorators/operations/publish.ts +6 -0
- package/src/decorators/operations/redirect.spec.ts +146 -0
- package/src/decorators/operations/redirect.ts +82 -0
- package/src/decorators/operations/returns.spec.ts +1393 -0
- package/src/decorators/operations/returns.ts +662 -0
- package/src/decorators/operations/route.spec.ts +211 -0
- package/src/decorators/operations/route.ts +154 -0
- package/src/decorators/operations/security.spec.ts +162 -0
- package/src/decorators/operations/security.ts +83 -0
- package/src/decorators/operations/status.spec.ts +582 -0
- package/src/decorators/operations/status.ts +130 -0
- package/src/decorators/operations/subscribe.spec.ts +32 -0
- package/src/decorators/operations/subscribe.ts +6 -0
- package/src/decorators/operations/summary.spec.ts +45 -0
- package/src/decorators/operations/summary.ts +32 -0
- package/src/decorators/operations/tags.spec.ts +113 -0
- package/src/decorators/operations/tags.ts +53 -0
- package/src/decorators/operations/view.spec.ts +16 -0
- package/src/decorators/operations/view.ts +27 -0
- package/src/domain/DecoratorContext.ts +116 -0
- package/src/domain/JsonAliasMap.ts +19 -0
- package/src/domain/JsonClassStore.ts +35 -0
- package/src/domain/JsonDiscriminator.spec.ts +65 -0
- package/src/domain/JsonDiscriminator.ts +52 -0
- package/src/domain/JsonEntityStore.spec.ts +277 -0
- package/src/domain/JsonEntityStore.ts +284 -0
- package/src/domain/JsonFormatTypes.ts +17 -0
- package/src/domain/JsonLazyRef.ts +21 -0
- package/src/domain/JsonMap.spec.ts +15 -0
- package/src/domain/JsonMap.ts +33 -0
- package/src/domain/JsonMedia.ts +24 -0
- package/src/domain/JsonMethodStore.spec.ts +301 -0
- package/src/domain/JsonMethodStore.ts +212 -0
- package/src/domain/JsonOperation.spec.ts +126 -0
- package/src/domain/JsonOperation.ts +219 -0
- package/src/domain/JsonOperationPathsMap.ts +16 -0
- package/src/domain/JsonOperationRoute.spec.ts +109 -0
- package/src/domain/JsonOperationRoute.ts +75 -0
- package/src/domain/JsonParameter.ts +70 -0
- package/src/domain/JsonParameterStore.spec.ts +212 -0
- package/src/domain/JsonParameterStore.ts +138 -0
- package/src/domain/JsonParameterTypes.spec.ts +12 -0
- package/src/domain/JsonParameterTypes.ts +20 -0
- package/src/domain/JsonPropertyStore.spec.ts +177 -0
- package/src/domain/JsonPropertyStore.ts +92 -0
- package/src/domain/JsonRequestBody.ts +47 -0
- package/src/domain/JsonResponse.spec.ts +33 -0
- package/src/domain/JsonResponse.ts +64 -0
- package/src/domain/JsonSchema.spec.ts +1470 -0
- package/src/domain/JsonSchema.ts +1049 -0
- package/src/domain/SpecTypes.ts +6 -0
- package/src/hooks/alterIgnore.ts +25 -0
- package/src/hooks/alterOneOf.ts +67 -0
- package/src/hooks/alterRequiredGroups.ts +12 -0
- package/src/index.ts +185 -0
- package/src/interfaces/IgnoreCallback.ts +5 -0
- package/src/interfaces/JsonHookContext.ts +18 -0
- package/src/interfaces/JsonOpenSpec.ts +7 -0
- package/src/interfaces/JsonSchemaOptions.ts +35 -0
- package/src/registries/JsonSchemaMapperContainer.ts +52 -0
- package/src/registries/enumRegistries.ts +3 -0
- package/src/utils/__snapshots__/generateSpec.spec.ts.snap +109 -0
- package/src/utils/buildPath.ts +8 -0
- package/src/utils/concatParameters.ts +12 -0
- package/src/utils/concatPath.spec.ts +23 -0
- package/src/utils/concatPath.ts +24 -0
- package/src/utils/defineStatusModel.ts +11 -0
- package/src/utils/from.spec.ts +243 -0
- package/src/utils/from.ts +281 -0
- package/src/utils/generateSpec.spec.ts +1262 -0
- package/src/utils/generateSpec.ts +54 -0
- package/src/utils/generics.ts +83 -0
- package/src/utils/getComputedType.spec.ts +45 -0
- package/src/utils/getComputedType.ts +39 -0
- package/src/utils/getInheritedStores.spec.ts +47 -0
- package/src/utils/getInheritedStores.ts +23 -0
- package/src/utils/getJsonEntityStore.ts +36 -0
- package/src/utils/getJsonPathParameters.spec.ts +126 -0
- package/src/utils/getJsonPathParameters.ts +97 -0
- package/src/utils/getJsonSchema.spec.ts +695 -0
- package/src/utils/getJsonSchema.ts +69 -0
- package/src/utils/getJsonType.spec.ts +28 -0
- package/src/utils/getJsonType.ts +46 -0
- package/src/utils/getOperationsRoutes.spec.ts +284 -0
- package/src/utils/getOperationsRoutes.ts +56 -0
- package/src/utils/getOperationsStore.spec.ts +47 -0
- package/src/utils/getOperationsStores.ts +37 -0
- package/src/utils/getPropertiesStores.spec.ts +138 -0
- package/src/utils/getPropertiesStores.ts +66 -0
- package/src/utils/getSpec.spec.ts +610 -0
- package/src/utils/getSpec.ts +117 -0
- package/src/utils/getSpecType.spec.ts +16 -0
- package/src/utils/getSpecType.ts +19 -0
- package/src/utils/isSuccessStatus.spec.ts +22 -0
- package/src/utils/isSuccessStatus.ts +2 -0
- package/src/utils/mapHeaders.spec.ts +57 -0
- package/src/utils/mapHeaders.ts +33 -0
- package/src/utils/mapOpenSpec.ts +44 -0
- package/src/utils/mapOpenSpec2.ts +50 -0
- package/src/utils/mapOpenSpec3.ts +25 -0
- package/src/utils/mapOpenSpecInfo.ts +19 -0
- package/src/utils/mapOperationOptions.ts +34 -0
- package/src/utils/matchGroups.spec.ts +85 -0
- package/src/utils/matchGroups.ts +64 -0
- package/src/utils/mergeSpec.spec.ts +533 -0
- package/src/utils/mergeSpec.ts +54 -0
- package/src/utils/operationIdFormatter.spec.ts +11 -0
- package/src/utils/operationIdFormatter.ts +49 -0
- package/src/utils/ref.ts +65 -0
- package/src/utils/removeHiddenOperation.ts +5 -0
- package/src/utils/serializeEnumValues.ts +27 -0
- package/src/utils/somethingOf.ts +11 -0
- package/src/utils/toJsonMapCollection.spec.ts +18 -0
- package/src/utils/toJsonMapCollection.ts +12 -0
- package/src/utils/toJsonRegex.ts +7 -0
- package/src/utils/transformToOS2.spec.ts +177 -0
- package/src/utils/transformToOS2.ts +607 -0
- package/src/utils/withErrorMsg.spec.ts +16 -0
- package/src/utils/withErrorMsg.ts +56 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import {deepMerge, uniq, uniqBy} from "@tsed/core";
|
|
2
|
+
import {OpenSpecSecurity, OpenSpecTag, OS3Operation} from "@tsed/openspec";
|
|
3
|
+
|
|
4
|
+
import {JsonHeader} from "../interfaces/JsonOpenSpec.js";
|
|
5
|
+
import {isRedirectionStatus, isSuccessStatus} from "../utils/isSuccessStatus.js";
|
|
6
|
+
import {JsonMap} from "./JsonMap.js";
|
|
7
|
+
import {JsonParameter} from "./JsonParameter.js";
|
|
8
|
+
import {JsonResponse} from "./JsonResponse.js";
|
|
9
|
+
import {JsonSchema} from "./JsonSchema.js";
|
|
10
|
+
|
|
11
|
+
export interface JsonMethodPath {
|
|
12
|
+
path: string | RegExp;
|
|
13
|
+
method: string;
|
|
14
|
+
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface JsonOperationOptions extends OS3Operation<JsonSchema, JsonParameter, JsonMap<JsonResponse>> {
|
|
19
|
+
consumes: string[];
|
|
20
|
+
produces: string[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class JsonOperation extends JsonMap<JsonOperationOptions> {
|
|
24
|
+
$kind: string = "operation";
|
|
25
|
+
|
|
26
|
+
readonly operationPaths: Map<string, JsonMethodPath> = new Map();
|
|
27
|
+
#status: number;
|
|
28
|
+
#redirection: boolean = false;
|
|
29
|
+
|
|
30
|
+
constructor(obj: Partial<JsonOperationOptions> = {}) {
|
|
31
|
+
super({parameters: [], responses: new JsonMap(), ...obj});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get response(): JsonResponse | undefined {
|
|
35
|
+
return this.getResponses().get(this.getStatus().toString());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get status() {
|
|
39
|
+
return this.#status;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
tags(tags: OpenSpecTag[]): this {
|
|
43
|
+
super.set("tags", tags);
|
|
44
|
+
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
addTags(tags: OpenSpecTag[]) {
|
|
49
|
+
tags = uniqBy([...(this.get("tags") || []), ...tags], "name");
|
|
50
|
+
|
|
51
|
+
return this.tags(tags);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
summary(summary: string): this {
|
|
55
|
+
super.set("summary", summary);
|
|
56
|
+
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
operationId(operationId: string): this {
|
|
61
|
+
this.set("operationId", operationId);
|
|
62
|
+
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
responses(responses: JsonMap<any>): this {
|
|
67
|
+
this.set("responses", responses);
|
|
68
|
+
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
defaultStatus(status: number) {
|
|
73
|
+
this.#status = status;
|
|
74
|
+
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getStatus() {
|
|
79
|
+
return this.#status || 200;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
setRedirection(status = 302) {
|
|
83
|
+
this.#redirection = true;
|
|
84
|
+
this.#status = status;
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
isRedirection(status?: number) {
|
|
89
|
+
if (this.#redirection) {
|
|
90
|
+
if (status) {
|
|
91
|
+
return isRedirectionStatus(status);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return this.#redirection;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
addResponse(statusCode: string | number, response: JsonResponse) {
|
|
99
|
+
if ((isSuccessStatus(statusCode) || isRedirectionStatus(statusCode)) && !this.#status) {
|
|
100
|
+
const res = this.getResponseOf(200);
|
|
101
|
+
|
|
102
|
+
this.getResponses().set(statusCode.toString(), res).delete("200");
|
|
103
|
+
|
|
104
|
+
this.defaultStatus(Number(statusCode));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const currentCode = statusCode === "default" ? this.getStatus().toString() : statusCode.toString();
|
|
108
|
+
const currentResponse = this.getResponses().get(currentCode);
|
|
109
|
+
|
|
110
|
+
if (!currentResponse) {
|
|
111
|
+
response.status = Number(currentCode);
|
|
112
|
+
this.getResponses().set(currentCode, response);
|
|
113
|
+
} else {
|
|
114
|
+
response.forEach((value, key) => {
|
|
115
|
+
if (!["content"].includes(key)) {
|
|
116
|
+
currentResponse.set(key, deepMerge(currentResponse.get(key), value));
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
currentResponse.status = Number(currentCode);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
getResponses() {
|
|
126
|
+
return this.get("responses") as JsonMap<JsonResponse>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
getResponseOf(status: number | string): JsonResponse {
|
|
130
|
+
return (status === "default" ? this.response : this.getResponses().get(String(status))) || new JsonResponse();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
ensureResponseOf(status: number | string): JsonResponse {
|
|
134
|
+
this.addResponse(status, this.getResponseOf(status));
|
|
135
|
+
return this.getResponseOf(status);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
getHeadersOf(status: number): Record<string, JsonHeader & {example: string}> {
|
|
139
|
+
return this.getResponseOf(status).get("headers") || {};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
getContentTypeOf(status: number): any {
|
|
143
|
+
return [...this.getResponseOf(status).get("content").keys()].slice(-1)[0];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
security(security: OpenSpecSecurity): this {
|
|
147
|
+
this.set("security", security);
|
|
148
|
+
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
addSecurityScopes(name: string, scopes: string[]) {
|
|
153
|
+
const security = this.get("security") || {};
|
|
154
|
+
security[name] = uniq([...(security[name] || []), ...scopes]);
|
|
155
|
+
|
|
156
|
+
return this.security(security);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
description(description: string): this {
|
|
160
|
+
super.set("description", description);
|
|
161
|
+
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
deprecated(deprecated: boolean): this {
|
|
166
|
+
super.set("deprecated", deprecated);
|
|
167
|
+
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
parameters(parameters: JsonParameter[]): this {
|
|
172
|
+
super.set("parameters", parameters);
|
|
173
|
+
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
addParameter(index: number, parameter: JsonParameter) {
|
|
178
|
+
if (index === -1) {
|
|
179
|
+
index = this.get("parameters").length;
|
|
180
|
+
}
|
|
181
|
+
this.get("parameters")[index] = parameter;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
consumes(consumes: string[]): this {
|
|
185
|
+
super.set("consumes", consumes);
|
|
186
|
+
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
produces(produces: string[]): this {
|
|
191
|
+
super.set("produces", produces);
|
|
192
|
+
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
addProduce(produce: string) {
|
|
197
|
+
const produces = uniq([].concat(this.get("produces"), produce as never)).filter(Boolean);
|
|
198
|
+
|
|
199
|
+
this.set("produces", produces);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
addOperationPath(method: string, path: string | RegExp, options: any = {}) {
|
|
203
|
+
this.operationPaths.set(String(method) + String(path), {
|
|
204
|
+
...options,
|
|
205
|
+
method,
|
|
206
|
+
path
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
getAllowedOperationPath(allowedVerbs?: string[]) {
|
|
213
|
+
if (!allowedVerbs) {
|
|
214
|
+
return [...this.operationPaths.values()];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return [...this.operationPaths.values()].filter(({method}) => method && allowedVerbs.includes(method.toUpperCase()));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {OperationVerbs} from "../constants/OperationVerbs.js";
|
|
2
|
+
import {JsonMethodPath} from "./JsonOperation.js";
|
|
3
|
+
|
|
4
|
+
export class JsonOperationPathsMap extends Map<string, JsonMethodPath> {
|
|
5
|
+
$kind: string = "operationPaths";
|
|
6
|
+
readonly $isJsonDocument = true;
|
|
7
|
+
|
|
8
|
+
setOperationPath(operationPath: JsonMethodPath) {
|
|
9
|
+
// if (operationPath.method !== OperationVerbs.CUSTOM) {
|
|
10
|
+
const key = this.getKey(operationPath.method, operationPath.path);
|
|
11
|
+
this.set(key, operationPath);
|
|
12
|
+
// }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
protected getKey = (method: string, path: any) => `${method}-${path}`;
|
|
16
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {BodyParams} from "@tsed/platform-params";
|
|
2
|
+
|
|
3
|
+
import {Name} from "../decorators/common/name.js";
|
|
4
|
+
import {Get} from "../decorators/operations/route.js";
|
|
5
|
+
import {JsonEntityStore} from "./JsonEntityStore.js";
|
|
6
|
+
import {JsonOperation} from "./JsonOperation.js";
|
|
7
|
+
import {JsonOperationRoute} from "./JsonOperationRoute.js";
|
|
8
|
+
|
|
9
|
+
describe("JsonOperationRoute", () => {
|
|
10
|
+
it("should create JsonOperationRoute instance", () => {
|
|
11
|
+
class Test {
|
|
12
|
+
@Get("/")
|
|
13
|
+
get() {}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const endpoint = JsonEntityStore.fromMethod(Test, "get");
|
|
17
|
+
const operationRoute = new JsonOperationRoute({
|
|
18
|
+
token: Test,
|
|
19
|
+
endpoint,
|
|
20
|
+
operationPath: {method: "GET", path: "/"},
|
|
21
|
+
basePath: "/base"
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
expect(operationRoute.operationPath).toEqual({
|
|
25
|
+
method: "GET",
|
|
26
|
+
path: "/"
|
|
27
|
+
});
|
|
28
|
+
expect(operationRoute.method).toEqual("GET");
|
|
29
|
+
expect(operationRoute.path).toEqual("/");
|
|
30
|
+
expect(operationRoute.fullPath).toEqual("/base");
|
|
31
|
+
expect(operationRoute.url).toEqual("/base");
|
|
32
|
+
expect(operationRoute.name).toEqual("Test.get()");
|
|
33
|
+
expect(operationRoute.className).toEqual("Test");
|
|
34
|
+
expect(operationRoute.methodClassName).toEqual("get");
|
|
35
|
+
expect(operationRoute.propertyKey).toEqual("get");
|
|
36
|
+
expect(operationRoute.propertyName).toEqual("get");
|
|
37
|
+
expect(operationRoute.operation).toBeInstanceOf(JsonOperation);
|
|
38
|
+
expect(operationRoute.operationId).toBe("get");
|
|
39
|
+
expect(operationRoute.parameters).toEqual([]);
|
|
40
|
+
});
|
|
41
|
+
it("should create JsonOperationRoute instance (with alias naming)", () => {
|
|
42
|
+
@Name("Testify")
|
|
43
|
+
class Test {
|
|
44
|
+
@Get("/")
|
|
45
|
+
@Name("getify")
|
|
46
|
+
get() {}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const endpoint = JsonEntityStore.fromMethod(Test, "get");
|
|
50
|
+
const operationRoute = new JsonOperationRoute({
|
|
51
|
+
token: Test,
|
|
52
|
+
endpoint,
|
|
53
|
+
operationPath: {method: "GET", path: "/"},
|
|
54
|
+
basePath: "/base"
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
expect(operationRoute.operationPath).toEqual({
|
|
58
|
+
method: "GET",
|
|
59
|
+
path: "/"
|
|
60
|
+
});
|
|
61
|
+
expect(operationRoute.method).toEqual("GET");
|
|
62
|
+
expect(operationRoute.path).toEqual("/");
|
|
63
|
+
expect(operationRoute.fullPath).toEqual("/base");
|
|
64
|
+
expect(operationRoute.url).toEqual("/base");
|
|
65
|
+
expect(operationRoute.name).toEqual("Test.get()");
|
|
66
|
+
expect(operationRoute.className).toEqual("Test");
|
|
67
|
+
expect(operationRoute.methodClassName).toEqual("get");
|
|
68
|
+
expect(operationRoute.propertyKey).toEqual("get");
|
|
69
|
+
expect(operationRoute.propertyName).toEqual("get");
|
|
70
|
+
expect(operationRoute.operation).toBeInstanceOf(JsonOperation);
|
|
71
|
+
expect(operationRoute.operationId).toBe("get");
|
|
72
|
+
});
|
|
73
|
+
it("should create operation with parameter", () => {
|
|
74
|
+
@Name("Testify")
|
|
75
|
+
class Test {
|
|
76
|
+
@Get("/")
|
|
77
|
+
@Name("getify")
|
|
78
|
+
get(@BodyParams() body: string) {}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const endpoint = JsonEntityStore.fromMethod(Test, "get");
|
|
82
|
+
const operationRoute = new JsonOperationRoute({
|
|
83
|
+
token: Test,
|
|
84
|
+
endpoint,
|
|
85
|
+
operationPath: {method: "GET", path: "/"},
|
|
86
|
+
basePath: "/base"
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
expect(operationRoute.operationPath).toEqual({
|
|
90
|
+
method: "GET",
|
|
91
|
+
path: "/"
|
|
92
|
+
});
|
|
93
|
+
expect(operationRoute.method).toEqual("GET");
|
|
94
|
+
expect(operationRoute.path).toEqual("/");
|
|
95
|
+
expect(operationRoute.fullPath).toEqual("/base");
|
|
96
|
+
expect(operationRoute.url).toEqual("/base");
|
|
97
|
+
expect(operationRoute.name).toEqual("Test.get()");
|
|
98
|
+
expect(operationRoute.className).toEqual("Test");
|
|
99
|
+
expect(operationRoute.methodClassName).toEqual("get");
|
|
100
|
+
expect(operationRoute.propertyKey).toEqual("get");
|
|
101
|
+
expect(operationRoute.propertyName).toEqual("get");
|
|
102
|
+
expect(operationRoute.operation).toBeInstanceOf(JsonOperation);
|
|
103
|
+
expect(operationRoute.operationId).toBe("get");
|
|
104
|
+
expect(operationRoute.paramsTypes).toEqual({
|
|
105
|
+
BODY: true
|
|
106
|
+
});
|
|
107
|
+
expect(operationRoute.has("BODY")).toEqual(true);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {Type} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {concatPath} from "../utils/concatPath.js";
|
|
4
|
+
import {JsonMethodStore} from "./JsonMethodStore.js";
|
|
5
|
+
import {JsonMethodPath, JsonOperation} from "./JsonOperation.js";
|
|
6
|
+
|
|
7
|
+
export class JsonOperationRoute<Entity extends JsonMethodStore = JsonMethodStore> {
|
|
8
|
+
readonly token: Type<any>;
|
|
9
|
+
readonly endpoint: Entity;
|
|
10
|
+
readonly operationPath?: JsonMethodPath;
|
|
11
|
+
readonly basePath?: string;
|
|
12
|
+
readonly paramsTypes: Record<string, boolean>;
|
|
13
|
+
|
|
14
|
+
constructor(options: Partial<JsonOperationRoute>) {
|
|
15
|
+
Object.assign(this, options);
|
|
16
|
+
|
|
17
|
+
this.paramsTypes = this.endpoint.getParamTypes();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get url() {
|
|
21
|
+
return this.fullPath;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get path() {
|
|
25
|
+
return this.operationPath?.path;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get fullPath() {
|
|
29
|
+
return concatPath(this.basePath, this.path as any);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get method() {
|
|
33
|
+
return this.operationPath?.method || "USE";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get name() {
|
|
37
|
+
return `${this.endpoint.targetName}.${this.methodClassName}()`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get className() {
|
|
41
|
+
return this.endpoint.targetName;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get methodClassName() {
|
|
45
|
+
return this.propertyKey;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get parameters() {
|
|
49
|
+
return this.endpoint.parameters;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get propertyKey() {
|
|
53
|
+
return String(this.endpoint.propertyKey);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get propertyName() {
|
|
57
|
+
return this.endpoint.propertyName;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get store() {
|
|
61
|
+
return this.endpoint.store;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get operation(): JsonOperation {
|
|
65
|
+
return this.endpoint.operation as JsonOperation;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get operationId() {
|
|
69
|
+
return this.operation.get("operationId") || this.endpoint.propertyKey;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
has(key: string) {
|
|
73
|
+
return this.paramsTypes[key];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {Type} from "@tsed/core";
|
|
2
|
+
import {OpenSpecHash, OpenSpecRef, OS3Example, OS3Parameter} from "@tsed/openspec";
|
|
3
|
+
|
|
4
|
+
import {JsonSchemaOptions} from "../interfaces/JsonSchemaOptions.js";
|
|
5
|
+
import {execMapper} from "../registries/JsonSchemaMapperContainer.js";
|
|
6
|
+
import {NestedGenerics} from "../utils/generics.js";
|
|
7
|
+
import {JsonMap} from "./JsonMap.js";
|
|
8
|
+
import {formatParameterType} from "./JsonParameterTypes.js";
|
|
9
|
+
import {JsonSchema} from "./JsonSchema.js";
|
|
10
|
+
|
|
11
|
+
export class JsonParameter extends JsonMap<OS3Parameter<JsonSchema>> implements NestedGenerics {
|
|
12
|
+
$kind = "operationInParameter";
|
|
13
|
+
|
|
14
|
+
nestedGenerics: Type<any>[][] = [];
|
|
15
|
+
groups: string[];
|
|
16
|
+
groupsName: string;
|
|
17
|
+
$schema: JsonSchema;
|
|
18
|
+
expression: string;
|
|
19
|
+
|
|
20
|
+
getName() {
|
|
21
|
+
const name = this.get("name");
|
|
22
|
+
|
|
23
|
+
if (this.get("in") === "files") {
|
|
24
|
+
return name.split(".")[0];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return name;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
name(name: string): this {
|
|
31
|
+
this.set("name", name);
|
|
32
|
+
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
examples(examples: OpenSpecHash<OS3Example | OpenSpecRef>) {
|
|
37
|
+
super.set("examples", examples);
|
|
38
|
+
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
description(description: string): this {
|
|
43
|
+
this.set("description", description);
|
|
44
|
+
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
in(inType: string, expression: string | any = ""): this {
|
|
49
|
+
this.set("in", formatParameterType(inType));
|
|
50
|
+
this.expression = expression;
|
|
51
|
+
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
required(required: boolean): this {
|
|
56
|
+
this.set("required", required);
|
|
57
|
+
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
schema(schema: JsonSchema): this {
|
|
62
|
+
this.$schema = schema;
|
|
63
|
+
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
toJSON(options?: JsonSchemaOptions) {
|
|
68
|
+
return execMapper("operationInParameter", [this], options);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import {prototypeOf, Store} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {Allow} from "../decorators/common/allow.js";
|
|
4
|
+
import {Required} from "../decorators/common/required.js";
|
|
5
|
+
import {In} from "../decorators/operations/in.js";
|
|
6
|
+
import {Path} from "../decorators/operations/path.js";
|
|
7
|
+
import {Get} from "../decorators/operations/route.js";
|
|
8
|
+
import {getJsonEntityStore} from "../utils/getJsonEntityStore.js";
|
|
9
|
+
import {JsonClassStore} from "./JsonClassStore.js";
|
|
10
|
+
import {JsonMethodStore} from "./JsonMethodStore.js";
|
|
11
|
+
import {JsonParameterStore} from "./JsonParameterStore.js";
|
|
12
|
+
import {JsonParameterTypes} from "./JsonParameterTypes.js";
|
|
13
|
+
|
|
14
|
+
describe("JsonParameterStore", () => {
|
|
15
|
+
describe("new JsonParameterStore", () => {
|
|
16
|
+
it("should load entities", () => {
|
|
17
|
+
class TestDynamicUrlCtrl {
|
|
18
|
+
async get(id: string) {}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const entity = getJsonEntityStore(prototypeOf(TestDynamicUrlCtrl), "get", 0);
|
|
22
|
+
|
|
23
|
+
expect(entity).toBeInstanceOf(JsonParameterStore);
|
|
24
|
+
expect(entity.parent).toBeInstanceOf(JsonMethodStore);
|
|
25
|
+
expect(entity.parent.parent).toBeInstanceOf(JsonClassStore);
|
|
26
|
+
expect(entity.parent.parent.parent).toBeInstanceOf(JsonClassStore);
|
|
27
|
+
expect(entity.nestedGenerics).toEqual([]);
|
|
28
|
+
expect(entity.required).toBe(false);
|
|
29
|
+
expect(entity.isRequired("")).toBe(false);
|
|
30
|
+
expect(entity.allowedRequiredValues).toEqual([]);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe("getParams()", () => {
|
|
34
|
+
it("should returns params (body + path)", () => {
|
|
35
|
+
// GIVEN
|
|
36
|
+
@Path("/")
|
|
37
|
+
class Test {
|
|
38
|
+
@Get("/")
|
|
39
|
+
test(@In("body") body: any) {}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// WHEN
|
|
43
|
+
const result = JsonParameterStore.getParams(prototypeOf(Test), "test");
|
|
44
|
+
|
|
45
|
+
// THEN
|
|
46
|
+
expect(result[0].parameter.get("in")).toEqual("body");
|
|
47
|
+
});
|
|
48
|
+
it("should returns params (body)", () => {
|
|
49
|
+
// GIVEN
|
|
50
|
+
class Test {
|
|
51
|
+
@Get("/")
|
|
52
|
+
test(@In(JsonParameterTypes.BODY) body: any) {}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// WHEN
|
|
56
|
+
const result = JsonParameterStore.getParams(prototypeOf(Test), "test");
|
|
57
|
+
// THEN
|
|
58
|
+
|
|
59
|
+
expect(result[0].parameter.get("in")).toEqual("body");
|
|
60
|
+
});
|
|
61
|
+
it("should returns params from inherited", () => {
|
|
62
|
+
// GIVEN
|
|
63
|
+
class BaseTest {
|
|
64
|
+
@Get("/")
|
|
65
|
+
list(@(In("query").Name("search")) search: string) {}
|
|
66
|
+
|
|
67
|
+
@Get("/")
|
|
68
|
+
base(@(In("query").Name("base")) test: string) {}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
class Test extends BaseTest {
|
|
72
|
+
@Get("/")
|
|
73
|
+
test(@(In("query").Name("search")) search: string) {}
|
|
74
|
+
|
|
75
|
+
@Get("/")
|
|
76
|
+
base(@(In("query").Name("test")) search: string) {}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// WHEN
|
|
80
|
+
const result1 = JsonParameterStore.getParams(prototypeOf(Test), "list");
|
|
81
|
+
const result2 = JsonParameterStore.getParams(prototypeOf(Test), "test");
|
|
82
|
+
const result3 = JsonParameterStore.getParams(prototypeOf(Test), "unknown");
|
|
83
|
+
const result4 = JsonParameterStore.getParams(prototypeOf(Test), "base");
|
|
84
|
+
|
|
85
|
+
// THEN
|
|
86
|
+
expect(result1.length).toEqual(1);
|
|
87
|
+
expect(result2.length).toEqual(1);
|
|
88
|
+
expect(result3).toEqual([]);
|
|
89
|
+
expect(result4.length).toEqual(1);
|
|
90
|
+
expect(result4[0].token).toBe(Test);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe("isRequired", () => {
|
|
94
|
+
describe("when property is required", () => {
|
|
95
|
+
it("should return the expected required state", () => {
|
|
96
|
+
class Test {
|
|
97
|
+
@Get("/")
|
|
98
|
+
test(@Required() @In(JsonParameterTypes.BODY) body: any) {}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const store = JsonParameterStore.get(Test, "test", 0);
|
|
102
|
+
|
|
103
|
+
expect(store.isRequired(0)).toEqual(false);
|
|
104
|
+
expect(store.isRequired("")).toEqual(true);
|
|
105
|
+
expect(store.isRequired(null)).toEqual(true);
|
|
106
|
+
expect(store.isRequired(undefined)).toEqual(true);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe("when property is required and have allowed values", () => {
|
|
111
|
+
it("should validate the required values", () => {
|
|
112
|
+
class Test {
|
|
113
|
+
@Get("/")
|
|
114
|
+
test(@Required() @Allow(null) @In(JsonParameterTypes.BODY) body: any) {}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const store = JsonParameterStore.get(Test, "test", 0);
|
|
118
|
+
|
|
119
|
+
expect(store.allowedRequiredValues).toEqual([null]);
|
|
120
|
+
expect(store.isRequired(0)).toEqual(false);
|
|
121
|
+
expect(store.isRequired("")).toEqual(true);
|
|
122
|
+
expect(store.isRequired(null)).toEqual(false);
|
|
123
|
+
expect(store.isRequired(undefined)).toEqual(true);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("should validate the required values (2)", () => {
|
|
127
|
+
class Test {
|
|
128
|
+
@Get("/")
|
|
129
|
+
test(@Required() @Allow("") @In(JsonParameterTypes.BODY) body: any) {}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const store = JsonParameterStore.get(Test, "test", 0);
|
|
133
|
+
store.required = true;
|
|
134
|
+
|
|
135
|
+
expect(store.allowedRequiredValues).toEqual([""]);
|
|
136
|
+
expect(store.isRequired(0)).toEqual(false);
|
|
137
|
+
expect(store.isRequired("")).toEqual(false);
|
|
138
|
+
expect(store.isRequired(null)).toEqual(true);
|
|
139
|
+
expect(store.isRequired(undefined)).toEqual(true);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("should validate the required values (3)", () => {
|
|
143
|
+
class Test {
|
|
144
|
+
@Get("/")
|
|
145
|
+
test(@Required() @Allow("") @In(JsonParameterTypes.BODY) body: any) {}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const store = JsonParameterStore.get(Test, "test", 0);
|
|
149
|
+
store.required = true;
|
|
150
|
+
|
|
151
|
+
expect(store.allowedRequiredValues).toEqual([""]);
|
|
152
|
+
expect(store.isRequired(0)).toEqual(false);
|
|
153
|
+
expect(store.isRequired("")).toEqual(false);
|
|
154
|
+
expect(store.isRequired(null)).toEqual(true);
|
|
155
|
+
expect(store.isRequired(undefined)).toEqual(true);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe("when property is not required", () => {
|
|
160
|
+
it("should validate values", () => {
|
|
161
|
+
class Test {
|
|
162
|
+
@Get("/")
|
|
163
|
+
test(@Required(false) @Allow("") @In(JsonParameterTypes.BODY) body: any) {}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const store = JsonParameterStore.get(Test, "test", 0);
|
|
167
|
+
store.required = false;
|
|
168
|
+
|
|
169
|
+
expect(store.isRequired(0)).toEqual(false);
|
|
170
|
+
expect(store.isRequired("")).toEqual(false);
|
|
171
|
+
expect(store.isRequired(null)).toEqual(false);
|
|
172
|
+
expect(store.isRequired(undefined)).toEqual(false);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
describe("props", () => {
|
|
177
|
+
it("should return the required value", () => {
|
|
178
|
+
class Test {
|
|
179
|
+
method(arg1: any, arg2: any) {}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const paramMetadata = JsonParameterStore.get(Test, "method", 0);
|
|
183
|
+
paramMetadata.required = true;
|
|
184
|
+
paramMetadata.expression = "test";
|
|
185
|
+
paramMetadata.type = Test;
|
|
186
|
+
|
|
187
|
+
expect(paramMetadata.required).toEqual(true);
|
|
188
|
+
|
|
189
|
+
expect(paramMetadata.expression).toEqual("test");
|
|
190
|
+
|
|
191
|
+
expect(paramMetadata.collectionType).toEqual(undefined);
|
|
192
|
+
expect(paramMetadata.type).toEqual(Test);
|
|
193
|
+
expect(paramMetadata.index).toEqual(0);
|
|
194
|
+
expect(paramMetadata.store).toBeInstanceOf(Store);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
describe("as a service", () => {
|
|
198
|
+
it("should return the service", () => {
|
|
199
|
+
class Test {
|
|
200
|
+
method(arg1: any, arg2: any) {}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const paramMetadata = JsonParameterStore.get(Test, "method", 0);
|
|
204
|
+
paramMetadata.required = true;
|
|
205
|
+
paramMetadata.expression = "test";
|
|
206
|
+
paramMetadata.type = Test;
|
|
207
|
+
paramMetadata.paramType = "ERR";
|
|
208
|
+
|
|
209
|
+
expect(paramMetadata.paramType).toEqual("ERR");
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
});
|