@tsed/schema 8.0.1 → 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,21 @@
|
|
|
1
|
+
import {JsonLazyRef} from "../../domain/JsonLazyRef.js";
|
|
2
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
3
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
4
|
+
import {mapGenericsOptions} from "../../utils/generics.js";
|
|
5
|
+
import {createRef, toRef} from "../../utils/ref.js";
|
|
6
|
+
|
|
7
|
+
export function lazyRefMapper(jsonLazyRef: JsonLazyRef, options: JsonSchemaOptions) {
|
|
8
|
+
const name = jsonLazyRef.name;
|
|
9
|
+
|
|
10
|
+
if (options.$refs?.find((t: any) => t === jsonLazyRef.target)) {
|
|
11
|
+
return createRef(name, jsonLazyRef.schema, options);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
options.$refs = [...(options.$refs || []), jsonLazyRef.target];
|
|
15
|
+
|
|
16
|
+
const schema = jsonLazyRef.getType() && execMapper("schema", [jsonLazyRef.schema], mapGenericsOptions(options));
|
|
17
|
+
|
|
18
|
+
return toRef(jsonLazyRef.schema, schema, options);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
registerJsonSchemaMapper("lazyRef", lazyRefMapper);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
2
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
3
|
+
import {mapGenericsOptions} from "../../utils/generics.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Serialize class which inherit from Map like JsonMap, JsonOperation, JsonParameter.
|
|
7
|
+
* @param input
|
|
8
|
+
* @param ignore
|
|
9
|
+
* @param options
|
|
10
|
+
* @ignore
|
|
11
|
+
*/
|
|
12
|
+
export function mapMapper(input: Map<string, any>, {ignore = [], ...options}: JsonSchemaOptions = {}): any {
|
|
13
|
+
options = mapGenericsOptions(options);
|
|
14
|
+
|
|
15
|
+
return Array.from(input.entries()).reduce((obj: any, [key, value]) => {
|
|
16
|
+
if (ignore.includes(key)) {
|
|
17
|
+
return obj;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
obj[key] = execMapper("item", [value], options);
|
|
21
|
+
return obj;
|
|
22
|
+
}, {});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
registerJsonSchemaMapper("map", mapMapper);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {cleanObject} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {MANY_OF_PROPERTIES} from "../../constants/jsonSchemaProperties.js";
|
|
4
|
+
import type {JsonSchema} from "../../domain/JsonSchema.js";
|
|
5
|
+
import {registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
6
|
+
|
|
7
|
+
export function nullableMapper(obj: any, schema: JsonSchema | null) {
|
|
8
|
+
if (!schema?.isNullable) {
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (!obj.discriminator) {
|
|
13
|
+
if (obj.$ref) {
|
|
14
|
+
obj = cleanObject({
|
|
15
|
+
...obj,
|
|
16
|
+
$ref: undefined,
|
|
17
|
+
anyOf: [
|
|
18
|
+
{type: "null"},
|
|
19
|
+
{
|
|
20
|
+
$ref: obj.$ref
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
MANY_OF_PROPERTIES.some((keyword: string) => {
|
|
26
|
+
if (obj[keyword]) {
|
|
27
|
+
obj[keyword] = obj[keyword].filter((item: any) => item.type !== "null");
|
|
28
|
+
|
|
29
|
+
if (obj[keyword].length === 1) {
|
|
30
|
+
const base = obj[keyword];
|
|
31
|
+
|
|
32
|
+
obj = cleanObject({
|
|
33
|
+
...obj,
|
|
34
|
+
...base[0],
|
|
35
|
+
[keyword]: undefined,
|
|
36
|
+
type: ["null", Number.isInteger(obj.multipleOf) ? "integer" : base[0].type]
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
obj[keyword] = [{type: "null"}].concat(obj[keyword]).map((item: any) => {
|
|
40
|
+
if (Number.isInteger(item.multipleOf)) {
|
|
41
|
+
item.type = "integer";
|
|
42
|
+
}
|
|
43
|
+
return item;
|
|
44
|
+
});
|
|
45
|
+
delete obj.type;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return obj;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
registerJsonSchemaMapper("nullable", nullableMapper);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {isArray} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {JsonSchema} from "../../domain/JsonSchema.js";
|
|
4
|
+
import {alterIgnore} from "../../hooks/alterIgnore.js";
|
|
5
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
6
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Serialize Any object to a json schema
|
|
10
|
+
* @param input
|
|
11
|
+
* @param options
|
|
12
|
+
* @ignore
|
|
13
|
+
*/
|
|
14
|
+
export function objectMapper(input: any, options: JsonSchemaOptions) {
|
|
15
|
+
const {specType, operationIdFormatter, root, components, genericTypes, nestedGenerics, useAlias, genericLabels, ...ctx} = options;
|
|
16
|
+
|
|
17
|
+
return Object.entries(input).reduce<any>(
|
|
18
|
+
(obj, [key, value]: [string, any | JsonSchema]) => {
|
|
19
|
+
if (options.withIgnoredProps !== false && !alterIgnore(value, ctx)) {
|
|
20
|
+
const opts = {
|
|
21
|
+
...options,
|
|
22
|
+
groups: input?.$forwardGroups || value?.$forwardGroups ? options.groups : undefined
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// remove groups to avoid bad schema generation over children models
|
|
26
|
+
obj[key] = execMapper("item", [value], opts);
|
|
27
|
+
obj[key] = execMapper("nullable", [obj[key], value], opts);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return obj;
|
|
31
|
+
},
|
|
32
|
+
isArray(input) ? [] : {}
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
registerJsonSchemaMapper("object", objectMapper);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type {JsonSchema} from "../../domain/JsonSchema.js";
|
|
2
|
+
import type {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
3
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
4
|
+
|
|
5
|
+
export function ofMapper(input: (any | JsonSchema)[], options: JsonSchemaOptions, parent: JsonSchema) {
|
|
6
|
+
return input.map((value: any | JsonSchema) => {
|
|
7
|
+
return execMapper("item", [value], {
|
|
8
|
+
...options,
|
|
9
|
+
genericLabels: parent.genericLabels
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
registerJsonSchemaMapper("anyOf", ofMapper);
|
|
15
|
+
registerJsonSchemaMapper("allOf", ofMapper);
|
|
16
|
+
registerJsonSchemaMapper("oneOf", ofMapper);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type {JsonSchema} from "../../domain/JsonSchema.js";
|
|
2
|
+
import type {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
3
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
4
|
+
|
|
5
|
+
export function propertiesMapper(input: any | JsonSchema, options: JsonSchemaOptions, parent: JsonSchema) {
|
|
6
|
+
if (input.isClass) {
|
|
7
|
+
return execMapper("class", [input], options);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return execMapper("any", [input], {
|
|
11
|
+
...options,
|
|
12
|
+
genericLabels: parent.genericLabels
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
registerJsonSchemaMapper("properties", propertiesMapper);
|
|
17
|
+
registerJsonSchemaMapper("items", propertiesMapper);
|
|
18
|
+
registerJsonSchemaMapper("additionalProperties", propertiesMapper);
|
|
19
|
+
registerJsonSchemaMapper("propertyNames", propertiesMapper);
|
|
20
|
+
registerJsonSchemaMapper("contains", propertiesMapper);
|
|
21
|
+
registerJsonSchemaMapper("dependencies", propertiesMapper);
|
|
22
|
+
registerJsonSchemaMapper("patternProperties", propertiesMapper);
|
|
23
|
+
registerJsonSchemaMapper("additionalItems", propertiesMapper);
|
|
24
|
+
registerJsonSchemaMapper("not", propertiesMapper);
|
|
25
|
+
registerJsonSchemaMapper("definitions", propertiesMapper);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {uniq} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import type {JsonSchema} from "../../domain/JsonSchema.js";
|
|
4
|
+
import {alterRequiredGroups} from "../../hooks/alterRequiredGroups.js";
|
|
5
|
+
import type {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
6
|
+
import {registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
7
|
+
import {createRef, createRefName, toRef} from "../../utils/ref.js";
|
|
8
|
+
|
|
9
|
+
function mapRequiredProps(obj: any, schema: JsonSchema, options: JsonSchemaOptions = {}) {
|
|
10
|
+
const {useAlias} = options;
|
|
11
|
+
const props = Object.keys(obj.properties || {});
|
|
12
|
+
|
|
13
|
+
return (keys: string[], key: string) => {
|
|
14
|
+
const aliasedKey = useAlias ? (schema.alias.get(key) as string) || key : key;
|
|
15
|
+
|
|
16
|
+
if (props.includes(aliasedKey)) {
|
|
17
|
+
return keys.concat(aliasedKey);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return keys;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function extractRequiredProps(obj: any, schema: JsonSchema, options: JsonSchemaOptions): string[] {
|
|
25
|
+
let required: string[] = obj.required || [];
|
|
26
|
+
|
|
27
|
+
required = [...required, ...schema.$required];
|
|
28
|
+
|
|
29
|
+
if (schema.get("properties")) {
|
|
30
|
+
required = Object.entries(schema.get("properties")).reduce((required, [key, prop]: [string, any]) => {
|
|
31
|
+
if (prop && prop.$selfRequired !== undefined) {
|
|
32
|
+
return prop.$selfRequired ? required.concat(key) : required.filter((k) => k === key);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return required;
|
|
36
|
+
}, required);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return alterRequiredGroups(uniq(required), schema, options);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function requiredMapper(obj: any, schema: JsonSchema, options: JsonSchemaOptions) {
|
|
43
|
+
if (options.groups && options.groups.includes("partial")) {
|
|
44
|
+
if (obj.discriminator) {
|
|
45
|
+
return {
|
|
46
|
+
...obj,
|
|
47
|
+
required: [obj.discriminator.propertyName]
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return obj;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let required = extractRequiredProps(obj, schema, options);
|
|
55
|
+
|
|
56
|
+
required = uniq(required).reduce(mapRequiredProps(obj, schema, options), []);
|
|
57
|
+
|
|
58
|
+
if (obj.discriminator) {
|
|
59
|
+
required.push(obj.discriminator.propertyName);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (required.length) {
|
|
63
|
+
obj.required = required;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return obj;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
registerJsonSchemaMapper("required", requiredMapper);
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import {getValue, isObject} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {mapAliasedProperties} from "../../domain/JsonAliasMap.js";
|
|
4
|
+
import {JsonSchema} from "../../domain/JsonSchema.js";
|
|
5
|
+
import {SpecTypes} from "../../domain/SpecTypes.js";
|
|
6
|
+
import {alterOneOf} from "../../hooks/alterOneOf.js";
|
|
7
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
8
|
+
import {execMapper, hasMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @ignore
|
|
12
|
+
*/
|
|
13
|
+
const IGNORES = ["name", "$required", "$hooks", "_nestedGenerics", SpecTypes.OPENAPI, SpecTypes.SWAGGER, SpecTypes.JSON];
|
|
14
|
+
/**
|
|
15
|
+
* @ignore
|
|
16
|
+
*/
|
|
17
|
+
const IGNORES_OPENSPEC: string[] = [];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @ignore
|
|
21
|
+
*/
|
|
22
|
+
function isEmptyProperties(key: string, value: any) {
|
|
23
|
+
return typeof value === "object" && ["items", "properties", "additionalProperties"].includes(key) && Object.keys(value).length === 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @ignore
|
|
28
|
+
*/
|
|
29
|
+
function shouldMapAlias(key: string, value: any, useAlias: boolean) {
|
|
30
|
+
return typeof value === "object" && useAlias && ["properties", "additionalProperties"].includes(key);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @ignore
|
|
35
|
+
*/
|
|
36
|
+
function shouldSkipKey(key: string, {specType = SpecTypes.JSON, customKeys = false}: JsonSchemaOptions) {
|
|
37
|
+
return (
|
|
38
|
+
IGNORES.includes(key) ||
|
|
39
|
+
(key.startsWith("#") && (customKeys === false || specType !== SpecTypes.JSON)) ||
|
|
40
|
+
(specType !== SpecTypes.JSON && IGNORES_OPENSPEC.includes(key))
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isExample(key: string, value: any, options: JsonSchemaOptions) {
|
|
45
|
+
return key === "examples" && isObject(value) && [SpecTypes.OPENAPI, SpecTypes.ASYNCAPI].includes(options.specType!)!;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function mapOptions(options: JsonSchemaOptions) {
|
|
49
|
+
let addDef = false;
|
|
50
|
+
|
|
51
|
+
if (!options) {
|
|
52
|
+
addDef = true;
|
|
53
|
+
options = {components: {schemas: {}}, inlineEnums: true};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const {useAlias = true, components = {schemas: {}}} = options;
|
|
57
|
+
options = {
|
|
58
|
+
...options,
|
|
59
|
+
useAlias,
|
|
60
|
+
components
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
addDef,
|
|
65
|
+
options
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function mapKeys(schema: JsonSchema, options: JsonSchemaOptions) {
|
|
70
|
+
const {useAlias} = options;
|
|
71
|
+
|
|
72
|
+
return [...schema.keys()]
|
|
73
|
+
.filter((key) => !shouldSkipKey(key, options))
|
|
74
|
+
.reduce((item: any, key) => {
|
|
75
|
+
let value = schema.get(key);
|
|
76
|
+
|
|
77
|
+
key = key.replace(/^#/, "");
|
|
78
|
+
|
|
79
|
+
if (key === "type") {
|
|
80
|
+
item[key] = schema.getJsonType();
|
|
81
|
+
return item;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (isExample(key, value, options)) {
|
|
85
|
+
key = "example";
|
|
86
|
+
value = Object.values(value)[0];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (value && typeof value === "object" && hasMapper(key)) {
|
|
90
|
+
value = execMapper(key, [value], options, schema);
|
|
91
|
+
|
|
92
|
+
if (isEmptyProperties(key, value)) {
|
|
93
|
+
return item;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (shouldMapAlias(key, value, useAlias!)) {
|
|
97
|
+
value = mapAliasedProperties(value, schema.alias);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
item[key] = value;
|
|
102
|
+
|
|
103
|
+
return item;
|
|
104
|
+
}, {});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function serializeSchema(schema: JsonSchema, options: JsonSchemaOptions) {
|
|
108
|
+
let obj: any = mapKeys(schema, options);
|
|
109
|
+
|
|
110
|
+
if (schema.isClass) {
|
|
111
|
+
obj = execMapper("inheritedClass", [obj], {
|
|
112
|
+
...options,
|
|
113
|
+
root: false,
|
|
114
|
+
target: schema.getComputedType()
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
obj = execMapper("generics", [obj], {
|
|
119
|
+
...options,
|
|
120
|
+
root: false
|
|
121
|
+
} as any);
|
|
122
|
+
|
|
123
|
+
if (schema.has(options.specType as string)) {
|
|
124
|
+
obj = {
|
|
125
|
+
...obj,
|
|
126
|
+
...schema.get(options.specType as string).toJSON(options)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
obj = execMapper("required", [obj, schema], options);
|
|
131
|
+
obj = execMapper("nullable", [obj, schema], options);
|
|
132
|
+
obj = alterOneOf(obj, schema, options);
|
|
133
|
+
obj = execMapper("enums", [obj, schema], options);
|
|
134
|
+
obj = execMapper("discriminatorMapping", [obj, schema], options);
|
|
135
|
+
|
|
136
|
+
return obj;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function schemaMapper(schema: JsonSchema, opts: JsonSchemaOptions): any {
|
|
140
|
+
const {options, addDef} = mapOptions(opts);
|
|
141
|
+
|
|
142
|
+
const obj = serializeSchema(schema, options);
|
|
143
|
+
|
|
144
|
+
if (addDef && Object.keys(getValue(options, "components.schemas", {})).length) {
|
|
145
|
+
obj.definitions = options.components!.schemas;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return obj;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
registerJsonSchemaMapper("schema", schemaMapper);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by @tsed/barrels.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./async-api/channelsMapper.js";
|
|
5
|
+
export * from "./async-api/generate.js";
|
|
6
|
+
export * from "./async-api/messageMapper.js";
|
|
7
|
+
export * from "./async-api/payloadMapper.js";
|
|
8
|
+
export * from "./async-api/responseMapper.js";
|
|
9
|
+
export * from "./default/anyMapper.js";
|
|
10
|
+
export * from "./default/classMapper.js";
|
|
11
|
+
export * from "./default/discriminatorMappingMapper.js";
|
|
12
|
+
export * from "./default/enumsMapper.js";
|
|
13
|
+
export * from "./default/genericsMapper.js";
|
|
14
|
+
export * from "./default/inheritedClassMapper.js";
|
|
15
|
+
export * from "./default/itemMapper.js";
|
|
16
|
+
export * from "./default/lazyRefMapper.js";
|
|
17
|
+
export * from "./default/mapMapper.js";
|
|
18
|
+
export * from "./default/nullableMapper.js";
|
|
19
|
+
export * from "./default/objectMapper.js";
|
|
20
|
+
export * from "./default/ofMapper.js";
|
|
21
|
+
export * from "./default/propertiesMapper.js";
|
|
22
|
+
export * from "./default/requiredMapper.js";
|
|
23
|
+
export * from "./default/schemaMapper.js";
|
|
24
|
+
export * from "./open-spec/discriminatorMappingMapper.js";
|
|
25
|
+
export * from "./open-spec/enumsMapper.js";
|
|
26
|
+
export * from "./open-spec/generate.js";
|
|
27
|
+
export * from "./open-spec/nullableMapper.js";
|
|
28
|
+
export * from "./open-spec/operationInFilesMapper.js";
|
|
29
|
+
export * from "./open-spec/operationInParameterMapper.js";
|
|
30
|
+
export * from "./open-spec/operationInParametersMapper.js";
|
|
31
|
+
export * from "./open-spec/operationInQueryMapper.js";
|
|
32
|
+
export * from "./open-spec/operationMapper.js";
|
|
33
|
+
export * from "./open-spec/operationMediaMapper.js";
|
|
34
|
+
export * from "./open-spec/operationRequestBodyMapper.js";
|
|
35
|
+
export * from "./open-spec/operationResponseMapper.js";
|
|
36
|
+
export * from "./open-spec/pathsMapper.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import {SpecTypes} from "../../domain/SpecTypes.js";
|
|
2
|
+
import {registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
3
|
+
import {discriminatorMappingMapper} from "../default/discriminatorMappingMapper.js";
|
|
4
|
+
|
|
5
|
+
registerJsonSchemaMapper("discriminatorMapping", discriminatorMappingMapper, SpecTypes.OPENAPI);
|
|
6
|
+
registerJsonSchemaMapper("discriminatorMapping", discriminatorMappingMapper, SpecTypes.SWAGGER);
|
|
7
|
+
registerJsonSchemaMapper("discriminatorMapping", discriminatorMappingMapper, SpecTypes.ASYNCAPI);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {JsonSchema} from "../../domain/JsonSchema.js";
|
|
2
|
+
import {SpecTypes} from "../../domain/SpecTypes.js";
|
|
3
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
4
|
+
import {registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
5
|
+
import {enumsMapper} from "../default/enumsMapper.js";
|
|
6
|
+
|
|
7
|
+
export function wrapEnumsMapper(obj: any, schema: JsonSchema, options: JsonSchemaOptions) {
|
|
8
|
+
obj = enumsMapper(obj, schema, options);
|
|
9
|
+
|
|
10
|
+
if (obj.const) {
|
|
11
|
+
obj.enum = [obj.const];
|
|
12
|
+
delete obj.const;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
registerJsonSchemaMapper("enums", wrapEnumsMapper, SpecTypes.OPENAPI);
|
|
19
|
+
registerJsonSchemaMapper("enums", wrapEnumsMapper, SpecTypes.SWAGGER);
|
|
20
|
+
registerJsonSchemaMapper("enums", wrapEnumsMapper, SpecTypes.ASYNCAPI);
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
options = {
|
|
9
|
+
...options,
|
|
10
|
+
specType: SpecTypes.OPENAPI
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const specJson: any = {
|
|
14
|
+
paths: execMapper("paths", [model], options)
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
specJson.tags = uniqBy(options.tags, "name");
|
|
18
|
+
|
|
19
|
+
if (Object.keys(getValue(options, "components.schemas", {})).length) {
|
|
20
|
+
specJson.components = {
|
|
21
|
+
schemas: options.components!.schemas
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return specJson;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
registerJsonSchemaMapper("generate", generate, SpecTypes.OPENAPI);
|
|
29
|
+
registerJsonSchemaMapper("generate", generate, SpecTypes.SWAGGER);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {cleanObject} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import type {JsonSchema} from "../../domain/JsonSchema.js";
|
|
4
|
+
import {SpecTypes} from "../../domain/SpecTypes.js";
|
|
5
|
+
import {registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
6
|
+
|
|
7
|
+
export function nullableMapperOpenApi(obj: any, schema: JsonSchema | null) {
|
|
8
|
+
if (!schema?.isNullable) {
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (obj.$ref) {
|
|
13
|
+
return cleanObject({
|
|
14
|
+
...obj,
|
|
15
|
+
...(obj.$ref && {
|
|
16
|
+
anyOf: [
|
|
17
|
+
{
|
|
18
|
+
$ref: obj.$ref
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
type: undefined
|
|
22
|
+
}),
|
|
23
|
+
nullable: true,
|
|
24
|
+
$ref: undefined
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return cleanObject({
|
|
29
|
+
...obj,
|
|
30
|
+
...(obj.anyOf?.length === 1
|
|
31
|
+
? {
|
|
32
|
+
...obj.anyOf[0],
|
|
33
|
+
anyOf: undefined,
|
|
34
|
+
type: Number.isInteger(obj.multipleOf) ? "integer" : obj.anyOf[0]?.type
|
|
35
|
+
}
|
|
36
|
+
: {
|
|
37
|
+
type: obj.anyOf?.length > 1 ? undefined : obj.type,
|
|
38
|
+
anyOf: obj.anyOf?.map((item: any) => {
|
|
39
|
+
if (Number.isInteger(item.multipleOf)) {
|
|
40
|
+
item.type = "integer";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return item;
|
|
44
|
+
})
|
|
45
|
+
}),
|
|
46
|
+
nullable: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
registerJsonSchemaMapper("nullable", nullableMapperOpenApi, SpecTypes.OPENAPI);
|
|
51
|
+
registerJsonSchemaMapper("nullable", nullableMapperOpenApi, SpecTypes.SWAGGER);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {cleanObject} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
4
|
+
import type {JsonParameterOptions} from "./operationInParameterMapper.js";
|
|
5
|
+
|
|
6
|
+
export function operationInFilesMapper(parameter: any, {jsonSchema}: JsonParameterOptions) {
|
|
7
|
+
const schema = {
|
|
8
|
+
type: "string",
|
|
9
|
+
format: "binary",
|
|
10
|
+
oneOf: undefined
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
if (jsonSchema.type === "array") {
|
|
14
|
+
jsonSchema.items = cleanObject({
|
|
15
|
+
...(jsonSchema.items as Object),
|
|
16
|
+
...schema
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
parameter.schema = jsonSchema;
|
|
20
|
+
|
|
21
|
+
return parameter;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
parameter.schema = cleanObject({
|
|
25
|
+
...jsonSchema,
|
|
26
|
+
...schema
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return parameter;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
registerJsonSchemaMapper("operationInFiles", operationInFilesMapper);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {OS3Schema} from "@tsed/openspec";
|
|
2
|
+
import {camelCase} from "change-case";
|
|
3
|
+
import type {JSONSchema6} from "json-schema";
|
|
4
|
+
|
|
5
|
+
import {JsonParameter} from "../../domain/JsonParameter.js";
|
|
6
|
+
import {JsonParameterTypes} from "../../domain/JsonParameterTypes.js";
|
|
7
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
8
|
+
import {execMapper, hasMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
9
|
+
import {popGenerics} from "../../utils/generics.js";
|
|
10
|
+
|
|
11
|
+
export type JsonParameterOptions = JsonSchemaOptions & {
|
|
12
|
+
jsonParameter: JsonParameter;
|
|
13
|
+
jsonSchema: JSONSchema6;
|
|
14
|
+
oldSchemas: Record<string, OS3Schema>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function mapOptions(parameter: JsonParameter, options: JsonSchemaOptions = {}) {
|
|
18
|
+
return {
|
|
19
|
+
...options,
|
|
20
|
+
groups: parameter.groups,
|
|
21
|
+
groupsName: parameter.groupsName
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function operationInParameterMapper(jsonParameter: JsonParameter, opts?: JsonSchemaOptions) {
|
|
26
|
+
const options = mapOptions(jsonParameter, opts);
|
|
27
|
+
const schemas = {...(options.components?.schemas || {})};
|
|
28
|
+
|
|
29
|
+
const {type, schema, ...parameter} = execMapper("map", [jsonParameter], options);
|
|
30
|
+
|
|
31
|
+
const jsonSchema = execMapper("item", [jsonParameter.$schema], {
|
|
32
|
+
...options,
|
|
33
|
+
...popGenerics(jsonParameter)
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
parameter.required = parameter.required || jsonParameter.get("in") === JsonParameterTypes.PATH;
|
|
37
|
+
|
|
38
|
+
const paramOpts = {
|
|
39
|
+
...options,
|
|
40
|
+
jsonSchema,
|
|
41
|
+
jsonParameter,
|
|
42
|
+
oldSchemas: schemas
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const mapperName = camelCase(`operationIn ${jsonParameter.get("in")}`);
|
|
46
|
+
|
|
47
|
+
if (hasMapper(mapperName)) {
|
|
48
|
+
return execMapper(mapperName, [parameter], paramOpts);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
parameter.schema = jsonSchema;
|
|
52
|
+
|
|
53
|
+
return parameter;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
registerJsonSchemaMapper("operationInParameter", operationInParameterMapper);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {JsonParameter} from "../../domain/JsonParameter.js";
|
|
2
|
+
import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
|
|
3
|
+
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
|
|
4
|
+
|
|
5
|
+
export function operationInParametersMapper(parameters: JsonParameter[], options: JsonSchemaOptions) {
|
|
6
|
+
return parameters.flatMap((parameter) => execMapper("operationInParameter", [parameter], options)).filter(Boolean);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
registerJsonSchemaMapper("operationInParameters", operationInParametersMapper);
|