@tsed/schema 8.0.1 → 8.0.3
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/readme.md +6 -6
- 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,27 @@
|
|
|
1
|
+
import {DecoratorTypes, UnsupportedDecoratorType} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {JsonEntityFn} from "../common/jsonEntityFn.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Set class path to expose all endpoints
|
|
7
|
+
*
|
|
8
|
+
* ::: warning
|
|
9
|
+
* Don't use this decorator to change the path if you develop your application with Ts.ED.
|
|
10
|
+
* :::
|
|
11
|
+
*
|
|
12
|
+
* @param path
|
|
13
|
+
* @decorator
|
|
14
|
+
* @swagger
|
|
15
|
+
* @schema
|
|
16
|
+
* @classDecorator
|
|
17
|
+
* @operation
|
|
18
|
+
*/
|
|
19
|
+
export function Path(path: string) {
|
|
20
|
+
return JsonEntityFn((store, args) => {
|
|
21
|
+
if (store.decoratorType !== DecoratorTypes.CLASS) {
|
|
22
|
+
throw new UnsupportedDecoratorType(Path, args);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
store.path = path;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {getSpec, OperationPath, Produces, SpecTypes} from "../../index.js";
|
|
2
|
+
|
|
3
|
+
describe("Produces", () => {
|
|
4
|
+
it("should store metadata", () => {
|
|
5
|
+
class MyController {
|
|
6
|
+
@OperationPath("POST", "/")
|
|
7
|
+
@Produces("text/json")
|
|
8
|
+
get() {}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
expect(getSpec(MyController, {specType: SpecTypes.OPENAPI})).toEqual({
|
|
12
|
+
tags: [
|
|
13
|
+
{
|
|
14
|
+
name: "MyController"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
paths: {
|
|
18
|
+
"/": {
|
|
19
|
+
post: {
|
|
20
|
+
operationId: "myControllerGet",
|
|
21
|
+
parameters: [],
|
|
22
|
+
responses: {
|
|
23
|
+
"200": {
|
|
24
|
+
description: "Success"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
tags: ["MyController"]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
it("should store metadata (class)", () => {
|
|
34
|
+
@Produces("text/json")
|
|
35
|
+
class MyController {
|
|
36
|
+
@OperationPath("GET", "/")
|
|
37
|
+
get() {}
|
|
38
|
+
|
|
39
|
+
@OperationPath("POST", "/")
|
|
40
|
+
post() {}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
expect(getSpec(MyController, {specType: SpecTypes.OPENAPI})).toEqual({
|
|
44
|
+
paths: {
|
|
45
|
+
"/": {
|
|
46
|
+
get: {
|
|
47
|
+
operationId: "myControllerGet",
|
|
48
|
+
parameters: [],
|
|
49
|
+
responses: {
|
|
50
|
+
"200": {
|
|
51
|
+
description: "Success"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
tags: ["MyController"]
|
|
55
|
+
},
|
|
56
|
+
post: {
|
|
57
|
+
operationId: "myControllerPost",
|
|
58
|
+
parameters: [],
|
|
59
|
+
responses: {
|
|
60
|
+
"200": {
|
|
61
|
+
description: "Success"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
tags: ["MyController"]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
tags: [
|
|
69
|
+
{
|
|
70
|
+
name: "MyController"
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
it("should throw error for unsupported usage", () => {
|
|
76
|
+
class Test {
|
|
77
|
+
test() {}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let actualError: any;
|
|
81
|
+
try {
|
|
82
|
+
Produces("text/json")(Test.prototype, "test", 0);
|
|
83
|
+
} catch (er) {
|
|
84
|
+
actualError = er;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
expect(actualError.message).toEqual("Produces cannot be used as parameter decorator on Test.test.[0]");
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {decorateMethodsOf, DecoratorTypes, UnsupportedDecoratorType} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {JsonEntityFn} from "../common/jsonEntityFn.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Add produces metadata on the decorated element.
|
|
7
|
+
*
|
|
8
|
+
* ## Examples
|
|
9
|
+
* ### On method
|
|
10
|
+
*
|
|
11
|
+
* ```typescript
|
|
12
|
+
* class Model {
|
|
13
|
+
* @Produces("text/html")
|
|
14
|
+
* id: string;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* ::: warning
|
|
19
|
+
* For openspec v3 prefer `@Returns().ContentType()` usage (see @@Returns@@).
|
|
20
|
+
* :::
|
|
21
|
+
*
|
|
22
|
+
* @param produces
|
|
23
|
+
* @decorator
|
|
24
|
+
* @swagger
|
|
25
|
+
* @methodDecorator
|
|
26
|
+
* @classDecorator
|
|
27
|
+
* @operation
|
|
28
|
+
* @response
|
|
29
|
+
*/
|
|
30
|
+
export function Produces(...produces: string[]) {
|
|
31
|
+
return JsonEntityFn((store, args) => {
|
|
32
|
+
switch (store.decoratorType) {
|
|
33
|
+
case DecoratorTypes.METHOD:
|
|
34
|
+
store.operation!.produces(produces);
|
|
35
|
+
break;
|
|
36
|
+
case DecoratorTypes.CLASS:
|
|
37
|
+
decorateMethodsOf(args[0], Produces(...produces));
|
|
38
|
+
break;
|
|
39
|
+
|
|
40
|
+
default:
|
|
41
|
+
throw new UnsupportedDecoratorType(Produces, args);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "../../index.js";
|
|
2
|
+
|
|
3
|
+
import {OperationVerbs} from "../../constants/OperationVerbs.js";
|
|
4
|
+
import {JsonEntityStore} from "../../domain/JsonEntityStore.js";
|
|
5
|
+
import {Publish} from "./publish.js";
|
|
6
|
+
|
|
7
|
+
describe("Publish", () => {
|
|
8
|
+
it("should register operation with Publish verb", () => {
|
|
9
|
+
// WHEN
|
|
10
|
+
class Test {
|
|
11
|
+
@Publish("event")
|
|
12
|
+
test() {}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const endpoint = JsonEntityStore.fromMethod(Test, "test");
|
|
16
|
+
|
|
17
|
+
// THEN
|
|
18
|
+
expect([...endpoint.operation!.operationPaths.values()]).toEqual([
|
|
19
|
+
{
|
|
20
|
+
method: OperationVerbs.PUBLISH,
|
|
21
|
+
path: "event"
|
|
22
|
+
}
|
|
23
|
+
]);
|
|
24
|
+
expect(endpoint.propertyKey).toBe("test");
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import {getSpec, OperationPath, SpecTypes} from "../../index.js";
|
|
2
|
+
import {Redirect} from "./redirect.js";
|
|
3
|
+
|
|
4
|
+
describe("Redirect", () => {
|
|
5
|
+
it("should set header with path only", () => {
|
|
6
|
+
class MyController {
|
|
7
|
+
@Redirect("/path/to")
|
|
8
|
+
@OperationPath("GET", "/")
|
|
9
|
+
test() {}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const spec = getSpec(MyController, {specType: SpecTypes.OPENAPI});
|
|
13
|
+
|
|
14
|
+
expect(spec).toEqual({
|
|
15
|
+
paths: {
|
|
16
|
+
"/": {
|
|
17
|
+
get: {
|
|
18
|
+
operationId: "myControllerTest",
|
|
19
|
+
parameters: [],
|
|
20
|
+
responses: {
|
|
21
|
+
"302": {
|
|
22
|
+
content: {
|
|
23
|
+
"*/*": {
|
|
24
|
+
schema: {
|
|
25
|
+
type: "object"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
description: "Found",
|
|
30
|
+
headers: {
|
|
31
|
+
Location: {
|
|
32
|
+
example: "/path/to",
|
|
33
|
+
schema: {
|
|
34
|
+
type: "string"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
tags: ["MyController"]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
tags: [
|
|
45
|
+
{
|
|
46
|
+
name: "MyController"
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
it("should set header with path and status", () => {
|
|
52
|
+
class MyController {
|
|
53
|
+
@Redirect(301, "/path/to")
|
|
54
|
+
@OperationPath("GET", "/")
|
|
55
|
+
test() {}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const spec = getSpec(MyController, {specType: SpecTypes.OPENAPI});
|
|
59
|
+
|
|
60
|
+
expect(spec).toEqual({
|
|
61
|
+
paths: {
|
|
62
|
+
"/": {
|
|
63
|
+
get: {
|
|
64
|
+
operationId: "myControllerTest",
|
|
65
|
+
parameters: [],
|
|
66
|
+
responses: {
|
|
67
|
+
"301": {
|
|
68
|
+
content: {
|
|
69
|
+
"*/*": {
|
|
70
|
+
schema: {
|
|
71
|
+
type: "object"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
description: "Moved Permanently",
|
|
76
|
+
headers: {
|
|
77
|
+
Location: {
|
|
78
|
+
example: "/path/to",
|
|
79
|
+
schema: {
|
|
80
|
+
type: "string"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
tags: ["MyController"]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
tags: [
|
|
91
|
+
{
|
|
92
|
+
name: "MyController"
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
it("should set header with path and status and meta", () => {
|
|
98
|
+
class MyController {
|
|
99
|
+
@Redirect(301, "/path/to", {
|
|
100
|
+
description: "Test description"
|
|
101
|
+
})
|
|
102
|
+
@OperationPath("GET", "/")
|
|
103
|
+
test() {}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const spec = getSpec(MyController, {specType: SpecTypes.OPENAPI});
|
|
107
|
+
|
|
108
|
+
expect(spec).toEqual({
|
|
109
|
+
paths: {
|
|
110
|
+
"/": {
|
|
111
|
+
get: {
|
|
112
|
+
operationId: "myControllerTest",
|
|
113
|
+
parameters: [],
|
|
114
|
+
responses: {
|
|
115
|
+
"301": {
|
|
116
|
+
content: {
|
|
117
|
+
"*/*": {
|
|
118
|
+
schema: {
|
|
119
|
+
type: "object"
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
description: "Moved Permanently",
|
|
124
|
+
headers: {
|
|
125
|
+
Location: {
|
|
126
|
+
description: "Test description",
|
|
127
|
+
example: "/path/to",
|
|
128
|
+
schema: {
|
|
129
|
+
type: "string"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
tags: ["MyController"]
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
tags: [
|
|
140
|
+
{
|
|
141
|
+
name: "MyController"
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {isNumber, isString, useDecorators} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {JsonHeader} from "../../interfaces/JsonOpenSpec.js";
|
|
4
|
+
import {JsonEntityFn} from "../common/jsonEntityFn.js";
|
|
5
|
+
import {Returns} from "./returns.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an HTTP status code . If not specified, status defaults to “302 “Found”.
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @Redirect('/foo/bar')
|
|
12
|
+
* @Redirect(301, 'http://example.com').Type(Model)
|
|
13
|
+
* private myMethod() {}
|
|
14
|
+
* ```
|
|
15
|
+
* Redirects can be a fully-qualified URL for redirecting to a different site:
|
|
16
|
+
*
|
|
17
|
+
* ```typescript
|
|
18
|
+
* @Redirect('http://google.com');
|
|
19
|
+
* private myMethod() {}
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Redirects can be relative to the root of the host name. For example, if the application is on http://example.com/admin/post/new, the following would redirect to the URL http://example.com/admin:
|
|
23
|
+
*
|
|
24
|
+
* ```typescript
|
|
25
|
+
* @Redirect('/admin');
|
|
26
|
+
* ```
|
|
27
|
+
* Redirects can be relative to the current URL. For example, from http://example.com/blog/admin/ (notice the trailing slash), the following would redirect to the URL http://example.com/blog/admin/post/new.
|
|
28
|
+
*
|
|
29
|
+
* ```typescript
|
|
30
|
+
* @Redirect('post/new');
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* Redirecting to post/new from http://example.com/blog/admin (no trailing slash), will redirect to http://example.com/blog/post/new.
|
|
34
|
+
*
|
|
35
|
+
* If you found the above behavior confusing, think of path segments as directories (with trailing slashes) and files, it will start to make sense.
|
|
36
|
+
*
|
|
37
|
+
* Path-relative redirects are also possible. If you were on http://example.com/admin/post/new, the following would redirect to http//example.com/admin/post:
|
|
38
|
+
*
|
|
39
|
+
* ```typescript
|
|
40
|
+
* @Redirect('..');
|
|
41
|
+
* ``
|
|
42
|
+
*
|
|
43
|
+
* A back redirection redirects the request back to the referer, defaulting to / when the referer is missing.
|
|
44
|
+
*
|
|
45
|
+
* ```typescript
|
|
46
|
+
* @Redirect('back');
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param url
|
|
50
|
+
* @param meta
|
|
51
|
+
* @decorator
|
|
52
|
+
* @operation
|
|
53
|
+
* @response
|
|
54
|
+
* @headers
|
|
55
|
+
*/
|
|
56
|
+
export function Redirect(url: string, meta?: JsonHeader): Function;
|
|
57
|
+
export function Redirect(status: number, url: string, meta?: JsonHeader): Function;
|
|
58
|
+
export function Redirect(...args: any[]): Function {
|
|
59
|
+
const {status, url, meta} = args.reduce(
|
|
60
|
+
(options: any, value: any) => {
|
|
61
|
+
if (isNumber(value)) {
|
|
62
|
+
options.status = value;
|
|
63
|
+
return options;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (isString(value)) {
|
|
67
|
+
options.url = value;
|
|
68
|
+
return options;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
options.meta = value;
|
|
72
|
+
return options;
|
|
73
|
+
},
|
|
74
|
+
{status: 302, url: "", meta: {}}
|
|
75
|
+
);
|
|
76
|
+
return useDecorators(
|
|
77
|
+
Returns(status).Location(url, meta),
|
|
78
|
+
JsonEntityFn((entity) => {
|
|
79
|
+
entity.operation?.setRedirection(status);
|
|
80
|
+
})
|
|
81
|
+
);
|
|
82
|
+
}
|