@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.
Files changed (291) hide show
  1. package/package.json +11 -10
  2. package/src/components/async-api/channelsMapper.ts +81 -0
  3. package/src/components/async-api/generate.ts +24 -0
  4. package/src/components/async-api/messageMapper.ts +62 -0
  5. package/src/components/async-api/payloadMapper.ts +61 -0
  6. package/src/components/async-api/responseMapper.ts +70 -0
  7. package/src/components/default/anyMapper.spec.ts +7 -0
  8. package/src/components/default/anyMapper.ts +33 -0
  9. package/src/components/default/classMapper.ts +55 -0
  10. package/src/components/default/discriminatorMappingMapper.ts +36 -0
  11. package/src/components/default/enumsMapper.spec.ts +64 -0
  12. package/src/components/default/enumsMapper.ts +17 -0
  13. package/src/components/default/genericsMapper.ts +70 -0
  14. package/src/components/default/inheritedClassMapper.ts +24 -0
  15. package/src/components/default/itemMapper.ts +8 -0
  16. package/src/components/default/lazyRefMapper.ts +21 -0
  17. package/src/components/default/mapMapper.ts +25 -0
  18. package/src/components/default/nullableMapper.ts +55 -0
  19. package/src/components/default/objectMapper.ts +36 -0
  20. package/src/components/default/ofMapper.ts +16 -0
  21. package/src/components/default/propertiesMapper.ts +25 -0
  22. package/src/components/default/requiredMapper.ts +69 -0
  23. package/src/components/default/schemaMapper.ts +151 -0
  24. package/src/components/index.ts +36 -0
  25. package/src/components/open-spec/discriminatorMappingMapper.ts +7 -0
  26. package/src/components/open-spec/enumsMapper.ts +20 -0
  27. package/src/components/open-spec/generate.ts +29 -0
  28. package/src/components/open-spec/nullableMapper.ts +51 -0
  29. package/src/components/open-spec/operationInFilesMapper.ts +32 -0
  30. package/src/components/open-spec/operationInParameterMapper.ts +56 -0
  31. package/src/components/open-spec/operationInParametersMapper.ts +9 -0
  32. package/src/components/open-spec/operationInQueryMapper.ts +74 -0
  33. package/src/components/open-spec/operationMapper.ts +65 -0
  34. package/src/components/open-spec/operationMediaMapper.ts +11 -0
  35. package/src/components/open-spec/operationRequestBodyMapper.ts +82 -0
  36. package/src/components/open-spec/operationResponseMapper.ts +26 -0
  37. package/src/components/open-spec/pathsMapper.ts +132 -0
  38. package/src/constants/OperationVerbs.ts +29 -0
  39. package/src/constants/httpStatusMessages.ts +21 -0
  40. package/src/constants/jsonSchemaProperties.ts +17 -0
  41. package/src/decorators/class/children.ts +22 -0
  42. package/src/decorators/class/discriminatorValue.ts +53 -0
  43. package/src/decorators/collections/collectionContains.ts +25 -0
  44. package/src/decorators/collections/collectionOf.spec.ts +327 -0
  45. package/src/decorators/collections/collectionOf.ts +182 -0
  46. package/src/decorators/collections/maxItems.spec.ts +40 -0
  47. package/src/decorators/collections/maxItems.ts +59 -0
  48. package/src/decorators/collections/maxProperties.spec.ts +109 -0
  49. package/src/decorators/collections/maxProperties.ts +82 -0
  50. package/src/decorators/collections/minItems.spec.ts +40 -0
  51. package/src/decorators/collections/minItems.ts +63 -0
  52. package/src/decorators/collections/minProperties.spec.ts +109 -0
  53. package/src/decorators/collections/minProperties.ts +81 -0
  54. package/src/decorators/collections/uniqueItems.spec.ts +28 -0
  55. package/src/decorators/collections/uniqueItems.ts +59 -0
  56. package/src/decorators/common/__snapshots__/groups.spec.ts.snap +321 -0
  57. package/src/decorators/common/additionalProperties.spec.ts +133 -0
  58. package/src/decorators/common/additionalProperties.ts +17 -0
  59. package/src/decorators/common/allOf.spec.ts +276 -0
  60. package/src/decorators/common/allOf.ts +19 -0
  61. package/src/decorators/common/allow.spec.ts +130 -0
  62. package/src/decorators/common/allow.ts +50 -0
  63. package/src/decorators/common/any.spec.ts +109 -0
  64. package/src/decorators/common/any.ts +45 -0
  65. package/src/decorators/common/anyOf.spec.ts +270 -0
  66. package/src/decorators/common/anyOf.ts +23 -0
  67. package/src/decorators/common/const.spec.ts +98 -0
  68. package/src/decorators/common/const.ts +68 -0
  69. package/src/decorators/common/customKey.spec.ts +105 -0
  70. package/src/decorators/common/customKey.ts +39 -0
  71. package/src/decorators/common/default.spec.ts +25 -0
  72. package/src/decorators/common/default.ts +47 -0
  73. package/src/decorators/common/defaultMsg.spec.ts +22 -0
  74. package/src/decorators/common/defaultMsg.ts +38 -0
  75. package/src/decorators/common/description.spec.ts +166 -0
  76. package/src/decorators/common/description.ts +77 -0
  77. package/src/decorators/common/discriminatorKey.ts +14 -0
  78. package/src/decorators/common/enum.spec.ts +305 -0
  79. package/src/decorators/common/enum.ts +111 -0
  80. package/src/decorators/common/errorMsg.spec.ts +57 -0
  81. package/src/decorators/common/errorMsg.ts +14 -0
  82. package/src/decorators/common/example.spec.ts +93 -0
  83. package/src/decorators/common/example.ts +18 -0
  84. package/src/decorators/common/examples.spec.ts +101 -0
  85. package/src/decorators/common/examples.ts +20 -0
  86. package/src/decorators/common/exclusiveMaximum.spec.ts +47 -0
  87. package/src/decorators/common/exclusiveMaximum.ts +75 -0
  88. package/src/decorators/common/exclusiveMinimum.spec.ts +47 -0
  89. package/src/decorators/common/exclusiveMinimum.ts +75 -0
  90. package/src/decorators/common/format.spec.ts +149 -0
  91. package/src/decorators/common/format.ts +486 -0
  92. package/src/decorators/common/forwardGroups.spec.ts +270 -0
  93. package/src/decorators/common/forwardGroups.ts +16 -0
  94. package/src/decorators/common/groups.spec.ts +968 -0
  95. package/src/decorators/common/groups.ts +66 -0
  96. package/src/decorators/common/hidden.spec.ts +52 -0
  97. package/src/decorators/common/hidden.ts +36 -0
  98. package/src/decorators/common/ignore.spec.ts +88 -0
  99. package/src/decorators/common/ignore.ts +66 -0
  100. package/src/decorators/common/integer.spec.ts +110 -0
  101. package/src/decorators/common/integer.ts +69 -0
  102. package/src/decorators/common/jsonEntityFn.spec.ts +16 -0
  103. package/src/decorators/common/jsonEntityFn.ts +33 -0
  104. package/src/decorators/common/maxLength.spec.ts +61 -0
  105. package/src/decorators/common/maxLength.ts +88 -0
  106. package/src/decorators/common/maximum.spec.ts +73 -0
  107. package/src/decorators/common/maximum.ts +146 -0
  108. package/src/decorators/common/minLength.spec.ts +186 -0
  109. package/src/decorators/common/minLength.ts +89 -0
  110. package/src/decorators/common/minimum.spec.ts +74 -0
  111. package/src/decorators/common/minimum.ts +145 -0
  112. package/src/decorators/common/multipleOf.spec.ts +33 -0
  113. package/src/decorators/common/multipleOf.ts +80 -0
  114. package/src/decorators/common/name.spec.ts +56 -0
  115. package/src/decorators/common/name.ts +50 -0
  116. package/src/decorators/common/nullable.spec.ts +818 -0
  117. package/src/decorators/common/nullable.ts +32 -0
  118. package/src/decorators/common/oneOf.spec.ts +301 -0
  119. package/src/decorators/common/oneOf.ts +24 -0
  120. package/src/decorators/common/optional.spec.ts +43 -0
  121. package/src/decorators/common/optional.ts +26 -0
  122. package/src/decorators/common/pattern.spec.ts +27 -0
  123. package/src/decorators/common/pattern.ts +102 -0
  124. package/src/decorators/common/property.ts +24 -0
  125. package/src/decorators/common/readOnly.spec.ts +135 -0
  126. package/src/decorators/common/readOnly.ts +17 -0
  127. package/src/decorators/common/recordOf.spec.ts +41 -0
  128. package/src/decorators/common/recordOf.ts +59 -0
  129. package/src/decorators/common/required.spec.ts +188 -0
  130. package/src/decorators/common/required.ts +50 -0
  131. package/src/decorators/common/requiredGroups.spec.ts +127 -0
  132. package/src/decorators/common/requiredGroups.ts +23 -0
  133. package/src/decorators/common/schema.spec.ts +23 -0
  134. package/src/decorators/common/schema.ts +64 -0
  135. package/src/decorators/common/title.spec.ts +20 -0
  136. package/src/decorators/common/title.ts +45 -0
  137. package/src/decorators/common/typeError.spec.ts +22 -0
  138. package/src/decorators/common/typeError.ts +15 -0
  139. package/src/decorators/common/writeOnly.spec.ts +105 -0
  140. package/src/decorators/common/writeOnly.ts +17 -0
  141. package/src/decorators/config/jsonEntityComponent.ts +16 -0
  142. package/src/decorators/generics/genericOf.spec.ts +246 -0
  143. package/src/decorators/generics/genericOf.ts +112 -0
  144. package/src/decorators/generics/generics.ts +22 -0
  145. package/src/decorators/operations/acceptMime.spec.ts +39 -0
  146. package/src/decorators/operations/acceptMime.ts +25 -0
  147. package/src/decorators/operations/consumes.spec.ts +89 -0
  148. package/src/decorators/operations/consumes.ts +37 -0
  149. package/src/decorators/operations/contentType.spec.ts +40 -0
  150. package/src/decorators/operations/contentType.ts +24 -0
  151. package/src/decorators/operations/deprecated.spec.ts +223 -0
  152. package/src/decorators/operations/deprecated.ts +49 -0
  153. package/src/decorators/operations/header.spec.ts +214 -0
  154. package/src/decorators/operations/header.ts +62 -0
  155. package/src/decorators/operations/in.spec.ts +321 -0
  156. package/src/decorators/operations/in.ts +141 -0
  157. package/src/decorators/operations/inFile.spec.ts +209 -0
  158. package/src/decorators/operations/inFile.ts +55 -0
  159. package/src/decorators/operations/location.spec.ts +51 -0
  160. package/src/decorators/operations/location.ts +26 -0
  161. package/src/decorators/operations/operation.ts +119 -0
  162. package/src/decorators/operations/operationId.spec.ts +43 -0
  163. package/src/decorators/operations/operationId.ts +22 -0
  164. package/src/decorators/operations/operationPath.spec.ts +42 -0
  165. package/src/decorators/operations/operationPath.ts +33 -0
  166. package/src/decorators/operations/partial.spec.ts +249 -0
  167. package/src/decorators/operations/partial.ts +14 -0
  168. package/src/decorators/operations/path.spec.ts +47 -0
  169. package/src/decorators/operations/path.ts +27 -0
  170. package/src/decorators/operations/produces.spec.ts +89 -0
  171. package/src/decorators/operations/produces.ts +44 -0
  172. package/src/decorators/operations/publish.spec.ts +26 -0
  173. package/src/decorators/operations/publish.ts +6 -0
  174. package/src/decorators/operations/redirect.spec.ts +146 -0
  175. package/src/decorators/operations/redirect.ts +82 -0
  176. package/src/decorators/operations/returns.spec.ts +1393 -0
  177. package/src/decorators/operations/returns.ts +662 -0
  178. package/src/decorators/operations/route.spec.ts +211 -0
  179. package/src/decorators/operations/route.ts +154 -0
  180. package/src/decorators/operations/security.spec.ts +162 -0
  181. package/src/decorators/operations/security.ts +83 -0
  182. package/src/decorators/operations/status.spec.ts +582 -0
  183. package/src/decorators/operations/status.ts +130 -0
  184. package/src/decorators/operations/subscribe.spec.ts +32 -0
  185. package/src/decorators/operations/subscribe.ts +6 -0
  186. package/src/decorators/operations/summary.spec.ts +45 -0
  187. package/src/decorators/operations/summary.ts +32 -0
  188. package/src/decorators/operations/tags.spec.ts +113 -0
  189. package/src/decorators/operations/tags.ts +53 -0
  190. package/src/decorators/operations/view.spec.ts +16 -0
  191. package/src/decorators/operations/view.ts +27 -0
  192. package/src/domain/DecoratorContext.ts +116 -0
  193. package/src/domain/JsonAliasMap.ts +19 -0
  194. package/src/domain/JsonClassStore.ts +35 -0
  195. package/src/domain/JsonDiscriminator.spec.ts +65 -0
  196. package/src/domain/JsonDiscriminator.ts +52 -0
  197. package/src/domain/JsonEntityStore.spec.ts +277 -0
  198. package/src/domain/JsonEntityStore.ts +284 -0
  199. package/src/domain/JsonFormatTypes.ts +17 -0
  200. package/src/domain/JsonLazyRef.ts +21 -0
  201. package/src/domain/JsonMap.spec.ts +15 -0
  202. package/src/domain/JsonMap.ts +33 -0
  203. package/src/domain/JsonMedia.ts +24 -0
  204. package/src/domain/JsonMethodStore.spec.ts +301 -0
  205. package/src/domain/JsonMethodStore.ts +212 -0
  206. package/src/domain/JsonOperation.spec.ts +126 -0
  207. package/src/domain/JsonOperation.ts +219 -0
  208. package/src/domain/JsonOperationPathsMap.ts +16 -0
  209. package/src/domain/JsonOperationRoute.spec.ts +109 -0
  210. package/src/domain/JsonOperationRoute.ts +75 -0
  211. package/src/domain/JsonParameter.ts +70 -0
  212. package/src/domain/JsonParameterStore.spec.ts +212 -0
  213. package/src/domain/JsonParameterStore.ts +138 -0
  214. package/src/domain/JsonParameterTypes.spec.ts +12 -0
  215. package/src/domain/JsonParameterTypes.ts +20 -0
  216. package/src/domain/JsonPropertyStore.spec.ts +177 -0
  217. package/src/domain/JsonPropertyStore.ts +92 -0
  218. package/src/domain/JsonRequestBody.ts +47 -0
  219. package/src/domain/JsonResponse.spec.ts +33 -0
  220. package/src/domain/JsonResponse.ts +64 -0
  221. package/src/domain/JsonSchema.spec.ts +1470 -0
  222. package/src/domain/JsonSchema.ts +1049 -0
  223. package/src/domain/SpecTypes.ts +6 -0
  224. package/src/hooks/alterIgnore.ts +25 -0
  225. package/src/hooks/alterOneOf.ts +67 -0
  226. package/src/hooks/alterRequiredGroups.ts +12 -0
  227. package/src/index.ts +185 -0
  228. package/src/interfaces/IgnoreCallback.ts +5 -0
  229. package/src/interfaces/JsonHookContext.ts +18 -0
  230. package/src/interfaces/JsonOpenSpec.ts +7 -0
  231. package/src/interfaces/JsonSchemaOptions.ts +35 -0
  232. package/src/registries/JsonSchemaMapperContainer.ts +52 -0
  233. package/src/registries/enumRegistries.ts +3 -0
  234. package/src/utils/__snapshots__/generateSpec.spec.ts.snap +109 -0
  235. package/src/utils/buildPath.ts +8 -0
  236. package/src/utils/concatParameters.ts +12 -0
  237. package/src/utils/concatPath.spec.ts +23 -0
  238. package/src/utils/concatPath.ts +24 -0
  239. package/src/utils/defineStatusModel.ts +11 -0
  240. package/src/utils/from.spec.ts +243 -0
  241. package/src/utils/from.ts +281 -0
  242. package/src/utils/generateSpec.spec.ts +1262 -0
  243. package/src/utils/generateSpec.ts +54 -0
  244. package/src/utils/generics.ts +83 -0
  245. package/src/utils/getComputedType.spec.ts +45 -0
  246. package/src/utils/getComputedType.ts +39 -0
  247. package/src/utils/getInheritedStores.spec.ts +47 -0
  248. package/src/utils/getInheritedStores.ts +23 -0
  249. package/src/utils/getJsonEntityStore.ts +36 -0
  250. package/src/utils/getJsonPathParameters.spec.ts +126 -0
  251. package/src/utils/getJsonPathParameters.ts +97 -0
  252. package/src/utils/getJsonSchema.spec.ts +695 -0
  253. package/src/utils/getJsonSchema.ts +69 -0
  254. package/src/utils/getJsonType.spec.ts +28 -0
  255. package/src/utils/getJsonType.ts +46 -0
  256. package/src/utils/getOperationsRoutes.spec.ts +284 -0
  257. package/src/utils/getOperationsRoutes.ts +56 -0
  258. package/src/utils/getOperationsStore.spec.ts +47 -0
  259. package/src/utils/getOperationsStores.ts +37 -0
  260. package/src/utils/getPropertiesStores.spec.ts +138 -0
  261. package/src/utils/getPropertiesStores.ts +66 -0
  262. package/src/utils/getSpec.spec.ts +610 -0
  263. package/src/utils/getSpec.ts +117 -0
  264. package/src/utils/getSpecType.spec.ts +16 -0
  265. package/src/utils/getSpecType.ts +19 -0
  266. package/src/utils/isSuccessStatus.spec.ts +22 -0
  267. package/src/utils/isSuccessStatus.ts +2 -0
  268. package/src/utils/mapHeaders.spec.ts +57 -0
  269. package/src/utils/mapHeaders.ts +33 -0
  270. package/src/utils/mapOpenSpec.ts +44 -0
  271. package/src/utils/mapOpenSpec2.ts +50 -0
  272. package/src/utils/mapOpenSpec3.ts +25 -0
  273. package/src/utils/mapOpenSpecInfo.ts +19 -0
  274. package/src/utils/mapOperationOptions.ts +34 -0
  275. package/src/utils/matchGroups.spec.ts +85 -0
  276. package/src/utils/matchGroups.ts +64 -0
  277. package/src/utils/mergeSpec.spec.ts +533 -0
  278. package/src/utils/mergeSpec.ts +54 -0
  279. package/src/utils/operationIdFormatter.spec.ts +11 -0
  280. package/src/utils/operationIdFormatter.ts +49 -0
  281. package/src/utils/ref.ts +65 -0
  282. package/src/utils/removeHiddenOperation.ts +5 -0
  283. package/src/utils/serializeEnumValues.ts +27 -0
  284. package/src/utils/somethingOf.ts +11 -0
  285. package/src/utils/toJsonMapCollection.spec.ts +18 -0
  286. package/src/utils/toJsonMapCollection.ts +12 -0
  287. package/src/utils/toJsonRegex.ts +7 -0
  288. package/src/utils/transformToOS2.spec.ts +177 -0
  289. package/src/utils/transformToOS2.ts +607 -0
  290. package/src/utils/withErrorMsg.spec.ts +16 -0
  291. package/src/utils/withErrorMsg.ts +56 -0
