@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,40 @@
|
|
|
1
|
+
import {ContentType, getSpec, OperationPath, SpecTypes} from "../../index.js";
|
|
2
|
+
|
|
3
|
+
describe("ContentType", () => {
|
|
4
|
+
it("should create middleware", () => {
|
|
5
|
+
class Test {
|
|
6
|
+
@OperationPath("GET", "/")
|
|
7
|
+
@ContentType("application/json")
|
|
8
|
+
test() {}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const spec = getSpec(Test, {specType: SpecTypes.OPENAPI});
|
|
12
|
+
expect(spec).toEqual({
|
|
13
|
+
paths: {
|
|
14
|
+
"/": {
|
|
15
|
+
get: {
|
|
16
|
+
operationId: "testTest",
|
|
17
|
+
parameters: [],
|
|
18
|
+
responses: {
|
|
19
|
+
"200": {
|
|
20
|
+
content: {
|
|
21
|
+
"application/json": {
|
|
22
|
+
schema: {
|
|
23
|
+
type: "object"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
tags: ["Test"]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
tags: [
|
|
34
|
+
{
|
|
35
|
+
name: "Test"
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {Returns} from "./returns.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sets the Content-Type HTTP header to the MIME type as determined by mime.lookup() for the specified type.
|
|
5
|
+
* If type contains the “/” character, then it sets the `Content-Type` to type.
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @ContentType('.html'); // => 'text/html'
|
|
9
|
+
* @ContentType('html'); // => 'text/html'
|
|
10
|
+
* @ContentType('json'); // => 'application/json'
|
|
11
|
+
* @ContentType('application/json'); // => 'application/json'
|
|
12
|
+
* @ContentType('png'); // => image/png
|
|
13
|
+
* private myMethod() {}
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param type
|
|
17
|
+
* @decorator
|
|
18
|
+
* @operation
|
|
19
|
+
* @response
|
|
20
|
+
* @headers
|
|
21
|
+
*/
|
|
22
|
+
export function ContentType(type: string) {
|
|
23
|
+
return Returns().ContentType(type);
|
|
24
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import {catchError} from "@tsed/core";
|
|
2
|
+
import {QueryParams} from "@tsed/platform-params";
|
|
3
|
+
|
|
4
|
+
import {Deprecated, getSpec, OperationPath, Returns, SpecTypes} from "../../index.js";
|
|
5
|
+
|
|
6
|
+
describe("Deprecated", () => {
|
|
7
|
+
it("should store metadata (swagger)", () => {
|
|
8
|
+
class MyController {
|
|
9
|
+
@OperationPath("POST", "/")
|
|
10
|
+
@Deprecated(true)
|
|
11
|
+
get() {}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
expect(getSpec(MyController)).toEqual({
|
|
15
|
+
tags: [
|
|
16
|
+
{
|
|
17
|
+
name: "MyController"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
paths: {
|
|
21
|
+
"/": {
|
|
22
|
+
post: {
|
|
23
|
+
operationId: "myControllerGet",
|
|
24
|
+
parameters: [],
|
|
25
|
+
deprecated: true,
|
|
26
|
+
responses: {
|
|
27
|
+
"200": {
|
|
28
|
+
description: "Success"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
tags: ["MyController"]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
it("should store metadata (openspec)", () => {
|
|
38
|
+
class MyController {
|
|
39
|
+
@OperationPath("POST", "/")
|
|
40
|
+
@Deprecated()
|
|
41
|
+
get() {}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
expect(getSpec(MyController, {specType: SpecTypes.OPENAPI})).toEqual({
|
|
45
|
+
tags: [
|
|
46
|
+
{
|
|
47
|
+
name: "MyController"
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
paths: {
|
|
51
|
+
"/": {
|
|
52
|
+
post: {
|
|
53
|
+
operationId: "myControllerGet",
|
|
54
|
+
deprecated: true,
|
|
55
|
+
parameters: [],
|
|
56
|
+
responses: {
|
|
57
|
+
"200": {
|
|
58
|
+
description: "Success"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
tags: ["MyController"]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
it("should store metadata (class)", () => {
|
|
68
|
+
@Deprecated()
|
|
69
|
+
class MyController {
|
|
70
|
+
@OperationPath("GET", "/")
|
|
71
|
+
get() {}
|
|
72
|
+
|
|
73
|
+
@OperationPath("POST", "/")
|
|
74
|
+
post() {}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
expect(getSpec(MyController)).toEqual({
|
|
78
|
+
tags: [
|
|
79
|
+
{
|
|
80
|
+
name: "MyController"
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
paths: {
|
|
84
|
+
"/": {
|
|
85
|
+
get: {
|
|
86
|
+
operationId: "myControllerGet",
|
|
87
|
+
parameters: [],
|
|
88
|
+
deprecated: true,
|
|
89
|
+
responses: {
|
|
90
|
+
"200": {
|
|
91
|
+
description: "Success"
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
tags: ["MyController"]
|
|
95
|
+
},
|
|
96
|
+
post: {
|
|
97
|
+
operationId: "myControllerPost",
|
|
98
|
+
parameters: [],
|
|
99
|
+
deprecated: true,
|
|
100
|
+
responses: {
|
|
101
|
+
"200": {
|
|
102
|
+
description: "Success"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
tags: ["MyController"]
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
it("should store metadata (param)", () => {
|
|
112
|
+
class MyController {
|
|
113
|
+
@OperationPath("GET", "/")
|
|
114
|
+
get(@QueryParams("param") @Deprecated(true) param: string) {}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
expect(getSpec(MyController)).toEqual({
|
|
118
|
+
tags: [
|
|
119
|
+
{
|
|
120
|
+
name: "MyController"
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
paths: {
|
|
124
|
+
"/": {
|
|
125
|
+
get: {
|
|
126
|
+
operationId: "myControllerGet",
|
|
127
|
+
parameters: [
|
|
128
|
+
{
|
|
129
|
+
deprecated: true,
|
|
130
|
+
in: "query",
|
|
131
|
+
name: "param",
|
|
132
|
+
required: false,
|
|
133
|
+
schema: {
|
|
134
|
+
type: "string"
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
],
|
|
138
|
+
responses: {
|
|
139
|
+
"200": {
|
|
140
|
+
description: "Success"
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
tags: ["MyController"]
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
it("should store metadata (prop)", () => {
|
|
150
|
+
class MyModel {
|
|
151
|
+
@Deprecated()
|
|
152
|
+
myProp: string;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
class MyController {
|
|
156
|
+
@OperationPath("GET", "/")
|
|
157
|
+
@Returns(200, MyModel)
|
|
158
|
+
get(@QueryParams("param") @Deprecated(true) param: string) {}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
expect(getSpec(MyController)).toEqual({
|
|
162
|
+
tags: [
|
|
163
|
+
{
|
|
164
|
+
name: "MyController"
|
|
165
|
+
}
|
|
166
|
+
],
|
|
167
|
+
paths: {
|
|
168
|
+
"/": {
|
|
169
|
+
get: {
|
|
170
|
+
operationId: "myControllerGet",
|
|
171
|
+
parameters: [
|
|
172
|
+
{
|
|
173
|
+
deprecated: true,
|
|
174
|
+
in: "query",
|
|
175
|
+
name: "param",
|
|
176
|
+
required: false,
|
|
177
|
+
schema: {
|
|
178
|
+
type: "string"
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
responses: {
|
|
183
|
+
"200": {
|
|
184
|
+
description: "Success",
|
|
185
|
+
content: {
|
|
186
|
+
"application/json": {
|
|
187
|
+
schema: {
|
|
188
|
+
$ref: "#/components/schemas/MyModel"
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
tags: ["MyController"]
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
components: {
|
|
199
|
+
schemas: {
|
|
200
|
+
MyModel: {
|
|
201
|
+
type: "object",
|
|
202
|
+
properties: {
|
|
203
|
+
myProp: {
|
|
204
|
+
type: "string",
|
|
205
|
+
deprecated: true
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
it("should throw an error when the decorator is as static func decorator", () => {
|
|
214
|
+
const error = catchError(() => {
|
|
215
|
+
class Model {
|
|
216
|
+
@Deprecated(true)
|
|
217
|
+
static myStaticFunc() {}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
expect(error?.message).toEqual("Deprecated cannot be used as method.static decorator on Model.myStaticFunc");
|
|
222
|
+
});
|
|
223
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {decorateMethodsOf, decoratorTypeOf, DecoratorTypes, UnsupportedDecoratorType} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {JsonParameterStore} from "../../domain/JsonParameterStore.js";
|
|
4
|
+
import {JsonPropertyStore} from "../../domain/JsonPropertyStore.js";
|
|
5
|
+
import {JsonEntityFn} from "../common/jsonEntityFn.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Add deprecated metadata on the decorated element.
|
|
9
|
+
*
|
|
10
|
+
* ## Examples
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
*
|
|
14
|
+
* @Deprecated()
|
|
15
|
+
* class MyCtrl {
|
|
16
|
+
* @Deprecated()
|
|
17
|
+
* @Get("/")
|
|
18
|
+
* method(){
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @param deprecated
|
|
24
|
+
* @decorator
|
|
25
|
+
* @swagger
|
|
26
|
+
* @schema
|
|
27
|
+
* @operation
|
|
28
|
+
*/
|
|
29
|
+
export function Deprecated(deprecated: boolean = true) {
|
|
30
|
+
return JsonEntityFn((store, args) => {
|
|
31
|
+
switch (decoratorTypeOf(args)) {
|
|
32
|
+
case DecoratorTypes.METHOD:
|
|
33
|
+
store.operation!.deprecated(deprecated);
|
|
34
|
+
break;
|
|
35
|
+
case DecoratorTypes.CLASS:
|
|
36
|
+
decorateMethodsOf(args[0], Deprecated(deprecated));
|
|
37
|
+
break;
|
|
38
|
+
case DecoratorTypes.PARAM:
|
|
39
|
+
(store as JsonParameterStore).parameter.set("deprecated", deprecated);
|
|
40
|
+
break;
|
|
41
|
+
case DecoratorTypes.PROP:
|
|
42
|
+
(store as JsonPropertyStore).schema.set("deprecated", deprecated);
|
|
43
|
+
break;
|
|
44
|
+
|
|
45
|
+
default:
|
|
46
|
+
throw new UnsupportedDecoratorType(Deprecated, args);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import {getSpec, OperationPath, SpecTypes} from "../../index.js";
|
|
2
|
+
import {Header} from "./header.js";
|
|
3
|
+
|
|
4
|
+
describe("Header", () => {
|
|
5
|
+
describe("when is used as method decorator", () => {
|
|
6
|
+
describe("with one params has object", () => {
|
|
7
|
+
it("should set Header", () => {
|
|
8
|
+
class MyController {
|
|
9
|
+
@Header({"Content-Type": "application/json"})
|
|
10
|
+
@OperationPath("GET", "/")
|
|
11
|
+
test() {}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const spec = getSpec(MyController, {specType: SpecTypes.OPENAPI});
|
|
15
|
+
|
|
16
|
+
expect(spec).toEqual({
|
|
17
|
+
paths: {
|
|
18
|
+
"/": {
|
|
19
|
+
get: {
|
|
20
|
+
operationId: "myControllerTest",
|
|
21
|
+
parameters: [],
|
|
22
|
+
responses: {
|
|
23
|
+
"200": {
|
|
24
|
+
content: {
|
|
25
|
+
"*/*": {
|
|
26
|
+
schema: {
|
|
27
|
+
type: "object"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
headers: {
|
|
32
|
+
"Content-Type": {
|
|
33
|
+
example: "application/json",
|
|
34
|
+
schema: {
|
|
35
|
+
type: "string"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
tags: ["MyController"]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
tags: [
|
|
46
|
+
{
|
|
47
|
+
name: "MyController"
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe("with one param as string", () => {
|
|
54
|
+
it("should set Header", () => {
|
|
55
|
+
class MyController {
|
|
56
|
+
@Header("x-header")
|
|
57
|
+
@OperationPath("GET", "/")
|
|
58
|
+
test() {}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const spec = getSpec(MyController, {specType: SpecTypes.OPENAPI});
|
|
62
|
+
|
|
63
|
+
expect(spec).toEqual({
|
|
64
|
+
paths: {
|
|
65
|
+
"/": {
|
|
66
|
+
get: {
|
|
67
|
+
operationId: "myControllerTest",
|
|
68
|
+
parameters: [],
|
|
69
|
+
responses: {
|
|
70
|
+
"200": {
|
|
71
|
+
content: {
|
|
72
|
+
"*/*": {
|
|
73
|
+
schema: {
|
|
74
|
+
type: "object"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
headers: {
|
|
79
|
+
"x-header": {
|
|
80
|
+
schema: {
|
|
81
|
+
type: "string"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
tags: ["MyController"]
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
tags: [
|
|
92
|
+
{
|
|
93
|
+
name: "MyController"
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe("with two params has object", () => {
|
|
100
|
+
it("should set Header", () => {
|
|
101
|
+
class MyController {
|
|
102
|
+
@OperationPath("GET", "/")
|
|
103
|
+
@Header("Content-Type", "application/json")
|
|
104
|
+
test() {}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const spec = getSpec(MyController, {specType: SpecTypes.OPENAPI});
|
|
108
|
+
|
|
109
|
+
expect(spec).toEqual({
|
|
110
|
+
paths: {
|
|
111
|
+
"/": {
|
|
112
|
+
get: {
|
|
113
|
+
operationId: "myControllerTest",
|
|
114
|
+
parameters: [],
|
|
115
|
+
responses: {
|
|
116
|
+
"200": {
|
|
117
|
+
content: {
|
|
118
|
+
"*/*": {
|
|
119
|
+
schema: {
|
|
120
|
+
type: "object"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
headers: {
|
|
125
|
+
"Content-Type": {
|
|
126
|
+
example: "application/json",
|
|
127
|
+
schema: {
|
|
128
|
+
type: "string"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
tags: ["MyController"]
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
tags: [
|
|
139
|
+
{
|
|
140
|
+
name: "MyController"
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
describe("with swagger params has object", () => {
|
|
147
|
+
it("should set Header", () => {
|
|
148
|
+
class MyController {
|
|
149
|
+
@OperationPath("GET", "/")
|
|
150
|
+
@Header({
|
|
151
|
+
"Content-Type": "text/plain",
|
|
152
|
+
"Content-Length": 123,
|
|
153
|
+
ETag: {
|
|
154
|
+
value: "12345",
|
|
155
|
+
description: "header description"
|
|
156
|
+
}
|
|
157
|
+
} as any)
|
|
158
|
+
test() {}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const spec = getSpec(MyController, {specType: SpecTypes.OPENAPI});
|
|
162
|
+
|
|
163
|
+
expect(spec).toEqual({
|
|
164
|
+
paths: {
|
|
165
|
+
"/": {
|
|
166
|
+
get: {
|
|
167
|
+
operationId: "myControllerTest",
|
|
168
|
+
parameters: [],
|
|
169
|
+
responses: {
|
|
170
|
+
"200": {
|
|
171
|
+
content: {
|
|
172
|
+
"*/*": {
|
|
173
|
+
schema: {
|
|
174
|
+
type: "object"
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
headers: {
|
|
179
|
+
"Content-Length": {
|
|
180
|
+
example: 123,
|
|
181
|
+
schema: {
|
|
182
|
+
type: "number"
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
"Content-Type": {
|
|
186
|
+
example: "text/plain",
|
|
187
|
+
schema: {
|
|
188
|
+
type: "string"
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
ETag: {
|
|
192
|
+
description: "header description",
|
|
193
|
+
example: "12345",
|
|
194
|
+
schema: {
|
|
195
|
+
type: "string"
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
tags: ["MyController"]
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
tags: [
|
|
206
|
+
{
|
|
207
|
+
name: "MyController"
|
|
208
|
+
}
|
|
209
|
+
]
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {isString} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {JsonHeader, JsonHeaders} from "../../interfaces/JsonOpenSpec.js";
|
|
4
|
+
import {Returns} from "./returns.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Sets the response’s HTTP header field to value. To set multiple fields at once, pass an object as the parameter.
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* @Header('Content-Type', 'text/plain');
|
|
11
|
+
* private myMethod() {}
|
|
12
|
+
*
|
|
13
|
+
* @Status(204)
|
|
14
|
+
* @Header({
|
|
15
|
+
* "Content-Type": "text/plain",
|
|
16
|
+
* "Content-Length": 123,
|
|
17
|
+
* "ETag": {
|
|
18
|
+
* "value": "12345",
|
|
19
|
+
* "description": "header description"
|
|
20
|
+
* }
|
|
21
|
+
* })
|
|
22
|
+
* private myMethod() {}
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* This example will produce the swagger responses object:
|
|
26
|
+
*
|
|
27
|
+
* ```json
|
|
28
|
+
* {
|
|
29
|
+
* "responses": {
|
|
30
|
+
* "204": {
|
|
31
|
+
* "description": "Description",
|
|
32
|
+
* "headers": {
|
|
33
|
+
* "Content-Type": {
|
|
34
|
+
* "type": "string"
|
|
35
|
+
* },
|
|
36
|
+
* "Content-Length": {
|
|
37
|
+
* "type": "number"
|
|
38
|
+
* },
|
|
39
|
+
* "ETag": {
|
|
40
|
+
* "type": "string",
|
|
41
|
+
* "description": "header description"
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @decorator
|
|
50
|
+
* @operation
|
|
51
|
+
* @response
|
|
52
|
+
*/
|
|
53
|
+
export function Header(headers: string | number | JsonHeaders, value?: string | number | JsonHeader): Function {
|
|
54
|
+
if (value !== undefined) {
|
|
55
|
+
headers = {[headers as string]: value};
|
|
56
|
+
}
|
|
57
|
+
if (value === undefined && isString(headers)) {
|
|
58
|
+
headers = {[headers as string]: {type: "string"}};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return Returns().Headers(headers as JsonHeaders);
|
|
62
|
+
}
|