@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
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/schema",
|
|
3
3
|
"description": "JsonSchema module for Ts.ED Framework",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.0.
|
|
5
|
+
"version": "8.0.2",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"browser": "./lib/browser/schema.umd.min.js",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
+
"@tsed/source": "./src/index.ts",
|
|
13
14
|
"types": "./lib/types/index.d.ts",
|
|
14
15
|
"browser": "./lib/browser/schema.umd.min.js",
|
|
15
16
|
"import": "./lib/esm/index.js",
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
"tsed"
|
|
37
38
|
],
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@tsed/openspec": "8.0.
|
|
40
|
+
"@tsed/openspec": "8.0.2",
|
|
40
41
|
"change-case": "^5.4.4",
|
|
41
42
|
"fs-extra": "^11.2.0",
|
|
42
43
|
"json-schema": "0.4.0",
|
|
@@ -46,11 +47,11 @@
|
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@apidevtools/swagger-parser": "10.1.0",
|
|
49
|
-
"@tsed/barrels": "8.0.
|
|
50
|
-
"@tsed/core": "8.0.
|
|
51
|
-
"@tsed/hooks": "8.0.
|
|
52
|
-
"@tsed/openspec": "8.0.
|
|
53
|
-
"@tsed/typescript": "8.0.
|
|
50
|
+
"@tsed/barrels": "8.0.2",
|
|
51
|
+
"@tsed/core": "8.0.2",
|
|
52
|
+
"@tsed/hooks": "8.0.2",
|
|
53
|
+
"@tsed/openspec": "8.0.2",
|
|
54
|
+
"@tsed/typescript": "8.0.2",
|
|
54
55
|
"@types/fs-extra": "11.0.4",
|
|
55
56
|
"@types/json-schema": "7.0.15",
|
|
56
57
|
"@types/picomatch": "3.0.1",
|
|
@@ -63,9 +64,9 @@
|
|
|
63
64
|
"webpack": "^5.75.0"
|
|
64
65
|
},
|
|
65
66
|
"peerDependencies": {
|
|
66
|
-
"@tsed/core": "8.0.
|
|
67
|
-
"@tsed/hooks": "8.0.
|
|
68
|
-
"@tsed/openspec": "8.0.
|
|
67
|
+
"@tsed/core": "8.0.2",
|
|
68
|
+
"@tsed/hooks": "8.0.2",
|
|
69
|
+
"@tsed/openspec": "8.0.2"
|
|
69
70
|
},
|
|
70
71
|
"peerDependenciesMeta": {
|
|
71
72
|
"@tsed/core": {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {camelCase} from "change-case";
|
|
2
|
+
|
|
3
|
+
import {OperationVerbs} from "../../constants/OperationVerbs.js";
|
|
4
|
+
import {JsonMethodStore} from "../../domain/JsonMethodStore.js";
|
|
5
|
+
import {JsonMethodPath} from "../../domain/JsonOperation.js";
|
|
6
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
7
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
8
|
+
import {buildPath} from "../../utils/buildPath.js";
|
|
9
|
+
import {getJsonEntityStore} from "../../utils/getJsonEntityStore.js";
|
|
10
|
+
import {getOperationsStores} from "../../utils/getOperationsStores.js";
|
|
11
|
+
import {removeHiddenOperation} from "../../utils/removeHiddenOperation.js";
|
|
12
|
+
|
|
13
|
+
const ALLOWED_VERBS = [OperationVerbs.PUBLISH, OperationVerbs.SUBSCRIBE];
|
|
14
|
+
|
|
15
|
+
function pushToChannels(options: JsonSchemaOptions) {
|
|
16
|
+
return (
|
|
17
|
+
channels: any,
|
|
18
|
+
{
|
|
19
|
+
operationPath,
|
|
20
|
+
operationStore
|
|
21
|
+
}: {
|
|
22
|
+
operationPath: JsonMethodPath;
|
|
23
|
+
operationStore: JsonMethodStore;
|
|
24
|
+
}
|
|
25
|
+
) => {
|
|
26
|
+
const path = options.ctrlRootPath || "/";
|
|
27
|
+
const method = operationPath.method.toLowerCase();
|
|
28
|
+
const operationId = camelCase(`${method.toLowerCase()} ${operationStore.parent.schema.getName()}`);
|
|
29
|
+
|
|
30
|
+
const message = execMapper("message", [operationStore, operationPath], options);
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
...channels,
|
|
34
|
+
[path]: {
|
|
35
|
+
...(channels as any)[path],
|
|
36
|
+
[method]: {
|
|
37
|
+
...(channels as any)[path]?.[method],
|
|
38
|
+
operationId,
|
|
39
|
+
message: {
|
|
40
|
+
oneOf: [...((channels as any)[path]?.[method]?.message?.oneOf || []), message]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function expandOperationPaths(options: JsonSchemaOptions) {
|
|
49
|
+
return (operationStore: JsonMethodStore) => {
|
|
50
|
+
const operationPaths = operationStore.operation.getAllowedOperationPath(ALLOWED_VERBS);
|
|
51
|
+
|
|
52
|
+
if (operationPaths.length === 0) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return operationPaths.map((operationPath) => {
|
|
57
|
+
return {
|
|
58
|
+
operationPath,
|
|
59
|
+
operationStore
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function channelsMapper(model: any, {channels, rootPath, ...options}: JsonSchemaOptions) {
|
|
66
|
+
const store = getJsonEntityStore(model);
|
|
67
|
+
const ctrlPath = store.path;
|
|
68
|
+
const ctrlRootPath = buildPath(rootPath + ctrlPath);
|
|
69
|
+
|
|
70
|
+
options = {
|
|
71
|
+
...options,
|
|
72
|
+
ctrlRootPath
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return [...getOperationsStores(model).values()]
|
|
76
|
+
.filter(removeHiddenOperation)
|
|
77
|
+
.flatMap(expandOperationPaths(options))
|
|
78
|
+
.reduce(pushToChannels(options), channels);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
registerJsonSchemaMapper("channels", channelsMapper);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {getValue, Type, uniqBy} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {SpecTypes} from "../../domain/SpecTypes.js";
|
|
4
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
5
|
+
import {SpecSerializerOptions} from "../../utils/getSpec.js";
|
|
6
|
+
|
|
7
|
+
function generate(model: Type<any>, options: SpecSerializerOptions) {
|
|
8
|
+
const specJson: any = {
|
|
9
|
+
channels: execMapper("channels", [model], options)
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
specJson.tags = uniqBy(options.tags, "name");
|
|
13
|
+
|
|
14
|
+
if (options.components?.schemas && Object.keys(options.components.schemas).length) {
|
|
15
|
+
specJson.components = {
|
|
16
|
+
...options.components,
|
|
17
|
+
schemas: options.components.schemas
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return specJson;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
registerJsonSchemaMapper("generate", generate, SpecTypes.ASYNCAPI);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {cleanObject, getValue} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {OperationVerbs} from "../../constants/OperationVerbs.js";
|
|
4
|
+
import {JsonMethodStore} from "../../domain/JsonMethodStore.js";
|
|
5
|
+
import {JsonMethodPath} from "../../domain/JsonOperation.js";
|
|
6
|
+
import {SpecTypes} from "../../domain/SpecTypes.js";
|
|
7
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
8
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
9
|
+
import {makeOf} from "../../utils/somethingOf.js";
|
|
10
|
+
|
|
11
|
+
export function messageMapper(
|
|
12
|
+
jsonOperationStore: JsonMethodStore,
|
|
13
|
+
operationPath: JsonMethodPath,
|
|
14
|
+
{tags = [], defaultTags = [], ...options}: JsonSchemaOptions = {}
|
|
15
|
+
) {
|
|
16
|
+
const {path: event, method} = operationPath;
|
|
17
|
+
|
|
18
|
+
const messageKey = String(event);
|
|
19
|
+
|
|
20
|
+
let message: any = getValue(
|
|
21
|
+
options.components,
|
|
22
|
+
"messages." + event,
|
|
23
|
+
cleanObject({
|
|
24
|
+
description: jsonOperationStore.operation.get("description"),
|
|
25
|
+
summary: jsonOperationStore.operation.get("summary")
|
|
26
|
+
})
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
if (method.toUpperCase() === OperationVerbs.PUBLISH) {
|
|
30
|
+
const payload = execMapper("payload", [jsonOperationStore, operationPath], options);
|
|
31
|
+
|
|
32
|
+
if (payload) {
|
|
33
|
+
message.payload = payload;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const responses = jsonOperationStore.operation
|
|
37
|
+
.getAllowedOperationPath([OperationVerbs.SUBSCRIBE])
|
|
38
|
+
.map((operationPath) => {
|
|
39
|
+
return execMapper("message", [jsonOperationStore, operationPath], options);
|
|
40
|
+
})
|
|
41
|
+
.filter(Boolean);
|
|
42
|
+
|
|
43
|
+
const responsesSchema = makeOf("oneOf", responses);
|
|
44
|
+
|
|
45
|
+
if (responsesSchema) {
|
|
46
|
+
message["x-response"] = responsesSchema;
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
const response = execMapper("response", [jsonOperationStore, operationPath], options);
|
|
50
|
+
|
|
51
|
+
if (response) {
|
|
52
|
+
message["x-response"] = response;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
options.components!.messages = options.components!.messages || {};
|
|
57
|
+
options.components!.messages[messageKey] = message;
|
|
58
|
+
|
|
59
|
+
return {$ref: `#/components/messages/${messageKey}`};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
registerJsonSchemaMapper("message", messageMapper, SpecTypes.ASYNCAPI);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {setValue} from "@tsed/core";
|
|
2
|
+
import {pascalCase} from "change-case";
|
|
3
|
+
|
|
4
|
+
import {JsonMethodStore} from "../../domain/JsonMethodStore.js";
|
|
5
|
+
import {JsonMethodPath, JsonOperation} from "../../domain/JsonOperation.js";
|
|
6
|
+
import {JsonParameter} from "../../domain/JsonParameter.js";
|
|
7
|
+
import {isParameterType, JsonParameterTypes} from "../../domain/JsonParameterTypes.js";
|
|
8
|
+
import {SpecTypes} from "../../domain/SpecTypes.js";
|
|
9
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
10
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
11
|
+
import {popGenerics} from "../../utils/generics.js";
|
|
12
|
+
import {makeOf} from "../../utils/somethingOf.js";
|
|
13
|
+
|
|
14
|
+
function mapOptions(parameter: JsonParameter, options: JsonSchemaOptions = {}) {
|
|
15
|
+
return {
|
|
16
|
+
...options,
|
|
17
|
+
groups: parameter.groups,
|
|
18
|
+
groupsName: parameter.groupsName
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getParameters(jsonOperation: JsonOperation, options: JsonSchemaOptions): JsonParameter[] {
|
|
23
|
+
return jsonOperation.get("parameters").filter((parameter: JsonParameter) => isParameterType(parameter.get("in")));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function payloadMapper(jsonOperationStore: JsonMethodStore, operationPath: JsonMethodPath, options: JsonSchemaOptions) {
|
|
27
|
+
const parameters = getParameters(jsonOperationStore.operation, options);
|
|
28
|
+
const payloadName = pascalCase([operationPath.path, operationPath.method, "Payload"].join(" "));
|
|
29
|
+
|
|
30
|
+
setValue(options, `components.schemas.${payloadName}`, {});
|
|
31
|
+
|
|
32
|
+
const allOf = parameters
|
|
33
|
+
.map((parameter) => {
|
|
34
|
+
const opts = mapOptions(parameter, options);
|
|
35
|
+
const jsonSchema = execMapper("item", [parameter.$schema], {
|
|
36
|
+
...opts,
|
|
37
|
+
...popGenerics(parameter)
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
switch (parameter.get("in")) {
|
|
41
|
+
case JsonParameterTypes.BODY:
|
|
42
|
+
return jsonSchema;
|
|
43
|
+
case JsonParameterTypes.QUERY:
|
|
44
|
+
case JsonParameterTypes.PATH:
|
|
45
|
+
case JsonParameterTypes.HEADER:
|
|
46
|
+
return {
|
|
47
|
+
type: "object",
|
|
48
|
+
properties: {
|
|
49
|
+
[parameter.get("name")]: jsonSchema
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return jsonSchema;
|
|
55
|
+
}, {})
|
|
56
|
+
.filter(Boolean);
|
|
57
|
+
|
|
58
|
+
return makeOf("allOf", allOf);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
registerJsonSchemaMapper("payload", payloadMapper, SpecTypes.ASYNCAPI);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {setValue} from "@tsed/core";
|
|
2
|
+
import {pascalCase} from "change-case";
|
|
3
|
+
|
|
4
|
+
import {JsonMethodStore} from "../../domain/JsonMethodStore.js";
|
|
5
|
+
import {JsonMethodPath} from "../../domain/JsonOperation.js";
|
|
6
|
+
import {SpecTypes} from "../../domain/SpecTypes.js";
|
|
7
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
8
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
9
|
+
import {makeOf} from "../../utils/somethingOf.js";
|
|
10
|
+
|
|
11
|
+
export function responsePayloadMapper(jsonOperationStore: JsonMethodStore, operationPath: JsonMethodPath, options: JsonSchemaOptions) {
|
|
12
|
+
const responses = jsonOperationStore.operation.getResponses();
|
|
13
|
+
const statuses: number[] = [];
|
|
14
|
+
const statusesTexts: string[] = [];
|
|
15
|
+
const successSchemes: unknown[] = [];
|
|
16
|
+
const errorSchemes: unknown[] = [];
|
|
17
|
+
|
|
18
|
+
[...responses.entries()].forEach(([status, jsonResponse]) => {
|
|
19
|
+
const response = execMapper("map", [jsonResponse], options);
|
|
20
|
+
|
|
21
|
+
statuses.push(+status);
|
|
22
|
+
|
|
23
|
+
statusesTexts.push(response.description);
|
|
24
|
+
|
|
25
|
+
if (+status !== 204) {
|
|
26
|
+
const {content} = response;
|
|
27
|
+
const schema = content[Object.keys(content)[0]];
|
|
28
|
+
|
|
29
|
+
if (+status >= 200 && +status < 400) {
|
|
30
|
+
successSchemes.push(schema);
|
|
31
|
+
} else {
|
|
32
|
+
successSchemes.push(schema);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const responsePayloadName = pascalCase([operationPath.path, operationPath.method, "Response"].join(" "));
|
|
38
|
+
const responsePayload = {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
status: {
|
|
42
|
+
type: "number",
|
|
43
|
+
enum: statuses
|
|
44
|
+
},
|
|
45
|
+
statusText: {
|
|
46
|
+
type: "string",
|
|
47
|
+
enum: statusesTexts
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
required: ["status"]
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const dataSchema = makeOf("oneOf", successSchemes);
|
|
54
|
+
|
|
55
|
+
if (dataSchema) {
|
|
56
|
+
setValue(responsePayload, "properties.data", dataSchema);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const errorSchema = makeOf("oneOf", errorSchemes);
|
|
60
|
+
|
|
61
|
+
if (errorSchemes.length) {
|
|
62
|
+
setValue(responsePayload, "properties.error", errorSchema);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
setValue(options, `components.schemas.${responsePayloadName}`, responsePayload);
|
|
66
|
+
|
|
67
|
+
return {$ref: `#/components/schemas/${responsePayloadName}`};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
registerJsonSchemaMapper("response", responsePayloadMapper, SpecTypes.ASYNCAPI);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {JsonLazyRef} from "../../domain/JsonLazyRef.js";
|
|
2
|
+
import {JsonSchema} from "../../domain/JsonSchema.js";
|
|
3
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
4
|
+
import {execMapper, oneOfMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
5
|
+
import {mapGenericsOptions} from "../../utils/generics.js";
|
|
6
|
+
import {toRef} from "../../utils/ref.js";
|
|
7
|
+
|
|
8
|
+
export function anyMapper(input: any, options: JsonSchemaOptions = {}): any {
|
|
9
|
+
if (typeof input !== "object" || input === null) {
|
|
10
|
+
return input;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (input instanceof JsonLazyRef) {
|
|
14
|
+
return execMapper("lazyRef", [input], options);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (input instanceof JsonSchema && input.get("enum") instanceof JsonSchema) {
|
|
18
|
+
const enumSchema: JsonSchema = input.get("enum");
|
|
19
|
+
|
|
20
|
+
return toRef(enumSchema, enumSchema.toJSON(options), options);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (input.$kind && input.$isJsonDocument) {
|
|
24
|
+
const kind = oneOfMapper([input.$kind, "map"], options);
|
|
25
|
+
const schema = execMapper(kind, [input], mapGenericsOptions(options));
|
|
26
|
+
|
|
27
|
+
return input.canRef ? toRef(input, schema, options) : schema;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return execMapper("object", [input], options);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
registerJsonSchemaMapper("any", anyMapper);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {getValue, setValue} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {JsonEntityStore} from "../../domain/JsonEntityStore.js";
|
|
4
|
+
import {JsonSchema} from "../../domain/JsonSchema.js";
|
|
5
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
6
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
7
|
+
import {mapGenericsOptions, popGenerics} from "../../utils/generics.js";
|
|
8
|
+
import {createRef, createRefName} from "../../utils/ref.js";
|
|
9
|
+
|
|
10
|
+
export function classMapper(value: JsonSchema, options: JsonSchemaOptions) {
|
|
11
|
+
const store = JsonEntityStore.from(value.class);
|
|
12
|
+
const name = createRefName(store.schema.getName() || value.getName(), options);
|
|
13
|
+
|
|
14
|
+
if (value.hasGenerics) {
|
|
15
|
+
// Inline generic
|
|
16
|
+
const {type, properties, additionalProperties, items, ...props} = value.toJSON(options);
|
|
17
|
+
const schema = {
|
|
18
|
+
...execMapper("any", [store.schema], {
|
|
19
|
+
...options,
|
|
20
|
+
...popGenerics(value),
|
|
21
|
+
root: false
|
|
22
|
+
}),
|
|
23
|
+
...props
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
if (schema.title) {
|
|
27
|
+
const name = createRefName(schema.title, options);
|
|
28
|
+
setValue(options.components, `schemas.${name}`, schema);
|
|
29
|
+
|
|
30
|
+
delete schema.title;
|
|
31
|
+
|
|
32
|
+
return createRef(name, value, options);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return schema;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!getValue(options, `components.schemas.${name}`)) {
|
|
39
|
+
// avoid infinite calls
|
|
40
|
+
setValue(options, `components.schemas.${name}`, {});
|
|
41
|
+
|
|
42
|
+
options.components!.schemas[name] = execMapper(
|
|
43
|
+
"any",
|
|
44
|
+
[store.schema],
|
|
45
|
+
mapGenericsOptions({
|
|
46
|
+
...options,
|
|
47
|
+
root: false
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return createRef(name, value, options);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
registerJsonSchemaMapper("class", classMapper);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {isString} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {JsonSchema} from "../../domain/JsonSchema.js";
|
|
4
|
+
import {SpecTypes} from "../../domain/SpecTypes.js";
|
|
5
|
+
import type {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
6
|
+
import {registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
7
|
+
import {toRef} from "../../utils/ref.js";
|
|
8
|
+
|
|
9
|
+
interface SchemaWithDiscriminator {
|
|
10
|
+
discriminator?: {mapping?: Record<string, JsonSchema | string>};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function discriminatorMappingMapper(obj: SchemaWithDiscriminator, _: JsonSchema, options: JsonSchemaOptions) {
|
|
14
|
+
if (obj.discriminator?.mapping) {
|
|
15
|
+
const entries = Object.entries(obj.discriminator.mapping);
|
|
16
|
+
const newMapping: Record<string, string> = {};
|
|
17
|
+
|
|
18
|
+
for (const [key, value] of entries) {
|
|
19
|
+
newMapping[key] = isString(value) ? value : toRef(value, null, options).$ref;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
obj.discriminator.mapping = newMapping;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function defaultDiscriminatorMappingMapper(obj: SchemaWithDiscriminator) {
|
|
29
|
+
if (obj.discriminator?.mapping) {
|
|
30
|
+
delete obj.discriminator.mapping;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return obj;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
registerJsonSchemaMapper("discriminatorMapping", defaultDiscriminatorMappingMapper);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {enumsMapper} from "./enumsMapper.js";
|
|
2
|
+
|
|
3
|
+
describe("enumsMapper()", () => {
|
|
4
|
+
it("should inline enums", () => {
|
|
5
|
+
const result = enumsMapper(
|
|
6
|
+
{
|
|
7
|
+
enum: {
|
|
8
|
+
$isJsonDocument: true,
|
|
9
|
+
toJSON() {
|
|
10
|
+
return {enum: ["type"]};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
{} as any,
|
|
15
|
+
{inlineEnums: true}
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
expect(result).toEqual({
|
|
19
|
+
enum: ["type"],
|
|
20
|
+
type: "string"
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should inline enums and set type (object to string)", () => {
|
|
25
|
+
const result = enumsMapper(
|
|
26
|
+
{
|
|
27
|
+
type: "object",
|
|
28
|
+
enum: {
|
|
29
|
+
$isJsonDocument: true,
|
|
30
|
+
toJSON() {
|
|
31
|
+
return {enum: ["type"]};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{} as any,
|
|
36
|
+
{inlineEnums: true}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect(result).toEqual({
|
|
40
|
+
type: "string",
|
|
41
|
+
enum: ["type"]
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
it("should inline enums and keep the type", () => {
|
|
45
|
+
const result = enumsMapper(
|
|
46
|
+
{
|
|
47
|
+
type: "string",
|
|
48
|
+
enum: {
|
|
49
|
+
$isJsonDocument: true,
|
|
50
|
+
toJSON() {
|
|
51
|
+
return {enum: ["type"]};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{} as any,
|
|
56
|
+
{inlineEnums: true}
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(result).toEqual({
|
|
60
|
+
type: "string",
|
|
61
|
+
enum: ["type"]
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {JsonSchema} from "../../domain/JsonSchema.js";
|
|
2
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
3
|
+
import {registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
4
|
+
|
|
5
|
+
export function enumsMapper(obj: any, schema: JsonSchema, options: JsonSchemaOptions) {
|
|
6
|
+
if (options.inlineEnums && obj.enum?.$isJsonDocument) {
|
|
7
|
+
obj.enum = obj.enum.toJSON().enum;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (obj.enum) {
|
|
11
|
+
obj.type = obj.type === "object" || obj.type === undefined ? "string" : obj.type;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return obj;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
registerJsonSchemaMapper("enums", enumsMapper);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {isClass, isPrimitiveClass} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {JsonEntityStore} from "../../domain/JsonEntityStore.js";
|
|
4
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
5
|
+
import {GenericsContext, popGenerics} from "../../utils/generics.js";
|
|
6
|
+
import {getJsonType} from "../../utils/getJsonType.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @ignore
|
|
10
|
+
*/
|
|
11
|
+
export function genericsMapper(obj: any, options: GenericsContext) {
|
|
12
|
+
const {generics} = options;
|
|
13
|
+
|
|
14
|
+
if (generics && obj.$ref) {
|
|
15
|
+
if (generics.has(obj.$ref)) {
|
|
16
|
+
let type = generics.get(obj.$ref);
|
|
17
|
+
|
|
18
|
+
if (isPrimitiveClass(type)) {
|
|
19
|
+
return {
|
|
20
|
+
type: getJsonType(type)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (type === Date) {
|
|
25
|
+
return {
|
|
26
|
+
type: "string",
|
|
27
|
+
format: "date-time"
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (type.toJSON) {
|
|
32
|
+
return type.toJSON({
|
|
33
|
+
...options,
|
|
34
|
+
generics: undefined
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (type === Object) {
|
|
39
|
+
return {
|
|
40
|
+
type: "object"
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (isClass(type)) {
|
|
45
|
+
const model = {
|
|
46
|
+
class: type
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
if (options.nestedGenerics.length === 0) {
|
|
50
|
+
return execMapper("class", [model as any], {
|
|
51
|
+
...options,
|
|
52
|
+
generics: undefined
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const store = JsonEntityStore.from(model.class);
|
|
57
|
+
|
|
58
|
+
return execMapper("schema", [store.schema], {
|
|
59
|
+
...options,
|
|
60
|
+
...popGenerics(options),
|
|
61
|
+
root: false
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return obj;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
registerJsonSchemaMapper("generics", genericsMapper);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {classOf, deepMerge} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
4
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
5
|
+
import {getInheritedStores} from "../../utils/getInheritedStores.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @ignore
|
|
9
|
+
*/
|
|
10
|
+
export function inheritedClassMapper(obj: any, {target, ...options}: JsonSchemaOptions) {
|
|
11
|
+
const stores = Array.from(getInheritedStores(target).entries()).filter(([model]) => classOf(model) !== classOf(target));
|
|
12
|
+
|
|
13
|
+
if (stores.length) {
|
|
14
|
+
const schema = stores.reduce((obj, [, store]) => {
|
|
15
|
+
return deepMerge(obj, execMapper("schema", [store.schema], options));
|
|
16
|
+
}, {});
|
|
17
|
+
|
|
18
|
+
obj = deepMerge(schema, obj);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return obj;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
registerJsonSchemaMapper("inheritedClass", inheritedClassMapper);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
2
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
3
|
+
|
|
4
|
+
export function itemMapper(value: any, options: JsonSchemaOptions) {
|
|
5
|
+
return value && value.isClass ? execMapper("class", [value], options) : execMapper("any", [value], options);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
registerJsonSchemaMapper("item", itemMapper);
|