@@ -0,0 +1,968 @@
1
+ import {SpecTypes} from "../../domain/SpecTypes.js";
2
+ import {getJsonSchema} from "../../utils/getJsonSchema.js";
3
+ import {getSpec} from "../../utils/getSpec.js";
4
+ import {CollectionOf} from "../collections/collectionOf.js";
5
+ import {In} from "../operations/in.js";
6
+ import {OperationPath} from "../operations/operationPath.js";
7
+ import {Path} from "../operations/path.js";
8
+ import {Returns} from "../operations/returns.js";
9
+ import {Groups} from "./groups.js";
10
+ import {Name} from "./name.js";
11
+ import {Property} from "./property.js";
12
+ import {Required} from "./required.js";
13
+ import {RequiredGroups} from "./requiredGroups.js";
14
+
15
+ class ChildModel {
16
+ @Groups("!creation")
17
+ id: string;
18
+
19
+ @Required()
20
+ prop1: string;
21
+ }
22
+
23
+ class MyModel {
24
+ @Groups("!creation")
25
+ id: string;
26
+
27
+ @Groups("group.summary")
28
+ @Required()
29
+ prop1: string;
30
+
31
+ @Groups("group.extended")
32
+ @Required()
33
+ prop2: string;
34
+
35
+ @Property()
36
+ @Required()
37
+ prop3: string;
38
+
39
+ @CollectionOf(ChildModel)
40
+ prop4: ChildModel[];
41
+ }
42
+
43
+ describe("@Groups", () => {
44
+ describe("JsonSchema", () => {
45
+ it("should show fields with group annotation", () => {
46
+ const spec = getJsonSchema(MyModel, {
47
+ groups: false
48
+ });
49
+
50
+ expect(spec).toEqual({
51
+ definitions: {
52
+ ChildModel: {
53
+ properties: {
54
+ id: {
55
+ type: "string"
56
+ },
57
+ prop1: {
58
+ minLength: 1,
59
+ type: "string"
60
+ }
61
+ },
62
+ required: ["prop1"],
63
+ type: "object"
64
+ }
65
+ },
66
+ properties: {
67
+ id: {
68
+ type: "string"
69
+ },
70
+ prop1: {
71
+ minLength: 1,
72
+ type: "string"
73
+ },
74
+ prop2: {
75
+ minLength: 1,
76
+ type: "string"
77
+ },
78
+ prop3: {
79
+ minLength: 1,
80
+ type: "string"
81
+ },
82
+ prop4: {
83
+ items: {
84
+ $ref: "#/definitions/ChildModel"
85
+ },
86
+ type: "array"
87
+ }
88
+ },
89
+ required: ["prop1", "prop2", "prop3"],
90
+ type: "object"
91
+ });
92
+ });
93
+ it("should show fields with group annotation (with x-groups custom key)", () => {
94
+ const spec = getJsonSchema(MyModel, {
95
+ groups: false,
96
+ customKeys: true
97
+ });
98
+
99
+ expect(spec).toEqual({
100
+ definitions: {
101
+ ChildModel: {
102
+ properties: {
103
+ id: {
104
+ "x-groups": ["!creation"],
105
+ type: "string"
106
+ },
107
+ prop1: {
108
+ minLength: 1,
109
+ type: "string"
110
+ }
111
+ },
112
+ required: ["prop1"],
113
+ type: "object"
114
+ }
115
+ },
116
+ properties: {
117
+ id: {
118
+ "x-groups": ["!creation"],
119
+ type: "string"
120
+ },
121
+ prop1: {
122
+ "x-groups": ["group.summary"],
123
+ minLength: 1,
124
+ type: "string"
125
+ },
126
+ prop2: {
127
+ "x-groups": ["group.extended"],
128
+ minLength: 1,
129
+ type: "string"
130
+ },
131
+ prop3: {
132
+ minLength: 1,
133
+ type: "string"
134
+ },
135
+ prop4: {
136
+ items: {
137
+ $ref: "#/definitions/ChildModel"
138
+ },
139
+ type: "array"
140
+ }
141
+ },
142
+ required: ["prop1", "prop2", "prop3"],
143
+ type: "object"
144
+ });
145
+ });
146
+ it("should show fields with group annotation if the an empty array is given to group fields", () => {
147
+ const spec = getJsonSchema(MyModel, {
148
+ groups: []
149
+ });
150
+
151
+ expect(spec).toEqual({
152
+ definitions: {
153
+ ChildModel: {
154
+ properties: {
155
+ id: {
156
+ type: "string"
157
+ },
158
+ prop1: {
159
+ minLength: 1,
160
+ type: "string"
161
+ }
162
+ },
163
+ required: ["prop1"],
164
+ type: "object"
165
+ }
166
+ },
167
+ properties: {
168
+ id: {
169
+ type: "string"
170
+ },
171
+ prop3: {
172
+ minLength: 1,
173
+ type: "string"
174
+ },
175
+ prop4: {
176
+ items: {
177
+ $ref: "#/definitions/ChildModel"
178
+ },
179
+ type: "array"
180
+ }
181
+ },
182
+ required: ["prop3"],
183
+ type: "object"
184
+ });
185
+ });
186
+ it("should show fields with group annotation if the an empty any groups is given", () => {
187
+ const spec = getJsonSchema(MyModel);
188
+
189
+ expect(spec).toEqual({
190
+ definitions: {
191
+ ChildModel: {
192
+ properties: {
193
+ id: {
194
+ type: "string"
195
+ },
196
+ prop1: {
197
+ minLength: 1,
198
+ type: "string"
199
+ }
200
+ },
201
+ required: ["prop1"],
202
+ type: "object"
203
+ }
204
+ },
205
+ properties: {
206
+ id: {
207
+ type: "string"
208
+ },
209
+ prop3: {
210
+ minLength: 1,
211
+ type: "string"
212
+ },
213
+ prop4: {
214
+ items: {
215
+ $ref: "#/definitions/ChildModel"
216
+ },
217
+ type: "array"
218
+ }
219
+ },
220
+ required: ["prop3"],
221
+ type: "object"
222
+ });
223
+ });
224
+ it("should display fields when a group match with (group.summary)", () => {
225
+ const spec = getJsonSchema(MyModel, {
226
+ groups: ["group.summary"]
227
+ });
228
+
229
+ expect(spec).toEqual({
230
+ definitions: {
231
+ ChildModel: {
232
+ properties: {
233
+ id: {
234
+ type: "string"
235
+ },
236
+ prop1: {
237
+ minLength: 1,
238
+ type: "string"
239
+ }
240
+ },
241
+ required: ["prop1"],
242
+ type: "object"
243
+ }
244
+ },
245
+ properties: {
246
+ id: {
247
+ type: "string"
248
+ },
249
+ prop1: {
250
+ minLength: 1,
251
+ type: "string"
252
+ },
253
+ prop3: {
254
+ minLength: 1,
255
+ type: "string"
256
+ },
257
+ prop4: {
258
+ items: {
259
+ $ref: "#/definitions/ChildModel"
260
+ },
261
+ type: "array"
262
+ }
263
+ },
264
+ required: ["prop1", "prop3"],
265
+ type: "object"
266
+ });
267
+ });
268
+ it("should display fields when a group match with (creation)", () => {
269
+ const spec = getJsonSchema(MyModel, {
270
+ groups: ["creation"]
271
+ });
272
+
273
+ expect(spec).toEqual({
274
+ definitions: {
275
+ ChildModel: {
276
+ properties: {
277
+ id: {
278
+ type: "string"
279
+ },
280
+ prop1: {
281
+ minLength: 1,
282
+ type: "string"
283
+ }
284
+ },
285
+ required: ["prop1"],
286
+ type: "object"
287
+ }
288
+ },
289
+ properties: {
290
+ prop3: {
291
+ minLength: 1,
292
+ type: "string"
293
+ },
294
+ prop4: {
295
+ items: {
296
+ $ref: "#/definitions/ChildModel"
297
+ },
298
+ type: "array"
299
+ }
300
+ },
301
+ required: ["prop3"],
302
+ type: "object"
303
+ });
304
+ });
305
+ it("should display fields when a group match with (pattern)", () => {
306
+ const spec = getJsonSchema(MyModel, {
307
+ groups: ["group.*"]
308
+ });
309
+
310
+ expect(spec).toEqual({
311
+ definitions: {
312
+ ChildModel: {
313
+ properties: {
314
+ id: {
315
+ type: "string"
316
+ },
317
+ prop1: {
318
+ minLength: 1,
319
+ type: "string"
320
+ }
321
+ },
322
+ required: ["prop1"],
323
+ type: "object"
324
+ }
325
+ },
326
+ properties: {
327
+ id: {
328
+ type: "string"
329
+ },
330
+ prop1: {
331
+ minLength: 1,
332
+ type: "string"
333
+ },
334
+ prop2: {
335
+ minLength: 1,
336
+ type: "string"
337
+ },
338
+ prop3: {
339
+ minLength: 1,
340
+ type: "string"
341
+ },
342
+ prop4: {
343
+ items: {
344
+ $ref: "#/definitions/ChildModel"
345
+ },
346
+ type: "array"
347
+ }
348
+ },
349
+ required: ["prop1", "prop2", "prop3"],
350
+ type: "object"
351
+ });
352
+ });
353
+ it("should show fields with group annotation (by class)", () => {
354
+ @Groups<User>({
355
+ // will generate UserCreate
356
+ creation: ["firstName", "lastName", "email", "password"],
357
+ // will generate UserUpdate
358
+ update: ["id", "firstName", "lastName", "email"],
359
+ // will generate UserChangePassword
360
+ changePassword: ["id", "password", "newPassword"]
361
+ })
362
+ class User {
363
+ @Required()
364
+ id: string;
365
+
366
+ @Required()
367
+ @RequiredGroups("creation")
368
+ firstName: string;
369
+
370
+ @Required()
371
+ @RequiredGroups("creation")
372
+ lastName: string;
373
+
374
+ @Required()
375
+ @RequiredGroups("creation")
376
+ email: string;
377
+
378
+ @Required()
379
+ @RequiredGroups("create", "changePassword")
380
+ password: string;
381
+
382
+ @Required()
383
+ @RequiredGroups("changePassword")
384
+ newPassword: string;
385
+ }
386
+
387
+ const spec1 = getJsonSchema(User, {
388
+ groups: ["creation"]
389
+ });
390
+
391
+ expect(spec1).toEqual({
392
+ properties: {
393
+ email: {
394
+ minLength: 1,
395
+ type: "string"
396
+ },
397
+ firstName: {
398
+ minLength: 1,
399
+ type: "string"
400
+ },
401
+ lastName: {
402
+ minLength: 1,
403
+ type: "string"
404
+ },
405
+ password: {
406
+ minLength: 1,
407
+ type: "string"
408
+ }
409
+ },
410
+ required: ["firstName", "lastName", "email"],
411
+ type: "object"
412
+ });
413
+
414
+ const spec2 = getJsonSchema(User, {
415
+ groups: ["update"]
416
+ });
417
+
418
+ expect(spec2).toEqual({
419
+ properties: {
420
+ email: {
421
+ minLength: 1,
422
+ type: "string"
423
+ },
424
+ firstName: {
425
+ minLength: 1,
426
+ type: "string"
427
+ },
428
+ id: {
429
+ minLength: 1,
430
+ type: "string"
431
+ },
432
+ lastName: {
433
+ minLength: 1,
434
+ type: "string"
435
+ }
436
+ },
437
+ required: ["id"],
438
+ type: "object"
439
+ });
440
+
441
+ const spec3 = getJsonSchema(User, {
442
+ groups: ["changePassword"]
443
+ });
444
+
445
+ expect(spec3).toEqual({
446
+ properties: {
447
+ id: {
448
+ minLength: 1,
449
+ type: "string"
450
+ },
451
+ newPassword: {
452
+ minLength: 1,
453
+ type: "string"
454
+ },
455
+ password: {
456
+ minLength: 1,
457
+ type: "string"
458
+ }
459
+ },
460
+ required: ["id", "password", "newPassword"],
461
+ type: "object"
462
+ });
463
+ });
464
+ });
465
+ describe("OpenSpec", () => {
466
+ it("should display fields when a group match with - body (OS3)", () => {
467
+ @Path("/")
468
+ class MyController {
469
+ @OperationPath("POST", "/")
470
+ @(Returns(201, MyModel).Groups("group.*"))
471
+ create(@In("body") @Groups("creation") payload: MyModel) {
472
+ return new MyModel();
473
+ }
474
+
475
+ @OperationPath("PUT", "/:id")
476
+ @Returns(200, MyModel)
477
+ update(@In("body") @Groups("group.*") payload: MyModel, @In("path") @Name("id") id: string) {
478
+ return new MyModel();
479
+ }
480
+ }
481
+
482
+ const spec = getSpec(MyController, {specType: SpecTypes.OPENAPI});
483
+
484
+ expect(spec).toEqual({
485
+ components: {
486
+ schemas: {
487
+ ChildModel: {
488
+ properties: {
489
+ id: {
490
+ type: "string"
491
+ },
492
+ prop1: {
493
+ minLength: 1,
494
+ type: "string"
495
+ }
496
+ },
497
+ required: ["prop1"],
498
+ type: "object"
499
+ },
500
+ MyModel: {
501
+ properties: {
502
+ id: {
503
+ type: "string"
504
+ },
505
+ prop3: {
506
+ minLength: 1,
507
+ type: "string"
508
+ },
509
+ prop4: {
510
+ items: {
511
+ $ref: "#/components/schemas/ChildModel"
512
+ },
513
+ type: "array"
514
+ }
515
+ },
516
+ required: ["prop3"],
517
+ type: "object"
518
+ },
519
+ MyModelCreation: {
520
+ properties: {
521
+ prop3: {
522
+ minLength: 1,
523
+ type: "string"
524
+ },
525
+ prop4: {
526
+ items: {
527
+ $ref: "#/components/schemas/ChildModel"
528
+ },
529
+ type: "array"
530
+ }
531
+ },
532
+ required: ["prop3"],
533
+ type: "object"
534
+ },
535
+ MyModelGroup: {
536
+ properties: {
537
+ id: {
538
+ type: "string"
539
+ },
540
+ prop1: {
541
+ minLength: 1,
542
+ type: "string"
543
+ },
544
+ prop2: {
545
+ minLength: 1,
546
+ type: "string"
547
+ },
548
+ prop3: {
549
+ minLength: 1,
550
+ type: "string"
551
+ },
552
+ prop4: {
553
+ items: {
554
+ $ref: "#/components/schemas/ChildModel"
555
+ },
556
+ type: "array"
557
+ }
558
+ },
559
+ required: ["prop1", "prop2", "prop3"],
560
+ type: "object"
561
+ }
562
+ }
563
+ },
564
+ paths: {
565
+ "/": {
566
+ post: {
567
+ operationId: "myControllerCreate",
568
+ parameters: [],
569
+ requestBody: {
570
+ content: {
571
+ "application/json": {
572
+ schema: {
573
+ $ref: "#/components/schemas/MyModelCreation"
574
+ }
575
+ }
576
+ },
577
+ required: false
578
+ },
579
+ responses: {
580
+ "201": {
581
+ content: {
582
+ "application/json": {
583
+ schema: {
584
+ $ref: "#/components/schemas/MyModelGroup"
585
+ }
586
+ }
587
+ },
588
+ description: "Created"
589
+ }
590
+ },
591
+ tags: ["MyController"]
592
+ }
593
+ },
594
+ "/{id}": {
595
+ put: {
596
+ operationId: "myControllerUpdate",
597
+ parameters: [
598
+ {
599
+ in: "path",
600
+ name: "id",
601
+ required: true,
602
+ schema: {
603
+ type: "string"
604
+ }
605
+ }
606
+ ],
607
+ requestBody: {
608
+ content: {
609
+ "application/json": {
610
+ schema: {
611
+ $ref: "#/components/schemas/MyModelGroup"
612
+ }
613
+ }
614
+ },
615
+ required: false
616
+ },
617
+ responses: {
618
+ "200": {
619
+ content: {
620
+ "application/json": {
621
+ schema: {
622
+ $ref: "#/components/schemas/MyModel"
623
+ }
624
+ }
625
+ },
626
+ description: "Success"
627
+ }
628
+ },
629
+ tags: ["MyController"]
630
+ }
631
+ }
632
+ },
633
+ tags: [
634
+ {
635
+ name: "MyController"
636
+ }
637
+ ]
638
+ });
639
+ });
640
+ it("should display fields when a group match with - body and a group name (OS3)", () => {
641
+ @Path("/")
642
+ class MyController {
643
+ @OperationPath("POST", "/")
644
+ @(Returns(201, MyModel).Groups("group.*"))
645
+ create(@In("body") @Groups("CreatePayload", ["creation"]) payload: MyModel) {
646
+ return new MyModel();
647
+ }
648
+
649
+ @OperationPath("PUT", "/:id")
650
+ @Returns(200, MyModel)
651
+ update(@In("body") @Groups("Complete", "group.*") payload: MyModel, @In("path") @Name("id") id: string) {
652
+ return new MyModel();
653
+ }
654
+ }
655
+
656
+ const spec = getSpec(MyController, {specType: SpecTypes.OPENAPI});
657
+
658
+ expect(spec).toMatchSnapshot();
659
+ });
660
+ it("should display fields when a group match with - query (OS3)", () => {
661
+ @Path("/")
662
+ class MyController {
663
+ @OperationPath("GET", "/")
664
+ @(Returns(201, MyModel).Groups("group.*"))
665
+ get(@In("query") @Groups("creation") payload: MyModel) {
666
+ return new MyModel();
667
+ }
668
+
669
+ @OperationPath("GET", "/all")
670
+ @(Returns(201, MyModel).Groups("group.*"))
671
+ getWithout(@In("query") payload: MyModel) {
672
+ return new MyModel();
673
+ }
674
+ }
675
+
676
+ const spec = getSpec(MyController, {specType: SpecTypes.OPENAPI});
677
+
678
+ expect(spec).toEqual({
679
+ components: {
680
+ schemas: {
681
+ ChildModel: {
682
+ properties: {
683
+ id: {
684
+ type: "string"
685
+ },
686
+ prop1: {
687
+ minLength: 1,
688
+ type: "string"
689
+ }
690
+ },
691
+ required: ["prop1"],
692
+ type: "object"
693
+ },
694
+ MyModelCreation: {
695
+ properties: {
696
+ prop3: {
697
+ minLength: 1,
698
+ type: "string"
699
+ },
700
+ prop4: {
701
+ items: {
702
+ $ref: "#/components/schemas/ChildModel"
703
+ },
704
+ type: "array"
705
+ }
706
+ },
707
+ required: ["prop3"],
708
+ type: "object"
709
+ },
710
+ MyModelGroup: {
711
+ properties: {
712
+ id: {
713
+ type: "string"
714
+ },
715
+ prop1: {
716
+ minLength: 1,
717
+ type: "string"
718
+ },
719
+ prop2: {
720
+ minLength: 1,
721
+ type: "string"
722
+ },
723
+ prop3: {
724
+ minLength: 1,
725
+ type: "string"
726
+ },
727
+ prop4: {
728
+ items: {
729
+ $ref: "#/components/schemas/ChildModel"
730
+ },
731
+ type: "array"
732
+ }
733
+ },
734
+ required: ["prop1", "prop2", "prop3"],
735
+ type: "object"
736
+ }
737
+ }
738
+ },
739
+ paths: {
740
+ "/": {
741
+ get: {
742
+ operationId: "myControllerGet",
743
+ parameters: [
744
+ {
745
+ in: "query",
746
+ name: "prop3",
747
+ required: true,
748
+ schema: {
749
+ minLength: 1,
750
+ type: "string"
751
+ }
752
+ },
753
+ {
754
+ in: "query",
755
+ name: "prop4",
756
+ required: false,
757
+ schema: {
758
+ items: {
759
+ $ref: "#/components/schemas/ChildModel"
760
+ },
761
+ type: "array"
762
+ }
763
+ }
764
+ ],
765
+ responses: {
766
+ "201": {
767
+ content: {
768
+ "application/json": {
769
+ schema: {
770
+ $ref: "#/components/schemas/MyModelGroup"
771
+ }
772
+ }
773
+ },
774
+ description: "Created"
775
+ }
776
+ },
777
+ tags: ["MyController"]
778
+ }
779
+ },
780
+ "/all": {
781
+ get: {
782
+ operationId: "myControllerGetWithout",
783
+ parameters: [
784
+ {
785
+ in: "query",
786
+ name: "id",
787
+ required: false,
788
+ schema: {
789
+ type: "string"
790
+ }
791
+ },
792
+ {
793
+ in: "query",
794
+ name: "prop3",
795
+ required: true,
796
+ schema: {
797
+ minLength: 1,
798
+ type: "string"
799
+ }
800
+ },
801
+ {
802
+ in: "query",
803
+ name: "prop4",
804
+ required: false,
805
+ schema: {
806
+ items: {
807
+ $ref: "#/components/schemas/ChildModel"
808
+ },
809
+ type: "array"
810
+ }
811
+ }
812
+ ],
813
+ responses: {
814
+ "201": {
815
+ content: {
816
+ "application/json": {
817
+ schema: {
818
+ $ref: "#/components/schemas/MyModelGroup"
819
+ }
820
+ }
821
+ },
822
+ description: "Created"
823
+ }
824
+ },
825
+ tags: ["MyController"]
826
+ }
827
+ }
828
+ },
829
+ tags: [
830
+ {
831
+ name: "MyController"
832
+ }
833
+ ]
834
+ });
835
+ });
836
+ it("should display fields when a group match with (array - OS3)", () => {
837
+ @Path("/")
838
+ class MyController {
839
+ @OperationPath("POST", "/")
840
+ @(Returns(201, Array).Of(MyModel).Groups("group.*"))
841
+ createWithArray(@In("body") @Groups("creation") @CollectionOf(MyModel) payload: MyModel[]) {
842
+ return [new MyModel()];
843
+ }
844
+ }
845
+
846
+ const spec = getSpec(MyController, {specType: SpecTypes.OPENAPI});
847
+
848
+ expect(spec).toEqual({
849
+ components: {
850
+ schemas: {
851
+ ChildModel: {
852
+ properties: {
853
+ id: {
854
+ type: "string"
855
+ },
856
+ prop1: {
857
+ minLength: 1,
858
+ type: "string"
859
+ }
860
+ },
861
+ required: ["prop1"],
862
+ type: "object"
863
+ },
864
+ MyModelCreation: {
865
+ properties: {
866
+ prop3: {
867
+ minLength: 1,
868
+ type: "string"
869
+ },
870
+ prop4: {
871
+ items: {
872
+ $ref: "#/components/schemas/ChildModel"
873
+ },
874
+ type: "array"
875
+ }
876
+ },
877
+ required: ["prop3"],
878
+ type: "object"
879
+ },
880
+ MyModelGroup: {
881
+ properties: {
882
+ id: {
883
+ type: "string"
884
+ },
885
+ prop1: {
886
+ minLength: 1,
887
+ type: "string"
888
+ },
889
+ prop2: {
890
+ minLength: 1,
891
+ type: "string"
892
+ },
893
+ prop3: {
894
+ minLength: 1,
895
+ type: "string"
896
+ },
897
+ prop4: {
898
+ items: {
899
+ $ref: "#/components/schemas/ChildModel"
900
+ },
901
+ type: "array"
902
+ }
903
+ },
904
+ required: ["prop1", "prop2", "prop3"],
905
+ type: "object"
906
+ }
907
+ }
908
+ },
909
+ paths: {
910
+ "/": {
911
+ post: {
912
+ operationId: "myControllerCreateWithArray",
913
+ parameters: [],
914
+ requestBody: {
915
+ content: {
916
+ "application/json": {
917
+ schema: {
918
+ items: {
919
+ $ref: "#/components/schemas/MyModelCreation"
920
+ },
921
+ type: "array"
922
+ }
923
+ }
924
+ },
925
+ required: false
926
+ },
927
+ responses: {
928
+ "201": {
929
+ content: {
930
+ "application/json": {
931
+ schema: {
932
+ items: {
933
+ $ref: "#/components/schemas/MyModelGroup"
934
+ },
935
+ type: "array"
936
+ }
937
+ }
938
+ },
939
+ description: "Created"
940
+ }
941
+ },
942
+ tags: ["MyController"]
943
+ }
944
+ }
945
+ },
946
+ tags: [
947
+ {
948
+ name: "MyController"
949
+ }
950
+ ]
951
+ });
952
+ });
953
+ it("should display fields when a group match with (array & groups - OS3)", () => {
954
+ @Path("/")
955
+ class MyController {
956
+ @OperationPath("POST", "/")
957
+ @(Returns(201, Array).Of(MyModel).Groups("Details", ["group.*"]))
958
+ createWithArray(@In("body") @Groups("Create", ["creation"]) @CollectionOf(MyModel) payload: MyModel[]) {
959
+ return [new MyModel()];
960
+ }
961
+ }
962
+
963
+ const spec = getSpec(MyController, {specType: SpecTypes.OPENAPI});
964
+
965
+ expect(spec).toMatchSnapshot();
966
+ });
967
+ });
968
+ });