@tsed/schema 8.0.1 → 8.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -10
- package/src/components/async-api/channelsMapper.ts +81 -0
- package/src/components/async-api/generate.ts +24 -0
- package/src/components/async-api/messageMapper.ts +62 -0
- package/src/components/async-api/payloadMapper.ts +61 -0
- package/src/components/async-api/responseMapper.ts +70 -0
- package/src/components/default/anyMapper.spec.ts +7 -0
- package/src/components/default/anyMapper.ts +33 -0
- package/src/components/default/classMapper.ts +55 -0
- package/src/components/default/discriminatorMappingMapper.ts +36 -0
- package/src/components/default/enumsMapper.spec.ts +64 -0
- package/src/components/default/enumsMapper.ts +17 -0
- package/src/components/default/genericsMapper.ts +70 -0
- package/src/components/default/inheritedClassMapper.ts +24 -0
- package/src/components/default/itemMapper.ts +8 -0
- package/src/components/default/lazyRefMapper.ts +21 -0
- package/src/components/default/mapMapper.ts +25 -0
- package/src/components/default/nullableMapper.ts +55 -0
- package/src/components/default/objectMapper.ts +36 -0
- package/src/components/default/ofMapper.ts +16 -0
- package/src/components/default/propertiesMapper.ts +25 -0
- package/src/components/default/requiredMapper.ts +69 -0
- package/src/components/default/schemaMapper.ts +151 -0
- package/src/components/index.ts +36 -0
- package/src/components/open-spec/discriminatorMappingMapper.ts +7 -0
- package/src/components/open-spec/enumsMapper.ts +20 -0
- package/src/components/open-spec/generate.ts +29 -0
- package/src/components/open-spec/nullableMapper.ts +51 -0
- package/src/components/open-spec/operationInFilesMapper.ts +32 -0
- package/src/components/open-spec/operationInParameterMapper.ts +56 -0
- package/src/components/open-spec/operationInParametersMapper.ts +9 -0
- package/src/components/open-spec/operationInQueryMapper.ts +74 -0
- package/src/components/open-spec/operationMapper.ts +65 -0
- package/src/components/open-spec/operationMediaMapper.ts +11 -0
- package/src/components/open-spec/operationRequestBodyMapper.ts +82 -0
- package/src/components/open-spec/operationResponseMapper.ts +26 -0
- package/src/components/open-spec/pathsMapper.ts +132 -0
- package/src/constants/OperationVerbs.ts +29 -0
- package/src/constants/httpStatusMessages.ts +21 -0
- package/src/constants/jsonSchemaProperties.ts +17 -0
- package/src/decorators/class/children.ts +22 -0
- package/src/decorators/class/discriminatorValue.ts +53 -0
- package/src/decorators/collections/collectionContains.ts +25 -0
- package/src/decorators/collections/collectionOf.spec.ts +327 -0
- package/src/decorators/collections/collectionOf.ts +182 -0
- package/src/decorators/collections/maxItems.spec.ts +40 -0
- package/src/decorators/collections/maxItems.ts +59 -0
- package/src/decorators/collections/maxProperties.spec.ts +109 -0
- package/src/decorators/collections/maxProperties.ts +82 -0
- package/src/decorators/collections/minItems.spec.ts +40 -0
- package/src/decorators/collections/minItems.ts +63 -0
- package/src/decorators/collections/minProperties.spec.ts +109 -0
- package/src/decorators/collections/minProperties.ts +81 -0
- package/src/decorators/collections/uniqueItems.spec.ts +28 -0
- package/src/decorators/collections/uniqueItems.ts +59 -0
- package/src/decorators/common/__snapshots__/groups.spec.ts.snap +321 -0
- package/src/decorators/common/additionalProperties.spec.ts +133 -0
- package/src/decorators/common/additionalProperties.ts +17 -0
- package/src/decorators/common/allOf.spec.ts +276 -0
- package/src/decorators/common/allOf.ts +19 -0
- package/src/decorators/common/allow.spec.ts +130 -0
- package/src/decorators/common/allow.ts +50 -0
- package/src/decorators/common/any.spec.ts +109 -0
- package/src/decorators/common/any.ts +45 -0
- package/src/decorators/common/anyOf.spec.ts +270 -0
- package/src/decorators/common/anyOf.ts +23 -0
- package/src/decorators/common/const.spec.ts +98 -0
- package/src/decorators/common/const.ts +68 -0
- package/src/decorators/common/customKey.spec.ts +105 -0
- package/src/decorators/common/customKey.ts +39 -0
- package/src/decorators/common/default.spec.ts +25 -0
- package/src/decorators/common/default.ts +47 -0
- package/src/decorators/common/defaultMsg.spec.ts +22 -0
- package/src/decorators/common/defaultMsg.ts +38 -0
- package/src/decorators/common/description.spec.ts +166 -0
- package/src/decorators/common/description.ts +77 -0
- package/src/decorators/common/discriminatorKey.ts +14 -0
- package/src/decorators/common/enum.spec.ts +305 -0
- package/src/decorators/common/enum.ts +111 -0
- package/src/decorators/common/errorMsg.spec.ts +57 -0
- package/src/decorators/common/errorMsg.ts +14 -0
- package/src/decorators/common/example.spec.ts +93 -0
- package/src/decorators/common/example.ts +18 -0
- package/src/decorators/common/examples.spec.ts +101 -0
- package/src/decorators/common/examples.ts +20 -0
- package/src/decorators/common/exclusiveMaximum.spec.ts +47 -0
- package/src/decorators/common/exclusiveMaximum.ts +75 -0
- package/src/decorators/common/exclusiveMinimum.spec.ts +47 -0
- package/src/decorators/common/exclusiveMinimum.ts +75 -0
- package/src/decorators/common/format.spec.ts +149 -0
- package/src/decorators/common/format.ts +486 -0
- package/src/decorators/common/forwardGroups.spec.ts +270 -0
- package/src/decorators/common/forwardGroups.ts +16 -0
- package/src/decorators/common/groups.spec.ts +968 -0
- package/src/decorators/common/groups.ts +66 -0
- package/src/decorators/common/hidden.spec.ts +52 -0
- package/src/decorators/common/hidden.ts +36 -0
- package/src/decorators/common/ignore.spec.ts +88 -0
- package/src/decorators/common/ignore.ts +66 -0
- package/src/decorators/common/integer.spec.ts +110 -0
- package/src/decorators/common/integer.ts +69 -0
- package/src/decorators/common/jsonEntityFn.spec.ts +16 -0
- package/src/decorators/common/jsonEntityFn.ts +33 -0
- package/src/decorators/common/maxLength.spec.ts +61 -0
- package/src/decorators/common/maxLength.ts +88 -0
- package/src/decorators/common/maximum.spec.ts +73 -0
- package/src/decorators/common/maximum.ts +146 -0
- package/src/decorators/common/minLength.spec.ts +186 -0
- package/src/decorators/common/minLength.ts +89 -0
- package/src/decorators/common/minimum.spec.ts +74 -0
- package/src/decorators/common/minimum.ts +145 -0
- package/src/decorators/common/multipleOf.spec.ts +33 -0
- package/src/decorators/common/multipleOf.ts +80 -0
- package/src/decorators/common/name.spec.ts +56 -0
- package/src/decorators/common/name.ts +50 -0
- package/src/decorators/common/nullable.spec.ts +818 -0
- package/src/decorators/common/nullable.ts +32 -0
- package/src/decorators/common/oneOf.spec.ts +301 -0
- package/src/decorators/common/oneOf.ts +24 -0
- package/src/decorators/common/optional.spec.ts +43 -0
- package/src/decorators/common/optional.ts +26 -0
- package/src/decorators/common/pattern.spec.ts +27 -0
- package/src/decorators/common/pattern.ts +102 -0
- package/src/decorators/common/property.ts +24 -0
- package/src/decorators/common/readOnly.spec.ts +135 -0
- package/src/decorators/common/readOnly.ts +17 -0
- package/src/decorators/common/recordOf.spec.ts +41 -0
- package/src/decorators/common/recordOf.ts +59 -0
- package/src/decorators/common/required.spec.ts +188 -0
- package/src/decorators/common/required.ts +50 -0
- package/src/decorators/common/requiredGroups.spec.ts +127 -0
- package/src/decorators/common/requiredGroups.ts +23 -0
- package/src/decorators/common/schema.spec.ts +23 -0
- package/src/decorators/common/schema.ts +64 -0
- package/src/decorators/common/title.spec.ts +20 -0
- package/src/decorators/common/title.ts +45 -0
- package/src/decorators/common/typeError.spec.ts +22 -0
- package/src/decorators/common/typeError.ts +15 -0
- package/src/decorators/common/writeOnly.spec.ts +105 -0
- package/src/decorators/common/writeOnly.ts +17 -0
- package/src/decorators/config/jsonEntityComponent.ts +16 -0
- package/src/decorators/generics/genericOf.spec.ts +246 -0
- package/src/decorators/generics/genericOf.ts +112 -0
- package/src/decorators/generics/generics.ts +22 -0
- package/src/decorators/operations/acceptMime.spec.ts +39 -0
- package/src/decorators/operations/acceptMime.ts +25 -0
- package/src/decorators/operations/consumes.spec.ts +89 -0
- package/src/decorators/operations/consumes.ts +37 -0
- package/src/decorators/operations/contentType.spec.ts +40 -0
- package/src/decorators/operations/contentType.ts +24 -0
- package/src/decorators/operations/deprecated.spec.ts +223 -0
- package/src/decorators/operations/deprecated.ts +49 -0
- package/src/decorators/operations/header.spec.ts +214 -0
- package/src/decorators/operations/header.ts +62 -0
- package/src/decorators/operations/in.spec.ts +321 -0
- package/src/decorators/operations/in.ts +141 -0
- package/src/decorators/operations/inFile.spec.ts +209 -0
- package/src/decorators/operations/inFile.ts +55 -0
- package/src/decorators/operations/location.spec.ts +51 -0
- package/src/decorators/operations/location.ts +26 -0
- package/src/decorators/operations/operation.ts +119 -0
- package/src/decorators/operations/operationId.spec.ts +43 -0
- package/src/decorators/operations/operationId.ts +22 -0
- package/src/decorators/operations/operationPath.spec.ts +42 -0
- package/src/decorators/operations/operationPath.ts +33 -0
- package/src/decorators/operations/partial.spec.ts +249 -0
- package/src/decorators/operations/partial.ts +14 -0
- package/src/decorators/operations/path.spec.ts +47 -0
- package/src/decorators/operations/path.ts +27 -0
- package/src/decorators/operations/produces.spec.ts +89 -0
- package/src/decorators/operations/produces.ts +44 -0
- package/src/decorators/operations/publish.spec.ts +26 -0
- package/src/decorators/operations/publish.ts +6 -0
- package/src/decorators/operations/redirect.spec.ts +146 -0
- package/src/decorators/operations/redirect.ts +82 -0
- package/src/decorators/operations/returns.spec.ts +1393 -0
- package/src/decorators/operations/returns.ts +662 -0
- package/src/decorators/operations/route.spec.ts +211 -0
- package/src/decorators/operations/route.ts +154 -0
- package/src/decorators/operations/security.spec.ts +162 -0
- package/src/decorators/operations/security.ts +83 -0
- package/src/decorators/operations/status.spec.ts +582 -0
- package/src/decorators/operations/status.ts +130 -0
- package/src/decorators/operations/subscribe.spec.ts +32 -0
- package/src/decorators/operations/subscribe.ts +6 -0
- package/src/decorators/operations/summary.spec.ts +45 -0
- package/src/decorators/operations/summary.ts +32 -0
- package/src/decorators/operations/tags.spec.ts +113 -0
- package/src/decorators/operations/tags.ts +53 -0
- package/src/decorators/operations/view.spec.ts +16 -0
- package/src/decorators/operations/view.ts +27 -0
- package/src/domain/DecoratorContext.ts +116 -0
- package/src/domain/JsonAliasMap.ts +19 -0
- package/src/domain/JsonClassStore.ts +35 -0
- package/src/domain/JsonDiscriminator.spec.ts +65 -0
- package/src/domain/JsonDiscriminator.ts +52 -0
- package/src/domain/JsonEntityStore.spec.ts +277 -0
- package/src/domain/JsonEntityStore.ts +284 -0
- package/src/domain/JsonFormatTypes.ts +17 -0
- package/src/domain/JsonLazyRef.ts +21 -0
- package/src/domain/JsonMap.spec.ts +15 -0
- package/src/domain/JsonMap.ts +33 -0
- package/src/domain/JsonMedia.ts +24 -0
- package/src/domain/JsonMethodStore.spec.ts +301 -0
- package/src/domain/JsonMethodStore.ts +212 -0
- package/src/domain/JsonOperation.spec.ts +126 -0
- package/src/domain/JsonOperation.ts +219 -0
- package/src/domain/JsonOperationPathsMap.ts +16 -0
- package/src/domain/JsonOperationRoute.spec.ts +109 -0
- package/src/domain/JsonOperationRoute.ts +75 -0
- package/src/domain/JsonParameter.ts +70 -0
- package/src/domain/JsonParameterStore.spec.ts +212 -0
- package/src/domain/JsonParameterStore.ts +138 -0
- package/src/domain/JsonParameterTypes.spec.ts +12 -0
- package/src/domain/JsonParameterTypes.ts +20 -0
- package/src/domain/JsonPropertyStore.spec.ts +177 -0
- package/src/domain/JsonPropertyStore.ts +92 -0
- package/src/domain/JsonRequestBody.ts +47 -0
- package/src/domain/JsonResponse.spec.ts +33 -0
- package/src/domain/JsonResponse.ts +64 -0
- package/src/domain/JsonSchema.spec.ts +1470 -0
- package/src/domain/JsonSchema.ts +1049 -0
- package/src/domain/SpecTypes.ts +6 -0
- package/src/hooks/alterIgnore.ts +25 -0
- package/src/hooks/alterOneOf.ts +67 -0
- package/src/hooks/alterRequiredGroups.ts +12 -0
- package/src/index.ts +185 -0
- package/src/interfaces/IgnoreCallback.ts +5 -0
- package/src/interfaces/JsonHookContext.ts +18 -0
- package/src/interfaces/JsonOpenSpec.ts +7 -0
- package/src/interfaces/JsonSchemaOptions.ts +35 -0
- package/src/registries/JsonSchemaMapperContainer.ts +52 -0
- package/src/registries/enumRegistries.ts +3 -0
- package/src/utils/__snapshots__/generateSpec.spec.ts.snap +109 -0
- package/src/utils/buildPath.ts +8 -0
- package/src/utils/concatParameters.ts +12 -0
- package/src/utils/concatPath.spec.ts +23 -0
- package/src/utils/concatPath.ts +24 -0
- package/src/utils/defineStatusModel.ts +11 -0
- package/src/utils/from.spec.ts +243 -0
- package/src/utils/from.ts +281 -0
- package/src/utils/generateSpec.spec.ts +1262 -0
- package/src/utils/generateSpec.ts +54 -0
- package/src/utils/generics.ts +83 -0
- package/src/utils/getComputedType.spec.ts +45 -0
- package/src/utils/getComputedType.ts +39 -0
- package/src/utils/getInheritedStores.spec.ts +47 -0
- package/src/utils/getInheritedStores.ts +23 -0
- package/src/utils/getJsonEntityStore.ts +36 -0
- package/src/utils/getJsonPathParameters.spec.ts +126 -0
- package/src/utils/getJsonPathParameters.ts +97 -0
- package/src/utils/getJsonSchema.spec.ts +695 -0
- package/src/utils/getJsonSchema.ts +69 -0
- package/src/utils/getJsonType.spec.ts +28 -0
- package/src/utils/getJsonType.ts +46 -0
- package/src/utils/getOperationsRoutes.spec.ts +284 -0
- package/src/utils/getOperationsRoutes.ts +56 -0
- package/src/utils/getOperationsStore.spec.ts +47 -0
- package/src/utils/getOperationsStores.ts +37 -0
- package/src/utils/getPropertiesStores.spec.ts +138 -0
- package/src/utils/getPropertiesStores.ts +66 -0
- package/src/utils/getSpec.spec.ts +610 -0
- package/src/utils/getSpec.ts +117 -0
- package/src/utils/getSpecType.spec.ts +16 -0
- package/src/utils/getSpecType.ts +19 -0
- package/src/utils/isSuccessStatus.spec.ts +22 -0
- package/src/utils/isSuccessStatus.ts +2 -0
- package/src/utils/mapHeaders.spec.ts +57 -0
- package/src/utils/mapHeaders.ts +33 -0
- package/src/utils/mapOpenSpec.ts +44 -0
- package/src/utils/mapOpenSpec2.ts +50 -0
- package/src/utils/mapOpenSpec3.ts +25 -0
- package/src/utils/mapOpenSpecInfo.ts +19 -0
- package/src/utils/mapOperationOptions.ts +34 -0
- package/src/utils/matchGroups.spec.ts +85 -0
- package/src/utils/matchGroups.ts +64 -0
- package/src/utils/mergeSpec.spec.ts +533 -0
- package/src/utils/mergeSpec.ts +54 -0
- package/src/utils/operationIdFormatter.spec.ts +11 -0
- package/src/utils/operationIdFormatter.ts +49 -0
- package/src/utils/ref.ts +65 -0
- package/src/utils/removeHiddenOperation.ts +5 -0
- package/src/utils/serializeEnumValues.ts +27 -0
- package/src/utils/somethingOf.ts +11 -0
- package/src/utils/toJsonMapCollection.spec.ts +18 -0
- package/src/utils/toJsonMapCollection.ts +12 -0
- package/src/utils/toJsonRegex.ts +7 -0
- package/src/utils/transformToOS2.spec.ts +177 -0
- package/src/utils/transformToOS2.ts +607 -0
- package/src/utils/withErrorMsg.spec.ts +16 -0
- package/src/utils/withErrorMsg.ts +56 -0
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
import {OpenSpec2, OpenSpec3} from "@tsed/openspec";
|
|
2
|
+
|
|
3
|
+
import {mergeSpec} from "./mergeSpec.js";
|
|
4
|
+
|
|
5
|
+
describe("mergeSpec", () => {
|
|
6
|
+
describe("security", () => {
|
|
7
|
+
it("should merge spec", () => {
|
|
8
|
+
const spec1: OpenSpec2 = {
|
|
9
|
+
swagger: "2.0",
|
|
10
|
+
paths: {
|
|
11
|
+
"/get": {
|
|
12
|
+
get: {
|
|
13
|
+
operationId: "id",
|
|
14
|
+
security: [
|
|
15
|
+
{
|
|
16
|
+
openid: ["profile", "email"]
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
ga: ["profile", "email"]
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
responses: {}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const spec2: OpenSpec2 = {
|
|
29
|
+
swagger: "2.0",
|
|
30
|
+
paths: {
|
|
31
|
+
"/get": {
|
|
32
|
+
get: {
|
|
33
|
+
operationId: "id",
|
|
34
|
+
security: [
|
|
35
|
+
{
|
|
36
|
+
fb: ["profile", "email"],
|
|
37
|
+
openid: ["profile", "email"]
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
ga: ["profile", "email", "custom"]
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
responses: {}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
expect(mergeSpec(spec1, spec2)).toEqual({
|
|
50
|
+
paths: {
|
|
51
|
+
"/get": {
|
|
52
|
+
get: {
|
|
53
|
+
operationId: "id",
|
|
54
|
+
responses: {},
|
|
55
|
+
security: [
|
|
56
|
+
{
|
|
57
|
+
fb: ["profile", "email"],
|
|
58
|
+
openid: ["profile", "email"]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
ga: ["profile", "email", "custom"]
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
swagger: "2.0"
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe("allOf", () => {
|
|
72
|
+
it("should merge spec by type", () => {
|
|
73
|
+
const spec1: OpenSpec2 = {
|
|
74
|
+
swagger: "2.0",
|
|
75
|
+
paths: {
|
|
76
|
+
"/get": {
|
|
77
|
+
get: {
|
|
78
|
+
operationId: "id",
|
|
79
|
+
responses: {
|
|
80
|
+
"200": {
|
|
81
|
+
description: "description",
|
|
82
|
+
schema: {
|
|
83
|
+
type: "object",
|
|
84
|
+
properties: {
|
|
85
|
+
test: {
|
|
86
|
+
allOf: [
|
|
87
|
+
{
|
|
88
|
+
type: "string"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
type: "number"
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const spec2: OpenSpec2 = {
|
|
105
|
+
swagger: "2.0",
|
|
106
|
+
paths: {
|
|
107
|
+
"/get": {
|
|
108
|
+
get: {
|
|
109
|
+
operationId: "id",
|
|
110
|
+
responses: {
|
|
111
|
+
"200": {
|
|
112
|
+
description: "description",
|
|
113
|
+
schema: {
|
|
114
|
+
type: "object",
|
|
115
|
+
properties: {
|
|
116
|
+
test: {
|
|
117
|
+
allOf: [
|
|
118
|
+
{
|
|
119
|
+
type: "string"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
type: "number",
|
|
123
|
+
minimum: 1
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
type: "boolean"
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
expect(mergeSpec(spec1, spec2)).toEqual({
|
|
140
|
+
paths: {
|
|
141
|
+
"/get": {
|
|
142
|
+
get: {
|
|
143
|
+
operationId: "id",
|
|
144
|
+
responses: {
|
|
145
|
+
"200": {
|
|
146
|
+
description: "description",
|
|
147
|
+
schema: {
|
|
148
|
+
properties: {
|
|
149
|
+
test: {
|
|
150
|
+
allOf: [
|
|
151
|
+
{
|
|
152
|
+
type: "string"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
minimum: 1,
|
|
156
|
+
type: "number"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
type: "boolean"
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
type: "object"
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
swagger: "2.0"
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
it("should merge spec by $ref", () => {
|
|
175
|
+
const spec1: OpenSpec2 = {
|
|
176
|
+
swagger: "2.0",
|
|
177
|
+
paths: {
|
|
178
|
+
"/get": {
|
|
179
|
+
get: {
|
|
180
|
+
operationId: "id",
|
|
181
|
+
responses: {
|
|
182
|
+
"200": {
|
|
183
|
+
description: "description",
|
|
184
|
+
schema: {
|
|
185
|
+
type: "object",
|
|
186
|
+
properties: {
|
|
187
|
+
test: {
|
|
188
|
+
allOf: [
|
|
189
|
+
{
|
|
190
|
+
$ref: "#/definitions/MyClass1"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
$ref: "#/definitions/MyClass2"
|
|
194
|
+
}
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const spec2: OpenSpec2 = {
|
|
206
|
+
swagger: "2.0",
|
|
207
|
+
paths: {
|
|
208
|
+
"/get": {
|
|
209
|
+
get: {
|
|
210
|
+
operationId: "id",
|
|
211
|
+
responses: {
|
|
212
|
+
"200": {
|
|
213
|
+
description: "description",
|
|
214
|
+
schema: {
|
|
215
|
+
type: "object",
|
|
216
|
+
properties: {
|
|
217
|
+
test: {
|
|
218
|
+
allOf: [
|
|
219
|
+
{
|
|
220
|
+
type: "string"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
type: "number",
|
|
224
|
+
minimum: 1
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
$ref: "#/definitions/MyClass2"
|
|
228
|
+
}
|
|
229
|
+
]
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
expect(mergeSpec(spec1, spec2)).toEqual({
|
|
241
|
+
paths: {
|
|
242
|
+
"/get": {
|
|
243
|
+
get: {
|
|
244
|
+
operationId: "id",
|
|
245
|
+
responses: {
|
|
246
|
+
"200": {
|
|
247
|
+
description: "description",
|
|
248
|
+
schema: {
|
|
249
|
+
properties: {
|
|
250
|
+
test: {
|
|
251
|
+
allOf: [
|
|
252
|
+
{
|
|
253
|
+
$ref: "#/definitions/MyClass1"
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
$ref: "#/definitions/MyClass2"
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
type: "string"
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
minimum: 1,
|
|
263
|
+
type: "number"
|
|
264
|
+
}
|
|
265
|
+
]
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
type: "object"
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
swagger: "2.0"
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
describe("oneOf", () => {
|
|
280
|
+
it("should merge spec", () => {
|
|
281
|
+
const spec1: OpenSpec3 = {
|
|
282
|
+
openapi: "3.0.1",
|
|
283
|
+
info: {
|
|
284
|
+
title: "title",
|
|
285
|
+
version: "1.0.0",
|
|
286
|
+
description: "description"
|
|
287
|
+
},
|
|
288
|
+
paths: {
|
|
289
|
+
"/get": {
|
|
290
|
+
get: {
|
|
291
|
+
operationId: "id",
|
|
292
|
+
parameters: [
|
|
293
|
+
{
|
|
294
|
+
in: "query",
|
|
295
|
+
required: false,
|
|
296
|
+
name: "email",
|
|
297
|
+
schema: {
|
|
298
|
+
oneOf: [
|
|
299
|
+
{
|
|
300
|
+
$ref: "#/components/schemas/ContainsSearchableString"
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
$ref: "#/components/schemas/EqualsSearchableString"
|
|
304
|
+
}
|
|
305
|
+
]
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
],
|
|
309
|
+
responses: {
|
|
310
|
+
"206": {
|
|
311
|
+
content: {
|
|
312
|
+
"application/json": {
|
|
313
|
+
schema: {
|
|
314
|
+
$ref: "#/components/schemas/ContactQueryParams"
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
description: "Partial Content"
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
const spec2: OpenSpec3 = {
|
|
327
|
+
openapi: "3.0.1",
|
|
328
|
+
info: {
|
|
329
|
+
title: "title",
|
|
330
|
+
version: "1.0.0",
|
|
331
|
+
description: "description"
|
|
332
|
+
},
|
|
333
|
+
paths: {
|
|
334
|
+
"/get": {
|
|
335
|
+
get: {
|
|
336
|
+
operationId: "id",
|
|
337
|
+
parameters: [
|
|
338
|
+
{
|
|
339
|
+
in: "query",
|
|
340
|
+
required: false,
|
|
341
|
+
name: "email",
|
|
342
|
+
schema: {
|
|
343
|
+
oneOf: [
|
|
344
|
+
{
|
|
345
|
+
$ref: "#/components/schemas/ContainsSearchableString"
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
$ref: "#/components/schemas/EqualsSearchableString"
|
|
349
|
+
}
|
|
350
|
+
]
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
],
|
|
354
|
+
responses: {
|
|
355
|
+
"206": {
|
|
356
|
+
content: {
|
|
357
|
+
"application/json": {
|
|
358
|
+
schema: {
|
|
359
|
+
$ref: "#/components/schemas/ContactQueryParams"
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
description: "Partial Content"
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
expect(mergeSpec(spec1, spec2)).toEqual({
|
|
372
|
+
openapi: "3.0.1",
|
|
373
|
+
info: {
|
|
374
|
+
title: "title",
|
|
375
|
+
version: "1.0.0",
|
|
376
|
+
description: "description"
|
|
377
|
+
},
|
|
378
|
+
paths: {
|
|
379
|
+
"/get": {
|
|
380
|
+
get: {
|
|
381
|
+
operationId: "id",
|
|
382
|
+
parameters: [
|
|
383
|
+
{
|
|
384
|
+
in: "query",
|
|
385
|
+
required: false,
|
|
386
|
+
name: "email",
|
|
387
|
+
schema: {
|
|
388
|
+
oneOf: [
|
|
389
|
+
{
|
|
390
|
+
$ref: "#/components/schemas/ContainsSearchableString"
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
$ref: "#/components/schemas/EqualsSearchableString"
|
|
394
|
+
}
|
|
395
|
+
]
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
],
|
|
399
|
+
responses: {
|
|
400
|
+
"206": {
|
|
401
|
+
content: {
|
|
402
|
+
"application/json": {
|
|
403
|
+
schema: {
|
|
404
|
+
$ref: "#/components/schemas/ContactQueryParams"
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
description: "Partial Content"
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
describe("merge two specs", () => {
|
|
418
|
+
it("should merge the spec", () => {
|
|
419
|
+
const spec1 = {
|
|
420
|
+
paths: {
|
|
421
|
+
"/rest/api/1.0/test": {
|
|
422
|
+
get: {
|
|
423
|
+
operationId: "helloWorldControllerGet",
|
|
424
|
+
responses: {"200": {description: "Success"}},
|
|
425
|
+
parameters: [],
|
|
426
|
+
tags: ["HelloWorldController"]
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
"/rest/api/1.0/test/{id}": {
|
|
430
|
+
get: {
|
|
431
|
+
operationId: "helloWorldControllerGetById",
|
|
432
|
+
responses: {"200": {description: "Success"}},
|
|
433
|
+
parameters: [{in: "path", name: "id", required: true, schema: {type: "string"}}],
|
|
434
|
+
tags: ["HelloWorldController"]
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
"/rest/api/2.0/test": {
|
|
438
|
+
get: {
|
|
439
|
+
operationId: "helloWorldController2Get",
|
|
440
|
+
responses: {"200": {description: "Success"}},
|
|
441
|
+
parameters: [],
|
|
442
|
+
tags: ["HelloWorldController2"]
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
"/rest/api/2.0/test/{id}": {
|
|
446
|
+
get: {
|
|
447
|
+
operationId: "helloWorldController2GetById",
|
|
448
|
+
responses: {"200": {description: "Success"}},
|
|
449
|
+
parameters: [{in: "path", name: "id", required: true, schema: {type: "string"}}],
|
|
450
|
+
tags: ["HelloWorldController2"]
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
const spec2 = {
|
|
457
|
+
paths: {
|
|
458
|
+
"/rest/api/1.0/test": {
|
|
459
|
+
get: {
|
|
460
|
+
operationId: "helloWorldControllerGet",
|
|
461
|
+
responses: {"200": {description: "Success"}},
|
|
462
|
+
parameters: [],
|
|
463
|
+
tags: ["HelloWorldController"]
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
"/rest/api/1.0/test/{id}": {
|
|
467
|
+
get: {
|
|
468
|
+
operationId: "helloWorldControllerGetById",
|
|
469
|
+
responses: {"200": {description: "Success"}},
|
|
470
|
+
parameters: [{in: "path", name: "id", required: true, schema: {type: "string"}}],
|
|
471
|
+
tags: ["HelloWorldController"]
|
|
472
|
+
}
|
|
473
|
+
},
|
|
474
|
+
"/rest/api/2.0/test": {
|
|
475
|
+
get: {
|
|
476
|
+
operationId: "helloWorldController2Get",
|
|
477
|
+
responses: {"200": {description: "Success"}},
|
|
478
|
+
parameters: [],
|
|
479
|
+
tags: ["HelloWorldController2"]
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
"/rest/api/2.0/test/{id}": {
|
|
483
|
+
get: {
|
|
484
|
+
operationId: "helloWorldController2GetById",
|
|
485
|
+
responses: {"200": {description: "Success"}},
|
|
486
|
+
parameters: [{in: "path", name: "id", required: true, schema: {type: "string"}}],
|
|
487
|
+
tags: ["HelloWorldController2"]
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
const spec = mergeSpec(spec1, spec2);
|
|
494
|
+
|
|
495
|
+
expect(spec).toEqual({
|
|
496
|
+
paths: {
|
|
497
|
+
"/rest/api/1.0/test": {
|
|
498
|
+
get: {
|
|
499
|
+
operationId: "helloWorldControllerGet",
|
|
500
|
+
responses: {"200": {description: "Success"}},
|
|
501
|
+
parameters: [],
|
|
502
|
+
tags: ["HelloWorldController"]
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
"/rest/api/1.0/test/{id}": {
|
|
506
|
+
get: {
|
|
507
|
+
operationId: "helloWorldControllerGetById",
|
|
508
|
+
responses: {"200": {description: "Success"}},
|
|
509
|
+
parameters: [{in: "path", name: "id", required: true, schema: {type: "string"}}],
|
|
510
|
+
tags: ["HelloWorldController"]
|
|
511
|
+
}
|
|
512
|
+
},
|
|
513
|
+
"/rest/api/2.0/test": {
|
|
514
|
+
get: {
|
|
515
|
+
operationId: "helloWorldController2Get",
|
|
516
|
+
responses: {"200": {description: "Success"}},
|
|
517
|
+
parameters: [],
|
|
518
|
+
tags: ["HelloWorldController2"]
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
"/rest/api/2.0/test/{id}": {
|
|
522
|
+
get: {
|
|
523
|
+
operationId: "helloWorldController2GetById",
|
|
524
|
+
responses: {"200": {description: "Success"}},
|
|
525
|
+
parameters: [{in: "path", name: "id", required: true, schema: {type: "string"}}],
|
|
526
|
+
tags: ["HelloWorldController2"]
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {deepMerge, mergeReducerBuilder} from "@tsed/core";
|
|
2
|
+
import {OpenSpec2, OpenSpec3} from "@tsed/openspec";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
7
|
+
export const schemesReducer = mergeReducerBuilder((current, value) => {
|
|
8
|
+
if (current.type && current.type && current.type === value.type && value.type === "array") {
|
|
9
|
+
return JSON.stringify(current.items) === JSON.stringify(value.items);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return (current.type && current.type === value.type) || (current.$ref && current.$ref === value.$ref);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @ignore
|
|
17
|
+
*/
|
|
18
|
+
export const parameters = mergeReducerBuilder((current, value) => current.in === value.in && current.name === value.name);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @ignore
|
|
22
|
+
*/
|
|
23
|
+
export const security = mergeReducerBuilder((current, value) => {
|
|
24
|
+
return !!Object.keys(value).find((key) => !!current[key]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @ignore
|
|
29
|
+
*/
|
|
30
|
+
export const tagsReducer = mergeReducerBuilder((current, value) => current.name === value.name);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @ignore
|
|
34
|
+
*/
|
|
35
|
+
const SPEC_REDUCERS = {
|
|
36
|
+
security,
|
|
37
|
+
parameters,
|
|
38
|
+
oneOf: schemesReducer,
|
|
39
|
+
anyOf: schemesReducer,
|
|
40
|
+
allOf: schemesReducer,
|
|
41
|
+
tags: tagsReducer
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Merge two spec
|
|
46
|
+
* @param spec
|
|
47
|
+
* @param input
|
|
48
|
+
*/
|
|
49
|
+
export function mergeSpec<Spec = OpenSpec2 | OpenSpec3>(spec: Partial<Spec>, input: Partial<Spec>): Partial<Spec> {
|
|
50
|
+
return deepMerge(spec, input, {
|
|
51
|
+
reducers: SPEC_REDUCERS,
|
|
52
|
+
cleanUndefinedProps: true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {operationIdFormatter} from "./operationIdFormatter.js";
|
|
2
|
+
|
|
3
|
+
describe("operationIdFormatter", () => {
|
|
4
|
+
it("should define new OperationId", () => {
|
|
5
|
+
const formatter = operationIdFormatter();
|
|
6
|
+
|
|
7
|
+
expect(formatter("Test", "test")).toBe("testTest");
|
|
8
|
+
expect(formatter("Test", "test")).toBe("testTest_1");
|
|
9
|
+
expect(formatter("Test", "test", "/path/{id}")).toBe("testTestById");
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {camelCase} from "change-case";
|
|
2
|
+
|
|
3
|
+
import {JsonSchemaOptions} from "../interfaces/JsonSchemaOptions.js";
|
|
4
|
+
|
|
5
|
+
const DEFAULT_PATTERN = "%c.%m";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @ignore
|
|
9
|
+
*/
|
|
10
|
+
export function operationIdFormatter(pattern: string = "") {
|
|
11
|
+
const OPERATION_IDS = new Map<string, number>();
|
|
12
|
+
|
|
13
|
+
const transform = (name: string, propertyKey: string) => {
|
|
14
|
+
const str = (pattern || DEFAULT_PATTERN).replace(/%c/, name).replace(/%m/, propertyKey);
|
|
15
|
+
return pattern === "" ? camelCase(str) : str;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return (name: string, propertyKey: string, path: string = "") => {
|
|
19
|
+
const operationId = transform(name, propertyKey);
|
|
20
|
+
const operationKey = name + propertyKey;
|
|
21
|
+
|
|
22
|
+
if (!OPERATION_IDS.has(operationKey)) {
|
|
23
|
+
OPERATION_IDS.set(operationKey, 0);
|
|
24
|
+
|
|
25
|
+
return operationId;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// try with paths
|
|
29
|
+
const result = path.match(/{(\w+)}/gi);
|
|
30
|
+
if (result) {
|
|
31
|
+
const operationKey = name + propertyKey + result[0];
|
|
32
|
+
|
|
33
|
+
if (!OPERATION_IDS.has(operationKey)) {
|
|
34
|
+
OPERATION_IDS.set(operationKey, 0);
|
|
35
|
+
|
|
36
|
+
return camelCase(`${operationId} By ${result}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const id = OPERATION_IDS.get(operationKey)! + 1;
|
|
41
|
+
OPERATION_IDS.set(operationKey, id);
|
|
42
|
+
|
|
43
|
+
return `${operationId}_${id}`;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function getOperationId(path: string, {store, operationIdFormatter}: JsonSchemaOptions) {
|
|
48
|
+
return operationIdFormatter!(store.parent.schema.get("name") || store.parent.targetName, store.propertyName, path);
|
|
49
|
+
}
|
package/src/utils/ref.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {cleanObject, setValue} from "@tsed/core";
|
|
2
|
+
import {pascalCase} from "change-case";
|
|
3
|
+
|
|
4
|
+
import type {JsonSchema} from "../domain/JsonSchema.js";
|
|
5
|
+
import {SpecTypes} from "../domain/SpecTypes.js";
|
|
6
|
+
import {JsonSchemaOptions} from "../interfaces/JsonSchemaOptions.js";
|
|
7
|
+
import {anyOf} from "./from.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* ignore
|
|
11
|
+
* @param options
|
|
12
|
+
*/
|
|
13
|
+
function getHost(options: JsonSchemaOptions) {
|
|
14
|
+
const {host = `#/${[SpecTypes.OPENAPI, SpecTypes.ASYNCAPI].includes(options.specType!) ? "components/schemas" : "definitions"}`} =
|
|
15
|
+
options;
|
|
16
|
+
|
|
17
|
+
return host;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @ignore
|
|
22
|
+
*/
|
|
23
|
+
export function createRefName(name: string, options: JsonSchemaOptions) {
|
|
24
|
+
if (options.groups && options.groups.length) {
|
|
25
|
+
return pascalCase(`${name} ${options.groupsName || options.groups.join(" ")}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return name;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @ignore
|
|
33
|
+
*/
|
|
34
|
+
export function createRef(name: string, schema: JsonSchema, options: JsonSchemaOptions) {
|
|
35
|
+
const host = getHost(options);
|
|
36
|
+
const ref = {
|
|
37
|
+
$ref: `${host}/${name}`
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const readOnly = schema.isReadOnly;
|
|
41
|
+
const writeOnly = schema.isWriteOnly;
|
|
42
|
+
|
|
43
|
+
return cleanObject({
|
|
44
|
+
readOnly: readOnly ? true : undefined,
|
|
45
|
+
writeOnly: writeOnly ? true : undefined,
|
|
46
|
+
...(readOnly || writeOnly
|
|
47
|
+
? {
|
|
48
|
+
anyOf: [ref]
|
|
49
|
+
}
|
|
50
|
+
: ref)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @ignore
|
|
56
|
+
*/
|
|
57
|
+
export function toRef(value: JsonSchema, schema: unknown | undefined, options: JsonSchemaOptions) {
|
|
58
|
+
const name = createRefName(value.getName(), options);
|
|
59
|
+
|
|
60
|
+
if (schema) {
|
|
61
|
+
setValue(options, `components.schemas.${name}`, schema);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return createRef(name, value, options);
|
|
65
|
+
}
|