@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,54 @@
|
|
|
1
|
+
import {getValue} from "@tsed/core";
|
|
2
|
+
import {OpenSpec2, OpenSpec3} from "@tsed/openspec";
|
|
3
|
+
|
|
4
|
+
import {SpecTypes} from "../domain/SpecTypes.js";
|
|
5
|
+
import {getSpec, JsonTokenOptions, SpecSerializerOptions} from "./getSpec.js";
|
|
6
|
+
import {getSpecTypeFromSpec} from "./getSpecType.js";
|
|
7
|
+
import {mapOpenSpec} from "./mapOpenSpec.js";
|
|
8
|
+
import {mergeSpec} from "./mergeSpec.js";
|
|
9
|
+
import {transformToOS2} from "./transformToOS2.js";
|
|
10
|
+
|
|
11
|
+
export interface GenerateSpecOptions extends Omit<SpecSerializerOptions, "specType"> {
|
|
12
|
+
tokens: JsonTokenOptions;
|
|
13
|
+
version?: string;
|
|
14
|
+
acceptMimes?: string;
|
|
15
|
+
specVersion?: string;
|
|
16
|
+
spec?: any;
|
|
17
|
+
fileSpec?: any;
|
|
18
|
+
sortPaths?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Generate OpenAPI spec from multiple sources (models, files, conf)
|
|
23
|
+
* @param tokens
|
|
24
|
+
* @param options
|
|
25
|
+
*/
|
|
26
|
+
export function generateSpec({tokens, ...options}: GenerateSpecOptions): OpenSpec2 | OpenSpec3 {
|
|
27
|
+
const {version = "1.0.0", acceptMimes, fileSpec = {}, specVersion} = options;
|
|
28
|
+
|
|
29
|
+
const defaultSpec = mapOpenSpec(getValue(options, "spec", {}), {
|
|
30
|
+
fileSpec,
|
|
31
|
+
version,
|
|
32
|
+
specVersion,
|
|
33
|
+
acceptMimes
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const specType = getSpecTypeFromSpec(defaultSpec);
|
|
37
|
+
|
|
38
|
+
let controllersSpec: any = getSpec(tokens, options);
|
|
39
|
+
const spec = mergeSpec(defaultSpec, controllersSpec) as OpenSpec2 | OpenSpec3;
|
|
40
|
+
|
|
41
|
+
if (options.sortPaths) {
|
|
42
|
+
spec.paths = Object.fromEntries(
|
|
43
|
+
Object.entries(spec.paths!).sort(([k1], [k2]) => {
|
|
44
|
+
return k1.localeCompare(k2);
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (specType === SpecTypes.SWAGGER) {
|
|
50
|
+
return transformToOS2(spec) as any;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return spec;
|
|
54
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {Type} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {JsonSchema} from "../domain/JsonSchema.js";
|
|
4
|
+
|
|
5
|
+
export type GenericValue = Type<any> | JsonSchema | any;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @ignore
|
|
9
|
+
*/
|
|
10
|
+
export type GenericsMap = Map<string, GenericValue>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @ignore
|
|
14
|
+
*/
|
|
15
|
+
export interface GenericTypes {
|
|
16
|
+
genericTypes: Type<any>[];
|
|
17
|
+
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @ignore
|
|
23
|
+
*/
|
|
24
|
+
export interface GenericLabels {
|
|
25
|
+
genericLabels: string[];
|
|
26
|
+
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @ignore
|
|
32
|
+
*/
|
|
33
|
+
export interface NestedGenerics {
|
|
34
|
+
nestedGenerics: GenericValue[][];
|
|
35
|
+
|
|
36
|
+
[key: string]: any;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @ignore
|
|
41
|
+
*/
|
|
42
|
+
export interface GenericsContext extends GenericTypes, GenericLabels, NestedGenerics {
|
|
43
|
+
generics: GenericsMap;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @ignore
|
|
48
|
+
* @param genericLabels
|
|
49
|
+
* @param genericTypes
|
|
50
|
+
*/
|
|
51
|
+
export function getGenericsMap(genericLabels: string[], genericTypes: GenericValue[]): GenericsMap {
|
|
52
|
+
return genericLabels.reduce((map: Map<string, any>, item: string, index: number) => map.set(item, genericTypes[index]), new Map());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @ignore
|
|
57
|
+
* @param options
|
|
58
|
+
*/
|
|
59
|
+
export function mapGenericsOptions(options: Partial<GenericTypes & GenericLabels>) {
|
|
60
|
+
if (options.genericLabels && options.genericTypes) {
|
|
61
|
+
const {genericLabels, genericTypes, ...ops} = options;
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
...ops,
|
|
65
|
+
generics: getGenericsMap(genericLabels, genericTypes)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return options;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @ignore
|
|
74
|
+
* @param value
|
|
75
|
+
*/
|
|
76
|
+
export function popGenerics(value: NestedGenerics): NestedGenerics & GenericTypes {
|
|
77
|
+
const [genericTypes, ...out] = value.nestedGenerics;
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
genericTypes,
|
|
81
|
+
nestedGenerics: out
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {getComputedType} from "./getComputedType.js";
|
|
2
|
+
|
|
3
|
+
describe("getComputedType", () => {
|
|
4
|
+
it("should return the right class (String)", () => {
|
|
5
|
+
expect(getComputedType(String)).toEqual(String);
|
|
6
|
+
});
|
|
7
|
+
it("should return the right class (Number)", () => {
|
|
8
|
+
expect(getComputedType(Number)).toEqual(Number);
|
|
9
|
+
});
|
|
10
|
+
it("should return the right class (Boolean)", () => {
|
|
11
|
+
expect(getComputedType(Boolean)).toEqual(Boolean);
|
|
12
|
+
});
|
|
13
|
+
it("should return the right class (Symbol)", () => {
|
|
14
|
+
expect(getComputedType(Symbol)).toEqual(Symbol);
|
|
15
|
+
});
|
|
16
|
+
it("should return the right class (Date)", () => {
|
|
17
|
+
expect(getComputedType(Date)).toEqual(Date);
|
|
18
|
+
});
|
|
19
|
+
it("should return the right class (Array)", () => {
|
|
20
|
+
expect(getComputedType(Array)).toEqual(Array);
|
|
21
|
+
});
|
|
22
|
+
it("should return the right class (Map)", () => {
|
|
23
|
+
expect(getComputedType(Map)).toEqual(Map);
|
|
24
|
+
});
|
|
25
|
+
it("should return the right class (Set)", () => {
|
|
26
|
+
expect(getComputedType(Set)).toEqual(Set);
|
|
27
|
+
});
|
|
28
|
+
it("should return the right class (Promise)", () => {
|
|
29
|
+
expect(getComputedType(Promise)).toEqual(Object);
|
|
30
|
+
});
|
|
31
|
+
it("should return the right class (class with arrow)", () => {
|
|
32
|
+
class Test {}
|
|
33
|
+
|
|
34
|
+
expect(getComputedType(() => Test)).toEqual(Test);
|
|
35
|
+
});
|
|
36
|
+
it("should return the right class (class)", () => {
|
|
37
|
+
class Test {}
|
|
38
|
+
|
|
39
|
+
expect(getComputedType(Test)).toEqual(Test);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should return the right class (undefined)", () => {
|
|
43
|
+
expect(getComputedType(undefined)).toEqual(undefined);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
classOf,
|
|
3
|
+
isArrowFn,
|
|
4
|
+
isClass,
|
|
5
|
+
isClassObject,
|
|
6
|
+
isCollection,
|
|
7
|
+
isDate,
|
|
8
|
+
isFunction,
|
|
9
|
+
isPrimitiveOrPrimitiveClass,
|
|
10
|
+
isPromise,
|
|
11
|
+
isSymbol,
|
|
12
|
+
Type
|
|
13
|
+
} from "@tsed/core";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @ignore
|
|
17
|
+
*/
|
|
18
|
+
export function getComputedType(target: any): Type<any> {
|
|
19
|
+
if (isPromise(target) || target === Function) {
|
|
20
|
+
return Object;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (
|
|
24
|
+
isClass(target) ||
|
|
25
|
+
isSymbol(target) ||
|
|
26
|
+
isPrimitiveOrPrimitiveClass(target) ||
|
|
27
|
+
isClassObject(target) ||
|
|
28
|
+
isDate(target) ||
|
|
29
|
+
isCollection(target)
|
|
30
|
+
) {
|
|
31
|
+
return classOf(target);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (isArrowFn(target)) {
|
|
35
|
+
return (target as any)();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return target;
|
|
39
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {StoreSet} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {OperationPath} from "../decorators/operations/operationPath.js";
|
|
4
|
+
import {getInheritedStores} from "./getInheritedStores.js";
|
|
5
|
+
|
|
6
|
+
describe("getInheritedStores", () => {
|
|
7
|
+
it("should return inherited store", () => {
|
|
8
|
+
class Test2 {
|
|
9
|
+
@StoreSet("test", "Test2")
|
|
10
|
+
@OperationPath("GET")
|
|
11
|
+
method1(): any {}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class Test1 extends Test2 {
|
|
15
|
+
@StoreSet("test", "Test1")
|
|
16
|
+
@OperationPath("GET")
|
|
17
|
+
method(): any {}
|
|
18
|
+
|
|
19
|
+
@StoreSet("test", "Test1")
|
|
20
|
+
@OperationPath("GET")
|
|
21
|
+
method2(): any {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class Test extends Test1 {
|
|
25
|
+
@StoreSet("test", "Test")
|
|
26
|
+
@OperationPath("GET")
|
|
27
|
+
method(): any {}
|
|
28
|
+
|
|
29
|
+
@StoreSet("test", "Test")
|
|
30
|
+
@OperationPath("GET")
|
|
31
|
+
method3() {}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const stores = [...getInheritedStores(Test).entries()];
|
|
35
|
+
|
|
36
|
+
expect(stores[0][0]).toEqual(Test);
|
|
37
|
+
expect(stores[1][0]).toEqual(Test1);
|
|
38
|
+
expect(stores[2][0]).toEqual(Test2);
|
|
39
|
+
|
|
40
|
+
const entity1 = stores[0][1].children.get("method");
|
|
41
|
+
const entity2 = stores[1][1].children.get("method");
|
|
42
|
+
const entity3 = stores[2][1].children.get("method");
|
|
43
|
+
expect(entity1?.store.get("test")).toEqual("Test");
|
|
44
|
+
expect(entity2?.store.get("test")).toEqual("Test1");
|
|
45
|
+
expect(entity3?.store.get("test")).toEqual(undefined);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {ancestorsOf, Type} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import type {JsonClassStore} from "../domain/JsonClassStore.js";
|
|
4
|
+
import {getJsonEntityStore} from "./getJsonEntityStore.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Return store and his inherited stores
|
|
8
|
+
* @param target
|
|
9
|
+
* @ignore
|
|
10
|
+
*/
|
|
11
|
+
export function getInheritedStores(target: Type<any> | any): Map<Type<any>, JsonClassStore> {
|
|
12
|
+
const store: JsonClassStore = target.isStore ? target : getJsonEntityStore<JsonClassStore>(target);
|
|
13
|
+
|
|
14
|
+
if (!store.$inherited) {
|
|
15
|
+
store.$inherited = ancestorsOf(store.target)
|
|
16
|
+
.reverse()
|
|
17
|
+
.reduce((context, model) => {
|
|
18
|
+
return context.set(model, getJsonEntityStore(model));
|
|
19
|
+
}, new Map());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return store.$inherited;
|
|
23
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {DecoratorTypes, Type} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {JsonClassStore} from "../domain/JsonClassStore.js";
|
|
4
|
+
import {JsonEntitiesContainer, JsonEntityStore} from "../domain/JsonEntityStore.js";
|
|
5
|
+
import {JsonMethodStore} from "../domain/JsonMethodStore.js";
|
|
6
|
+
import {JsonParameterStore} from "../domain/JsonParameterStore.js";
|
|
7
|
+
import {JsonPropertyStore} from "../domain/JsonPropertyStore.js";
|
|
8
|
+
|
|
9
|
+
JsonEntitiesContainer.set(DecoratorTypes.CLASS, JsonClassStore);
|
|
10
|
+
JsonEntitiesContainer.set(DecoratorTypes.PROP, JsonPropertyStore);
|
|
11
|
+
JsonEntitiesContainer.set(DecoratorTypes.PARAM, JsonParameterStore);
|
|
12
|
+
JsonEntitiesContainer.set(DecoratorTypes.METHOD, JsonMethodStore);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Get entity store from decorator args
|
|
16
|
+
* @param target
|
|
17
|
+
*/
|
|
18
|
+
export function getJsonEntityStore<T extends JsonClassStore = JsonClassStore>(target: Type<any>): T;
|
|
19
|
+
export function getJsonEntityStore<T extends JsonPropertyStore = JsonPropertyStore>(
|
|
20
|
+
target: Type<any> | any,
|
|
21
|
+
propertyKey: string | symbol
|
|
22
|
+
): T;
|
|
23
|
+
export function getJsonEntityStore<T extends JsonParameterStore = JsonParameterStore>(
|
|
24
|
+
target: Type<any> | any,
|
|
25
|
+
propertyKey: string | symbol,
|
|
26
|
+
index: number
|
|
27
|
+
): T;
|
|
28
|
+
export function getJsonEntityStore<T extends JsonMethodStore = JsonMethodStore>(
|
|
29
|
+
target: Type<any> | any,
|
|
30
|
+
propertyKey: string | symbol,
|
|
31
|
+
descriptor: PropertyDescriptor
|
|
32
|
+
): T;
|
|
33
|
+
export function getJsonEntityStore<T extends JsonEntityStore = JsonEntityStore>(...args: any[]): T;
|
|
34
|
+
export function getJsonEntityStore<T extends JsonEntityStore = JsonEntityStore>(...args: any[]): T {
|
|
35
|
+
return JsonEntityStore.from<T>(...args);
|
|
36
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {getJsonPathParameters} from "./getJsonPathParameters.js";
|
|
2
|
+
|
|
3
|
+
describe("getJsonPathParameters", () => {
|
|
4
|
+
it("should return params and path(1)", () => {
|
|
5
|
+
expect(getJsonPathParameters("/rest/", "/get/:path1/:path2?")).toEqual([
|
|
6
|
+
{
|
|
7
|
+
path: "/rest/get/{path1}",
|
|
8
|
+
parameters: [
|
|
9
|
+
{
|
|
10
|
+
in: "path",
|
|
11
|
+
name: "path1",
|
|
12
|
+
required: true,
|
|
13
|
+
type: "string"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
path: "/rest/get/{path1}/{path2}",
|
|
19
|
+
parameters: [
|
|
20
|
+
{
|
|
21
|
+
in: "path",
|
|
22
|
+
name: "path1",
|
|
23
|
+
required: true,
|
|
24
|
+
type: "string"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
in: "path",
|
|
28
|
+
name: "path2",
|
|
29
|
+
required: true,
|
|
30
|
+
type: "string"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
]);
|
|
35
|
+
});
|
|
36
|
+
it("should return params and path(2)", () => {
|
|
37
|
+
expect(getJsonPathParameters("/rest/", "/get/:path1/:path2")).toEqual([
|
|
38
|
+
{
|
|
39
|
+
path: "/rest/get/{path1}/{path2}",
|
|
40
|
+
parameters: [
|
|
41
|
+
{
|
|
42
|
+
in: "path",
|
|
43
|
+
name: "path1",
|
|
44
|
+
required: true,
|
|
45
|
+
type: "string"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
in: "path",
|
|
49
|
+
name: "path2",
|
|
50
|
+
required: true,
|
|
51
|
+
type: "string"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
]);
|
|
56
|
+
});
|
|
57
|
+
it("should return params and path(3)", () => {
|
|
58
|
+
expect(getJsonPathParameters("/rest/", "/get/path1/path2")).toEqual([
|
|
59
|
+
{
|
|
60
|
+
path: "/rest/get/path1/path2",
|
|
61
|
+
parameters: []
|
|
62
|
+
}
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
it("should return params and path(4)", () => {
|
|
66
|
+
expect(getJsonPathParameters("/rest/calendar/", "/")).toEqual([
|
|
67
|
+
{
|
|
68
|
+
path: "/rest/calendar",
|
|
69
|
+
parameters: []
|
|
70
|
+
}
|
|
71
|
+
]);
|
|
72
|
+
});
|
|
73
|
+
it("should return params and path /file/:filename.json", () => {
|
|
74
|
+
expect(getJsonPathParameters("/rest/", "/file/:filename.json")).toEqual([
|
|
75
|
+
{
|
|
76
|
+
path: "/rest/file/{filename}.json",
|
|
77
|
+
parameters: [
|
|
78
|
+
{
|
|
79
|
+
in: "path",
|
|
80
|
+
name: "filename",
|
|
81
|
+
required: true,
|
|
82
|
+
type: "string"
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
]);
|
|
87
|
+
});
|
|
88
|
+
it("should return params and path /category/:category([a-zA-Z/_-]+).json", () => {
|
|
89
|
+
expect(getJsonPathParameters("/rest/", "/category/:category([a-zA-Z/_-]+).json")).toEqual([
|
|
90
|
+
{
|
|
91
|
+
path: "/rest/category/{category}.json",
|
|
92
|
+
parameters: [
|
|
93
|
+
{
|
|
94
|
+
in: "path",
|
|
95
|
+
name: "category",
|
|
96
|
+
required: true,
|
|
97
|
+
type: "string"
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
it("should return params and path /path/JQ=:id", () => {
|
|
104
|
+
expect(getJsonPathParameters("/rest/", "/path/JQ=:id")).toEqual([
|
|
105
|
+
{
|
|
106
|
+
path: "/rest/path/JQ={id}",
|
|
107
|
+
parameters: [
|
|
108
|
+
{
|
|
109
|
+
in: "path",
|
|
110
|
+
name: "id",
|
|
111
|
+
required: true,
|
|
112
|
+
type: "string"
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
]);
|
|
117
|
+
});
|
|
118
|
+
it("should return params and path regexp", () => {
|
|
119
|
+
expect(getJsonPathParameters("/rest/", /\*json$/)).toEqual([
|
|
120
|
+
{
|
|
121
|
+
parameters: [],
|
|
122
|
+
path: "/rest/*json$"
|
|
123
|
+
}
|
|
124
|
+
]);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ignore
|
|
3
|
+
*/
|
|
4
|
+
function getVariable(subpath: string) {
|
|
5
|
+
const [prefix, right] = subpath.split("=");
|
|
6
|
+
const splited = (right || prefix).split(".");
|
|
7
|
+
const name = splited.splice(0, 1)[0];
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
prefix: right && prefix ? `${prefix}=` : "",
|
|
11
|
+
name,
|
|
12
|
+
postfix: splited.length ? `.${splited.join(".")}` : ""
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function parseUrl(key: string) {
|
|
17
|
+
let inCapture = 0;
|
|
18
|
+
|
|
19
|
+
return key
|
|
20
|
+
.split("")
|
|
21
|
+
.filter((c) => {
|
|
22
|
+
if (c === "(") {
|
|
23
|
+
inCapture++;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const result = inCapture === 0;
|
|
27
|
+
|
|
28
|
+
if (c === ")") {
|
|
29
|
+
inCapture--;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return result;
|
|
33
|
+
})
|
|
34
|
+
.join("")
|
|
35
|
+
.split("/")
|
|
36
|
+
.filter((o) => !!o);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @ignore
|
|
41
|
+
*/
|
|
42
|
+
export function getJsonPathParameters(base: string, path: string | RegExp | (string | RegExp)[] = ""): {path: string; parameters: any[]}[] {
|
|
43
|
+
if (path instanceof RegExp) {
|
|
44
|
+
path = path.toString().replace(/^\//g, "").replace(/\/$/g, "").replace(/\\/g, "");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const params: any[] = [];
|
|
48
|
+
const paths: any[] = [];
|
|
49
|
+
let isOptional = false;
|
|
50
|
+
let current = "";
|
|
51
|
+
|
|
52
|
+
parseUrl(`${base}${path}`).map((key) => {
|
|
53
|
+
const subpath = key.replace(":", "").replace("?", "");
|
|
54
|
+
|
|
55
|
+
if (key.includes(":")) {
|
|
56
|
+
const optional = key.includes("?");
|
|
57
|
+
|
|
58
|
+
// Append previous config
|
|
59
|
+
if (optional && !isOptional) {
|
|
60
|
+
isOptional = true;
|
|
61
|
+
|
|
62
|
+
paths.push({
|
|
63
|
+
path: current,
|
|
64
|
+
parameters: [].concat(params as any)
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const {prefix, name, postfix} = getVariable(subpath);
|
|
69
|
+
current += `/${prefix}{${name}}${postfix}`;
|
|
70
|
+
|
|
71
|
+
params.push({
|
|
72
|
+
in: "path",
|
|
73
|
+
name,
|
|
74
|
+
type: "string",
|
|
75
|
+
required: true
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (optional && isOptional) {
|
|
79
|
+
paths.push({
|
|
80
|
+
path: current,
|
|
81
|
+
parameters: [].concat(params as any)
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
current += `/${key}`;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return paths.length
|
|
90
|
+
? paths
|
|
91
|
+
: [
|
|
92
|
+
{
|
|
93
|
+
path: current,
|
|
94
|
+
parameters: [].concat(params as any)
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
}
|