@tsed/schema 7.0.0-beta.2 → 7.0.0-beta.5

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 (304) hide show
  1. package/jest.config.js +4 -4
  2. package/lib/cjs/components/schemaMapper.js +1 -1
  3. package/lib/cjs/components/schemaMapper.js.map +1 -1
  4. package/lib/cjs/constants/httpStatusMessages.js +12 -96
  5. package/lib/cjs/constants/httpStatusMessages.js.map +1 -1
  6. package/lib/cjs/decorators/common/anyOf.js +4 -0
  7. package/lib/cjs/decorators/common/anyOf.js.map +1 -1
  8. package/lib/cjs/decorators/common/description.js.map +1 -1
  9. package/lib/cjs/decorators/common/enum.js +1 -20
  10. package/lib/cjs/decorators/common/enum.js.map +1 -1
  11. package/lib/cjs/decorators/common/ignore.js.map +1 -1
  12. package/lib/cjs/decorators/common/jsonEntityFn.js.map +1 -1
  13. package/lib/cjs/decorators/common/oneOf.js +4 -0
  14. package/lib/cjs/decorators/common/oneOf.js.map +1 -1
  15. package/lib/cjs/decorators/common/recordOf.js +63 -0
  16. package/lib/cjs/decorators/common/recordOf.js.map +1 -0
  17. package/lib/cjs/decorators/operations/acceptMime.js +28 -0
  18. package/lib/cjs/decorators/operations/acceptMime.js.map +1 -0
  19. package/lib/cjs/decorators/operations/in.js +6 -4
  20. package/lib/cjs/decorators/operations/in.js.map +1 -1
  21. package/lib/cjs/decorators/operations/view.js +31 -0
  22. package/lib/cjs/decorators/operations/view.js.map +1 -0
  23. package/lib/cjs/domain/DecoratorContext.js.map +1 -1
  24. package/lib/cjs/domain/JsonClassStore.js +1 -1
  25. package/lib/cjs/domain/JsonMap.js.map +1 -1
  26. package/lib/cjs/domain/JsonMethodStore.js +66 -24
  27. package/lib/cjs/domain/JsonMethodStore.js.map +1 -1
  28. package/lib/cjs/domain/JsonOperation.js +11 -26
  29. package/lib/cjs/domain/JsonOperation.js.map +1 -1
  30. package/lib/cjs/domain/JsonOperationRoute.js +4 -0
  31. package/lib/cjs/domain/JsonOperationRoute.js.map +1 -1
  32. package/lib/cjs/domain/JsonParameter.js +38 -44
  33. package/lib/cjs/domain/JsonParameter.js.map +1 -1
  34. package/lib/cjs/domain/JsonParameterStore.js +14 -5
  35. package/lib/cjs/domain/JsonParameterStore.js.map +1 -1
  36. package/lib/cjs/domain/JsonPropertyStore.js +6 -2
  37. package/lib/cjs/domain/JsonPropertyStore.js.map +1 -1
  38. package/lib/cjs/domain/JsonResponse.js +1 -11
  39. package/lib/cjs/domain/JsonResponse.js.map +1 -1
  40. package/lib/cjs/domain/JsonSchema.js +47 -54
  41. package/lib/cjs/domain/JsonSchema.js.map +1 -1
  42. package/lib/cjs/domain/SpecTypes.js +1 -0
  43. package/lib/cjs/domain/SpecTypes.js.map +1 -1
  44. package/lib/cjs/index.js +150 -20
  45. package/lib/cjs/index.js.map +1 -1
  46. package/lib/cjs/interfaces/JsonSchemaOptions.js.map +1 -1
  47. package/lib/cjs/package.json +3 -0
  48. package/lib/cjs/utils/from.js +9 -8
  49. package/lib/cjs/utils/from.js.map +1 -1
  50. package/lib/cjs/utils/generateSpec.js +46 -0
  51. package/lib/cjs/utils/generateSpec.js.map +1 -0
  52. package/lib/cjs/utils/generics.js.map +1 -1
  53. package/lib/cjs/utils/getJsonSchema.js +11 -1
  54. package/lib/cjs/utils/getJsonSchema.js.map +1 -1
  55. package/lib/cjs/utils/getJsonType.js +1 -1
  56. package/lib/cjs/utils/getJsonType.js.map +1 -1
  57. package/lib/cjs/utils/getOperationsRoutes.js +2 -1
  58. package/lib/cjs/utils/getOperationsRoutes.js.map +1 -1
  59. package/lib/cjs/utils/getSpec.js +58 -43
  60. package/lib/cjs/utils/getSpec.js.map +1 -1
  61. package/lib/cjs/utils/getSpecType.js +21 -0
  62. package/lib/cjs/utils/getSpecType.js.map +1 -0
  63. package/lib/cjs/utils/mapNullableType.js +1 -1
  64. package/lib/cjs/utils/mapNullableType.js.map +1 -1
  65. package/lib/cjs/utils/mapOpenSpec.js +41 -0
  66. package/lib/cjs/utils/mapOpenSpec.js.map +1 -0
  67. package/lib/cjs/utils/mapOpenSpec2.js +34 -0
  68. package/lib/cjs/utils/mapOpenSpec2.js.map +1 -0
  69. package/lib/cjs/utils/mapOpenSpec3.js +26 -0
  70. package/lib/cjs/utils/mapOpenSpec3.js.map +1 -0
  71. package/lib/cjs/utils/mapOpenSpecInfo.js +21 -0
  72. package/lib/cjs/utils/mapOpenSpecInfo.js.map +1 -0
  73. package/lib/cjs/utils/matchGroups.js +1 -1
  74. package/lib/cjs/utils/matchGroups.js.map +1 -1
  75. package/lib/cjs/utils/mergeOperation.js +1 -0
  76. package/lib/cjs/utils/mergeOperation.js.map +1 -1
  77. package/lib/cjs/utils/mergeSpec.js.map +1 -1
  78. package/lib/cjs/utils/serializeEnumValues.js +26 -0
  79. package/lib/cjs/utils/serializeEnumValues.js.map +1 -0
  80. package/lib/cjs/utils/transformToOS2.js +510 -0
  81. package/lib/cjs/utils/transformToOS2.js.map +1 -0
  82. package/lib/esm/components/anyMapper.js +4 -4
  83. package/lib/esm/components/classMapper.js +4 -4
  84. package/lib/esm/components/genericsMapper.js +4 -4
  85. package/lib/esm/components/inheritedClassMapper.js +2 -2
  86. package/lib/esm/components/itemMapper.js +1 -1
  87. package/lib/esm/components/lazyRefMapper.js +3 -3
  88. package/lib/esm/components/mapMapper.js +2 -2
  89. package/lib/esm/components/objectMapper.js +3 -3
  90. package/lib/esm/components/ofMapper.js +1 -1
  91. package/lib/esm/components/propertiesMapper.js +1 -1
  92. package/lib/esm/components/schemaMapper.js +7 -7
  93. package/lib/esm/components/schemaMapper.js.map +1 -1
  94. package/lib/esm/constants/httpStatusMessages.js +11 -96
  95. package/lib/esm/constants/httpStatusMessages.js.map +1 -1
  96. package/lib/esm/decorators/class/children.js +1 -1
  97. package/lib/esm/decorators/collections/collectionContains.js +1 -1
  98. package/lib/esm/decorators/collections/collectionOf.js +1 -1
  99. package/lib/esm/decorators/collections/maxItems.js +1 -1
  100. package/lib/esm/decorators/collections/maxProperties.js +1 -1
  101. package/lib/esm/decorators/collections/minItems.js +1 -1
  102. package/lib/esm/decorators/collections/minProperties.js +1 -1
  103. package/lib/esm/decorators/collections/uniqueItems.js +1 -1
  104. package/lib/esm/decorators/common/additionalProperties.js +1 -1
  105. package/lib/esm/decorators/common/allOf.js +1 -1
  106. package/lib/esm/decorators/common/allow.js +2 -2
  107. package/lib/esm/decorators/common/any.js +1 -1
  108. package/lib/esm/decorators/common/anyOf.js +5 -1
  109. package/lib/esm/decorators/common/anyOf.js.map +1 -1
  110. package/lib/esm/decorators/common/const.js +1 -1
  111. package/lib/esm/decorators/common/customKey.js +1 -1
  112. package/lib/esm/decorators/common/default.js +1 -1
  113. package/lib/esm/decorators/common/description.js +1 -1
  114. package/lib/esm/decorators/common/description.js.map +1 -1
  115. package/lib/esm/decorators/common/enum.js +2 -21
  116. package/lib/esm/decorators/common/enum.js.map +1 -1
  117. package/lib/esm/decorators/common/example.js +1 -1
  118. package/lib/esm/decorators/common/examples.js +1 -1
  119. package/lib/esm/decorators/common/exclusiveMaximum.js +1 -1
  120. package/lib/esm/decorators/common/exclusiveMinimum.js +1 -1
  121. package/lib/esm/decorators/common/format.js +2 -2
  122. package/lib/esm/decorators/common/forwardGroups.js +1 -1
  123. package/lib/esm/decorators/common/groups.js +2 -2
  124. package/lib/esm/decorators/common/ignore.js +1 -1
  125. package/lib/esm/decorators/common/ignore.js.map +1 -1
  126. package/lib/esm/decorators/common/integer.js +1 -1
  127. package/lib/esm/decorators/common/jsonEntityFn.js +1 -1
  128. package/lib/esm/decorators/common/jsonEntityFn.js.map +1 -1
  129. package/lib/esm/decorators/common/maxLength.js +1 -1
  130. package/lib/esm/decorators/common/maximum.js +1 -1
  131. package/lib/esm/decorators/common/minLength.js +1 -1
  132. package/lib/esm/decorators/common/minimum.js +1 -1
  133. package/lib/esm/decorators/common/multipleOf.js +1 -1
  134. package/lib/esm/decorators/common/name.js +1 -1
  135. package/lib/esm/decorators/common/nullable.js +2 -2
  136. package/lib/esm/decorators/common/oneOf.js +5 -1
  137. package/lib/esm/decorators/common/oneOf.js.map +1 -1
  138. package/lib/esm/decorators/common/optional.js +1 -1
  139. package/lib/esm/decorators/common/pattern.js +1 -1
  140. package/lib/esm/decorators/common/property.js +1 -1
  141. package/lib/esm/decorators/common/readOnly.js +1 -1
  142. package/lib/esm/decorators/common/recordOf.js +59 -0
  143. package/lib/esm/decorators/common/recordOf.js.map +1 -0
  144. package/lib/esm/decorators/common/required.js +2 -2
  145. package/lib/esm/decorators/common/requiredGroups.js +2 -2
  146. package/lib/esm/decorators/common/schema.js +1 -1
  147. package/lib/esm/decorators/common/title.js +1 -1
  148. package/lib/esm/decorators/common/writeOnly.js +1 -1
  149. package/lib/esm/decorators/config/jsonEntityComponent.js +1 -1
  150. package/lib/esm/decorators/generics/genericOf.js +2 -2
  151. package/lib/esm/decorators/generics/generics.js +1 -1
  152. package/lib/esm/decorators/operations/acceptMime.js +24 -0
  153. package/lib/esm/decorators/operations/acceptMime.js.map +1 -0
  154. package/lib/esm/decorators/operations/consumes.js +1 -1
  155. package/lib/esm/decorators/operations/contentType.js +1 -1
  156. package/lib/esm/decorators/operations/deprecated.js +1 -1
  157. package/lib/esm/decorators/operations/header.js +1 -1
  158. package/lib/esm/decorators/operations/in.js +3 -1
  159. package/lib/esm/decorators/operations/in.js.map +1 -1
  160. package/lib/esm/decorators/operations/inFile.js +5 -5
  161. package/lib/esm/decorators/operations/location.js +1 -1
  162. package/lib/esm/decorators/operations/operationId.js +1 -1
  163. package/lib/esm/decorators/operations/operationPath.js +1 -1
  164. package/lib/esm/decorators/operations/partial.js +1 -1
  165. package/lib/esm/decorators/operations/path.js +1 -1
  166. package/lib/esm/decorators/operations/produces.js +1 -1
  167. package/lib/esm/decorators/operations/redirect.js +2 -2
  168. package/lib/esm/decorators/operations/returns.js +8 -8
  169. package/lib/esm/decorators/operations/route.js +3 -3
  170. package/lib/esm/decorators/operations/security.js +1 -1
  171. package/lib/esm/decorators/operations/status.js +1 -1
  172. package/lib/esm/decorators/operations/summary.js +1 -1
  173. package/lib/esm/decorators/operations/tags.js +1 -1
  174. package/lib/esm/decorators/operations/view.js +27 -0
  175. package/lib/esm/decorators/operations/view.js.map +1 -0
  176. package/lib/esm/domain/DecoratorContext.js +1 -1
  177. package/lib/esm/domain/DecoratorContext.js.map +1 -1
  178. package/lib/esm/domain/JsonClassStore.js +3 -3
  179. package/lib/esm/domain/JsonLazyRef.js +2 -2
  180. package/lib/esm/domain/JsonMap.js +1 -1
  181. package/lib/esm/domain/JsonMap.js.map +1 -1
  182. package/lib/esm/domain/JsonMethodStore.js +68 -26
  183. package/lib/esm/domain/JsonMethodStore.js.map +1 -1
  184. package/lib/esm/domain/JsonOperation.js +10 -25
  185. package/lib/esm/domain/JsonOperation.js.map +1 -1
  186. package/lib/esm/domain/JsonOperationPathsMap.js +1 -1
  187. package/lib/esm/domain/JsonOperationRoute.js +5 -1
  188. package/lib/esm/domain/JsonOperationRoute.js.map +1 -1
  189. package/lib/esm/domain/JsonParameter.js +42 -48
  190. package/lib/esm/domain/JsonParameter.js.map +1 -1
  191. package/lib/esm/domain/JsonParameterStore.js +17 -8
  192. package/lib/esm/domain/JsonParameterStore.js.map +1 -1
  193. package/lib/esm/domain/JsonPropertyStore.js +7 -3
  194. package/lib/esm/domain/JsonPropertyStore.js.map +1 -1
  195. package/lib/esm/domain/JsonRequestBody.js +2 -2
  196. package/lib/esm/domain/JsonResponse.js +4 -14
  197. package/lib/esm/domain/JsonResponse.js.map +1 -1
  198. package/lib/esm/domain/JsonSchema.js +9 -16
  199. package/lib/esm/domain/JsonSchema.js.map +1 -1
  200. package/lib/esm/domain/SpecTypes.js +1 -0
  201. package/lib/esm/domain/SpecTypes.js.map +1 -1
  202. package/lib/esm/index.js +150 -20
  203. package/lib/esm/index.js.map +1 -1
  204. package/lib/esm/interfaces/JsonSchemaOptions.js.map +1 -1
  205. package/lib/esm/package.json +3 -0
  206. package/lib/esm/utils/from.js +5 -4
  207. package/lib/esm/utils/from.js.map +1 -1
  208. package/lib/esm/utils/generateSpec.js +41 -0
  209. package/lib/esm/utils/generateSpec.js.map +1 -0
  210. package/lib/esm/utils/generics.js.map +1 -1
  211. package/lib/esm/utils/getInheritedStores.js +1 -1
  212. package/lib/esm/utils/getJsonEntityStore.js +5 -5
  213. package/lib/esm/utils/getJsonSchema.js +14 -4
  214. package/lib/esm/utils/getJsonSchema.js.map +1 -1
  215. package/lib/esm/utils/getJsonType.js +2 -2
  216. package/lib/esm/utils/getJsonType.js.map +1 -1
  217. package/lib/esm/utils/getOperationsRoutes.js +5 -4
  218. package/lib/esm/utils/getOperationsRoutes.js.map +1 -1
  219. package/lib/esm/utils/getOperationsStores.js +4 -4
  220. package/lib/esm/utils/getPropertiesStores.js +3 -3
  221. package/lib/esm/utils/getRequiredProperties.js +1 -1
  222. package/lib/esm/utils/getSpec.js +65 -50
  223. package/lib/esm/utils/getSpec.js.map +1 -1
  224. package/lib/esm/utils/getSpecType.js +16 -0
  225. package/lib/esm/utils/getSpecType.js.map +1 -0
  226. package/lib/esm/utils/mapNullableType.js +2 -2
  227. package/lib/esm/utils/mapNullableType.js.map +1 -1
  228. package/lib/esm/utils/mapOpenSpec.js +37 -0
  229. package/lib/esm/utils/mapOpenSpec.js.map +1 -0
  230. package/lib/esm/utils/mapOpenSpec2.js +30 -0
  231. package/lib/esm/utils/mapOpenSpec2.js.map +1 -0
  232. package/lib/esm/utils/mapOpenSpec3.js +22 -0
  233. package/lib/esm/utils/mapOpenSpec3.js.map +1 -0
  234. package/lib/esm/utils/mapOpenSpecInfo.js +17 -0
  235. package/lib/esm/utils/mapOpenSpecInfo.js.map +1 -0
  236. package/lib/esm/utils/mapRouteOptions.js +1 -1
  237. package/lib/esm/utils/mergeOperation.js +4 -3
  238. package/lib/esm/utils/mergeOperation.js.map +1 -1
  239. package/lib/esm/utils/mergeSpec.js.map +1 -1
  240. package/lib/esm/utils/ref.js +1 -1
  241. package/lib/esm/utils/serializeEnumValues.js +21 -0
  242. package/lib/esm/utils/serializeEnumValues.js.map +1 -0
  243. package/lib/esm/utils/toJsonMapCollection.js +1 -1
  244. package/lib/esm/utils/transformToOS2.js +504 -0
  245. package/lib/esm/utils/transformToOS2.js.map +1 -0
  246. package/lib/types/constants/httpStatusMessages.d.ts +2 -263
  247. package/lib/types/decorators/common/anyOf.d.ts +4 -0
  248. package/lib/types/decorators/common/ignore.d.ts +1 -1
  249. package/lib/types/decorators/common/jsonEntityFn.d.ts +1 -1
  250. package/lib/types/decorators/common/oneOf.d.ts +4 -0
  251. package/lib/types/decorators/common/recordOf.d.ts +46 -0
  252. package/lib/types/decorators/operations/acceptMime.d.ts +19 -0
  253. package/lib/types/decorators/operations/in.d.ts +1 -1
  254. package/lib/types/decorators/operations/view.d.ts +23 -0
  255. package/lib/types/domain/JsonMap.d.ts +1 -1
  256. package/lib/types/domain/JsonMethodStore.d.ts +51 -2
  257. package/lib/types/domain/JsonOperation.d.ts +2 -1
  258. package/lib/types/domain/JsonOperationRoute.d.ts +5 -3
  259. package/lib/types/domain/JsonParameter.d.ts +2 -1
  260. package/lib/types/domain/JsonParameterStore.d.ts +23 -1
  261. package/lib/types/domain/JsonPropertyStore.d.ts +7 -0
  262. package/lib/types/domain/JsonResponse.d.ts +2 -1
  263. package/lib/types/domain/JsonSchema.d.ts +2 -2
  264. package/lib/types/domain/SpecTypes.d.ts +1 -0
  265. package/lib/types/index.d.ts +143 -13
  266. package/lib/types/interfaces/JsonSchemaOptions.d.ts +2 -2
  267. package/lib/types/utils/generateSpec.d.ts +16 -0
  268. package/lib/types/utils/generics.d.ts +1 -1
  269. package/lib/types/utils/getJsonSchema.d.ts +12 -2
  270. package/lib/types/utils/getOperationsRoutes.d.ts +2 -2
  271. package/lib/types/utils/getSpec.d.ts +5 -4
  272. package/lib/types/utils/getSpecType.d.ts +12 -0
  273. package/lib/types/utils/mapNullableType.d.ts +1 -1
  274. package/lib/types/utils/mapOpenSpec.d.ts +10 -0
  275. package/lib/types/utils/mapOpenSpec2.d.ts +9 -0
  276. package/lib/types/utils/mapOpenSpec3.d.ts +8 -0
  277. package/lib/types/utils/mapOpenSpecInfo.d.ts +6 -0
  278. package/lib/types/utils/mergeSpec.d.ts +2 -2
  279. package/lib/types/utils/serializeEnumValues.d.ts +5 -0
  280. package/lib/types/utils/transformToOS2.d.ts +25 -0
  281. package/package.json +30 -15
  282. package/readme.md +1 -0
  283. package/tsconfig.compile.esm.json +2 -12
  284. package/benchmark/cold-start.js +0 -17
  285. package/lib/cjs/components/index.js +0 -15
  286. package/lib/cjs/components/index.js.map +0 -1
  287. package/lib/cjs/decorators/index.js +0 -77
  288. package/lib/cjs/decorators/index.js.map +0 -1
  289. package/lib/cjs/domain/index.js +0 -20
  290. package/lib/cjs/domain/index.js.map +0 -1
  291. package/lib/cjs/interfaces/index.js +0 -8
  292. package/lib/cjs/interfaces/index.js.map +0 -1
  293. package/lib/esm/components/index.js +0 -12
  294. package/lib/esm/components/index.js.map +0 -1
  295. package/lib/esm/decorators/index.js +0 -74
  296. package/lib/esm/decorators/index.js.map +0 -1
  297. package/lib/esm/domain/index.js +0 -17
  298. package/lib/esm/domain/index.js.map +0 -1
  299. package/lib/esm/interfaces/index.js +0 -5
  300. package/lib/esm/interfaces/index.js.map +0 -1
  301. package/lib/types/components/index.d.ts +0 -11
  302. package/lib/types/decorators/index.d.ts +0 -68
  303. package/lib/types/domain/index.d.ts +0 -16
  304. package/lib/types/interfaces/index.d.ts +0 -4
@@ -1 +1 @@
1
- {"version":3,"file":"JsonSchemaOptions.js","sourceRoot":"","sources":["../../../src/interfaces/JsonSchemaOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {OpenSpecHash, OS3Schema} from \"@tsed/openspec\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\n\nexport interface JsonSchemaOptions {\n /**\n * Map properties with the alias name. By default: false\n */\n useAlias?: boolean;\n /**\n * Reference to Schema Object.\n */\n schemas?: OpenSpecHash<OS3Schema>;\n /**\n * Define Spec types level\n */\n specType?: SpecTypes;\n /**\n * Define a groups restriction to generate the JsonSchema.\n * Set false to disable groups.\n */\n groups?: string[] | false;\n /**\n * Generate custom keys when SpecType is JSON.\n */\n customKeys?: boolean;\n\n [key: string]: any;\n}\n"]}
1
+ {"version":3,"file":"JsonSchemaOptions.js","sourceRoot":"","sources":["../../../src/interfaces/JsonSchemaOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {OpenSpecHash, OS2Schema, OS3Schema} from \"@tsed/openspec\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\n\nexport interface JsonSchemaOptions {\n /**\n * Map properties with the alias name. By default: false\n */\n useAlias?: boolean;\n /**\n * Reference to Schema Object.\n */\n schemas?: OpenSpecHash<OS3Schema | OS2Schema>;\n /**\n * Define Spec types level\n */\n specType?: SpecTypes;\n /**\n * Define a groups restriction to generate the JsonSchema.\n * Set false to disable groups.\n */\n groups?: string[] | false;\n /**\n * Generate custom keys when SpecType is JSON.\n */\n customKeys?: boolean;\n\n [key: string]: any;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -1,8 +1,9 @@
1
1
  import { isClass } from "@tsed/core";
2
- import { JsonEntityStore, JsonFormatTypes } from "../domain";
3
- import { JsonLazyRef } from "../domain/JsonLazyRef";
4
- import { JsonSchema } from "../domain/JsonSchema";
5
- import { getJsonEntityStore } from "./getJsonEntityStore";
2
+ import { JsonEntityStore } from "../domain/JsonEntityStore.js";
3
+ import { JsonFormatTypes } from "../domain/JsonFormatTypes.js";
4
+ import { JsonLazyRef } from "../domain/JsonLazyRef.js";
5
+ import { JsonSchema } from "../domain/JsonSchema.js";
6
+ import { getJsonEntityStore } from "./getJsonEntityStore.js";
6
7
  /**
7
8
  * Create a new model from the given type.
8
9
  *
@@ -1 +1 @@
1
- {"version":3,"file":"from.js","sourceRoot":"","sources":["../../../src/utils/from.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAO,MAAM,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AAC,aAA0C,EAAE;IACjE,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,GAAG,CAAC,GAAG,KAAY;IACjC,OAAO,IAAI,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,KAAK,CAAC,GAAG,KAAY;IACnC,OAAO,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,KAAK,CAAC,GAAG,KAAY;IACnC,OAAO,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,KAAK,CAAC,GAAG,KAAY;IACnC,OAAO,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,EAAmB;IACzC,IAAI;QACF,2CAA2C;QAC3C,IAAI,EAAE,EAAE,EAAE;YACR,6BAA6B;YAC7B,OAAO,eAAe,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,MAAa,CAAC;SACjD;KACF;IAAC,OAAO,EAAE,EAAE,GAAE;IAEf,OAAO,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import {isClass, Type} from \"@tsed/core\";\nimport {JsonEntityStore, JsonFormatTypes} from \"../domain\";\nimport {JsonLazyRef} from \"../domain/JsonLazyRef\";\nimport {JsonSchema} from \"../domain/JsonSchema\";\nimport {getJsonEntityStore} from \"./getJsonEntityStore\";\n\n/**\n * Create a new model from the given type.\n *\n * ```typescript\n * from(String)\n * ```\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function from(type: Type<any> = Object) {\n if (isClass(type)) {\n const {schema} = getJsonEntityStore(type);\n\n schema.properties = function properties(obj: {[key: string]: JsonSchema}) {\n Object.entries(obj).forEach(([propertyKey, propSchema]) => {\n getJsonEntityStore(type.prototype, propertyKey).schema.assign(propSchema);\n });\n\n return this;\n };\n\n return schema;\n }\n\n return JsonSchema.from({type});\n}\n\n/**\n * Declare a new number model.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function number() {\n return from(Number);\n}\n\n/**\n * Declare a new integer model.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function integer() {\n return from(Number).integer();\n}\n\n/**\n * Declare a new string model.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function string() {\n return from(String);\n}\n\n/**\n * Declare a new boolean model.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function boolean() {\n return from(Boolean);\n}\n\n/**\n * Declare a new string model with `format: date`.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function date() {\n return from(Date).format(JsonFormatTypes.DATE);\n}\n\n/**\n * Declare a new string model with `format: datetime`.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function datetime() {\n return from(Date).format(JsonFormatTypes.DATE_TIME);\n}\n\n/**\n * Declare a new string model with `format: time`.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function time() {\n return from(Date).format(JsonFormatTypes.TIME);\n}\n\n/**\n * Declare a new string model with `format: email`.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function email() {\n return from(String).format(JsonFormatTypes.EMAIL);\n}\n\n/**\n * Declare a new string model with `format: uri`.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function uri() {\n return from(String).format(JsonFormatTypes.URI);\n}\n\n/**\n * Declare a new string model with `format: url`.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function url() {\n return from(String).format(JsonFormatTypes.URL);\n}\n\n/**\n * Declare a new object model with `additionalProperties: true`.\n *\n * ```json\n * {\n * \"type\": \"array\"\n * }\n * ```\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function array() {\n return from(Array);\n}\n\n/**\n * Declare a new object model with `additionalProperties: true`.\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"additionalProperties\": true\n * }\n * ```\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function map() {\n return from(Map).unknown(true);\n}\n\n/**\n * Declare a new array model with `uniqueItems: true`.\n *\n * ```json\n * {\n * \"type\": \"array\",\n * \"uniqueItems\": true\n * }\n * ```\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function set() {\n return from(Array).uniqueItems(true);\n}\n\n/**\n * Declare a new object model.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function object(properties: {[key: string]: JsonSchema} = {}) {\n return from(Object).properties(properties);\n}\n\n/**\n * Declare a model with any type (By default: `integer`, `number`, `string`, `boolean`, `array`, `object`, `null`)\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function any(...types: any[]) {\n return from().any(...types);\n}\n\n/**\n * See https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.27\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.27\n * @schemaFunctional\n */\nexport function anyOf(...anyOf: any[]) {\n return from().anyOf(anyOf);\n}\n\n/**\n * See https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.28\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.28\n */\nexport function oneOf(...oneOf: any[]) {\n return from().oneOf(oneOf);\n}\n\n/**\n * See https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.26\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.26\n * @schemaFunctional\n */\nexport function allOf(...allOf: any[]) {\n return from().allOf(allOf);\n}\n\n/**\n * Declare a sub schema which will be resolved later. Use this function when you have a circular reference between two schemes.\n *\n * @schemaFunctional\n */\nexport function lazyRef(cb: () => Type<any>) {\n try {\n // solve issue with a self referenced model\n if (cb()) {\n // type is already accessible\n return JsonEntityStore.from(cb()).schema as any;\n }\n } catch (er) {}\n\n return new JsonLazyRef(cb);\n}\n"]}
1
+ {"version":3,"file":"from.js","sourceRoot":"","sources":["../../../src/utils/from.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAO,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAC,WAAW,EAAC,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAExD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,IAAI,CAAC,OAAkB,MAAM;IAC3C,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE;QACjB,MAAM,EAAC,MAAM,EAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAE1C,MAAM,CAAC,UAAU,GAAG,SAAS,UAAU,CAAC,GAAgC;YACtE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,EAAE;gBACxD,kBAAkB,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW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AAC;AAC7B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,EAAmB;IACzC,IAAI;QACF,2CAA2C;QAC3C,IAAI,EAAE,EAAE,EAAE;YACR,6BAA6B;YAC7B,OAAO,eAAe,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,MAAa,CAAC;SACjD;KACF;IAAC,OAAO,EAAE,EAAE,GAAE;IAEf,OAAO,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import {isClass, Type} from \"@tsed/core\";\nimport {JsonEntityStore} from \"../domain/JsonEntityStore\";\nimport {JsonFormatTypes} from \"../domain/JsonFormatTypes\";\nimport {JsonLazyRef} from \"../domain/JsonLazyRef\";\nimport {JsonSchema} from \"../domain/JsonSchema\";\nimport {getJsonEntityStore} from \"./getJsonEntityStore\";\n\n/**\n * Create a new model from the given type.\n *\n * ```typescript\n * from(String)\n * ```\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function from(type: Type<any> = Object) {\n if (isClass(type)) {\n const {schema} = getJsonEntityStore(type);\n\n schema.properties = function properties(obj: {[key: string]: JsonSchema}) {\n Object.entries(obj).forEach(([propertyKey, propSchema]) => {\n getJsonEntityStore(type.prototype, propertyKey).schema.assign(propSchema);\n });\n\n return this;\n };\n\n return schema;\n }\n\n return JsonSchema.from({type});\n}\n\n/**\n * Declare a new number model.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function number() {\n return from(Number);\n}\n\n/**\n * Declare a new integer model.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function integer() {\n return from(Number).integer();\n}\n\n/**\n * Declare a new string model.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function string() {\n return from(String);\n}\n\n/**\n * Declare a new boolean model.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function boolean() {\n return from(Boolean);\n}\n\n/**\n * Declare a new string model with `format: date`.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function date() {\n return from(Date).format(JsonFormatTypes.DATE);\n}\n\n/**\n * Declare a new string model with `format: datetime`.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function datetime() {\n return from(Date).format(JsonFormatTypes.DATE_TIME);\n}\n\n/**\n * Declare a new string model with `format: time`.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function time() {\n return from(Date).format(JsonFormatTypes.TIME);\n}\n\n/**\n * Declare a new string model with `format: email`.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function email() {\n return from(String).format(JsonFormatTypes.EMAIL);\n}\n\n/**\n * Declare a new string model with `format: uri`.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function uri() {\n return from(String).format(JsonFormatTypes.URI);\n}\n\n/**\n * Declare a new string model with `format: url`.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function url() {\n return from(String).format(JsonFormatTypes.URL);\n}\n\n/**\n * Declare a new object model with `additionalProperties: true`.\n *\n * ```json\n * {\n * \"type\": \"array\"\n * }\n * ```\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function array() {\n return from(Array);\n}\n\n/**\n * Declare a new object model with `additionalProperties: true`.\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"additionalProperties\": true\n * }\n * ```\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function map() {\n return from(Map).unknown(true);\n}\n\n/**\n * Declare a new array model with `uniqueItems: true`.\n *\n * ```json\n * {\n * \"type\": \"array\",\n * \"uniqueItems\": true\n * }\n * ```\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function set() {\n return from(Array).uniqueItems(true);\n}\n\n/**\n * Declare a new object model.\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function object(properties: {[key: string]: JsonSchema} = {}) {\n return from(Object).properties(properties);\n}\n\n/**\n * Declare a model with any type (By default: `integer`, `number`, `string`, `boolean`, `array`, `object`, `null`)\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n */\nexport function any(...types: any[]) {\n return from().any(...types);\n}\n\n/**\n * See https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.27\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.27\n * @schemaFunctional\n */\nexport function anyOf(...anyOf: any[]) {\n return from().anyOf(anyOf);\n}\n\n/**\n * See https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.28\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @schemaFunctional\n * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.28\n */\nexport function oneOf(...oneOf: any[]) {\n return from().oneOf(oneOf);\n}\n\n/**\n * See https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.26\n *\n * * See @@JsonSchema@@ to discover available methods.\n *\n * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.26\n * @schemaFunctional\n */\nexport function allOf(...allOf: any[]) {\n return from().allOf(allOf);\n}\n\n/**\n * Declare a sub schema which will be resolved later. Use this function when you have a circular reference between two schemes.\n *\n * @schemaFunctional\n */\nexport function lazyRef(cb: () => Type<any>) {\n try {\n // solve issue with a self referenced model\n if (cb()) {\n // type is already accessible\n return JsonEntityStore.from(cb()).schema as any;\n }\n } catch (er) {}\n\n return new JsonLazyRef(cb);\n}\n"]}
@@ -0,0 +1,41 @@
1
+ import fs from "fs-extra";
2
+ import { getValue } from "@tsed/core";
3
+ import { mapOpenSpec } from "./mapOpenSpec.js";
4
+ import { getSpec } from "./getSpec.js";
5
+ import { getSpecTypeFromSpec } from "./getSpecType.js";
6
+ import { mergeSpec } from "./mergeSpec.js";
7
+ import { SpecTypes } from "../domain/SpecTypes.js";
8
+ import { transformToOS2 } from "./transformToOS2.js";
9
+ async function readSpec(path) {
10
+ if (fs.existsSync(path)) {
11
+ try {
12
+ return await fs.readJSON(path, { encoding: "utf8" });
13
+ }
14
+ catch (e) { }
15
+ }
16
+ /* istanbul ignore next */
17
+ return {};
18
+ }
19
+ /**
20
+ * Generate OpenAPI spec from multiple sources (models, files, conf)
21
+ * @param tokens
22
+ * @param options
23
+ */
24
+ export async function generateSpec({ tokens, ...options }) {
25
+ const { version = "1.0.0", acceptMimes, specPath, specVersion } = options;
26
+ const fileSpec = specPath ? await readSpec(specPath) : {};
27
+ const defaultSpec = mapOpenSpec(getValue(options, "spec", {}), {
28
+ fileSpec,
29
+ version,
30
+ specVersion,
31
+ acceptMimes
32
+ });
33
+ const specType = getSpecTypeFromSpec(defaultSpec);
34
+ let controllersSpec = getSpec(tokens, options);
35
+ const spec = mergeSpec(defaultSpec, controllersSpec);
36
+ if (specType === SpecTypes.SWAGGER) {
37
+ return transformToOS2(spec);
38
+ }
39
+ return spec;
40
+ }
41
+ //# sourceMappingURL=generateSpec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateSpec.js","sourceRoot":"","sources":["../../../src/utils/generateSpec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,OAAO,EAA0C,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAC,mBAAmB,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAC,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enSpec\";\nimport {getSpec, JsonTokenOptions, SpecSerializerOptions} from \"./getSpec\";\nimport {getSpecTypeFromSpec} from \"./getSpecType\";\nimport {mergeSpec} from \"./mergeSpec\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {transformToOS2} from \"./transformToOS2\";\n\nexport interface GenerateSpecOptions extends Omit<SpecSerializerOptions, \"specType\"> {\n tokens: JsonTokenOptions;\n version?: string;\n acceptMimes?: string;\n specPath?: string;\n specVersion?: string;\n spec?: any;\n}\n\nasync function readSpec(path: string) {\n if (fs.existsSync(path)) {\n try {\n return await fs.readJSON(path, {encoding: \"utf8\"});\n } catch (e) {}\n }\n\n /* istanbul ignore next */\n return {};\n}\n\n/**\n * Generate OpenAPI spec from multiple sources (models, files, conf)\n * @param tokens\n * @param options\n */\nexport async function generateSpec({tokens, ...options}: GenerateSpecOptions): Promise<OpenSpec2 | OpenSpec3> {\n const {version = \"1.0.0\", acceptMimes, specPath, specVersion} = options;\n const fileSpec: Partial<OpenSpec2 | OpenSpec3> = specPath ? await readSpec(specPath) : {};\n\n const defaultSpec = mapOpenSpec(getValue(options, \"spec\", {}), {\n fileSpec,\n version,\n specVersion,\n acceptMimes\n });\n\n const specType = getSpecTypeFromSpec(defaultSpec);\n\n let controllersSpec: any = getSpec(tokens, options);\n const spec: any = mergeSpec(defaultSpec, controllersSpec);\n\n if (specType === SpecTypes.SWAGGER) {\n return transformToOS2(spec) as any;\n }\n\n return spec;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"generics.js","sourceRoot":"","sources":["../../../src/utils/generics.ts"],"names":[],"mappings":"AA4CA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,aAAuB,EAAE,YAA4B;IAClF,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,GAAqB,EAAE,IAAY,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;AACrI,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAA8C;IAC/E,IAAI,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,YAAY,EAAE;QACjD,MAAM,EAAC,aAAa,EAAE,YAAY,EAAE,GAAG,GAAG,EAAC,GAAG,OAAO,CAAC;QAEtD,OAAO;YACL,GAAG,GAAG;YACN,QAAQ,EAAE,cAAc,CAAC,aAAa,EAAE,YAAY,CAAC;SACtD,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAqB;IAC/C,MAAM,CAAC,YAAY,EAAE,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC,cAAc,CAAC;IAEpD,OAAO;QACL,YAAY;QACZ,cAAc,EAAE,GAAG;KACpB,CAAC;AACJ,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {JsonSchema} from \"../domain\";\n\nexport type GenericValue = Type<any> | JsonSchema | any;\n\n/**\n * @ignore\n */\nexport type GenericsMap = Map<string, GenericValue>;\n\n/**\n * @ignore\n */\nexport interface GenericTypes {\n genericTypes: Type<any>[];\n\n [key: string]: any;\n}\n\n/**\n * @ignore\n */\nexport interface GenericLabels {\n genericLabels: string[];\n\n [key: string]: any;\n}\n\n/**\n * @ignore\n */\nexport interface NestedGenerics {\n nestedGenerics: GenericValue[][];\n\n [key: string]: any;\n}\n\n/**\n * @ignore\n */\nexport interface GenericsContext extends GenericTypes, GenericLabels, NestedGenerics {\n generics: GenericsMap;\n}\n\n/**\n * @ignore\n * @param genericLabels\n * @param genericTypes\n */\nexport function getGenericsMap(genericLabels: string[], genericTypes: GenericValue[]): GenericsMap {\n return genericLabels.reduce((map: Map<string, any>, item: string, index: number) => map.set(item, genericTypes[index]), new Map());\n}\n\n/**\n * @ignore\n * @param options\n */\nexport function mapGenericsOptions(options: Partial<GenericTypes & GenericLabels>) {\n if (options.genericLabels && options.genericTypes) {\n const {genericLabels, genericTypes, ...ops} = options;\n\n return {\n ...ops,\n generics: getGenericsMap(genericLabels, genericTypes)\n };\n }\n\n return options;\n}\n\n/**\n * @ignore\n * @param value\n */\nexport function popGenerics(value: NestedGenerics): NestedGenerics & GenericTypes {\n const [genericTypes, ...out] = value.nestedGenerics;\n\n return {\n genericTypes,\n nestedGenerics: out\n };\n}\n"]}
1
+ {"version":3,"file":"generics.js","sourceRoot":"","sources":["../../../src/utils/generics.ts"],"names":[],"mappings":"AA4CA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,aAAuB,EAAE,YAA4B;IAClF,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,GAAqB,EAAE,IAAY,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;AACrI,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAA8C;IAC/E,IAAI,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,YAAY,EAAE;QACjD,MAAM,EAAC,aAAa,EAAE,YAAY,EAAE,GAAG,GAAG,EAAC,GAAG,OAAO,CAAC;QAEtD,OAAO;YACL,GAAG,GAAG;YACN,QAAQ,EAAE,cAAc,CAAC,aAAa,EAAE,YAAY,CAAC;SACtD,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAqB;IAC/C,MAAM,CAAC,YAAY,EAAE,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC,cAAc,CAAC;IAEpD,OAAO;QACL,YAAY;QACZ,cAAc,EAAE,GAAG;KACpB,CAAC;AACJ,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {JsonSchema} from \"../domain/JsonSchema\";\n\nexport type GenericValue = Type<any> | JsonSchema | any;\n\n/**\n * @ignore\n */\nexport type GenericsMap = Map<string, GenericValue>;\n\n/**\n * @ignore\n */\nexport interface GenericTypes {\n genericTypes: Type<any>[];\n\n [key: string]: any;\n}\n\n/**\n * @ignore\n */\nexport interface GenericLabels {\n genericLabels: string[];\n\n [key: string]: any;\n}\n\n/**\n * @ignore\n */\nexport interface NestedGenerics {\n nestedGenerics: GenericValue[][];\n\n [key: string]: any;\n}\n\n/**\n * @ignore\n */\nexport interface GenericsContext extends GenericTypes, GenericLabels, NestedGenerics {\n generics: GenericsMap;\n}\n\n/**\n * @ignore\n * @param genericLabels\n * @param genericTypes\n */\nexport function getGenericsMap(genericLabels: string[], genericTypes: GenericValue[]): GenericsMap {\n return genericLabels.reduce((map: Map<string, any>, item: string, index: number) => map.set(item, genericTypes[index]), new Map());\n}\n\n/**\n * @ignore\n * @param options\n */\nexport function mapGenericsOptions(options: Partial<GenericTypes & GenericLabels>) {\n if (options.genericLabels && options.genericTypes) {\n const {genericLabels, genericTypes, ...ops} = options;\n\n return {\n ...ops,\n generics: getGenericsMap(genericLabels, genericTypes)\n };\n }\n\n return options;\n}\n\n/**\n * @ignore\n * @param value\n */\nexport function popGenerics(value: NestedGenerics): NestedGenerics & GenericTypes {\n const [genericTypes, ...out] = value.nestedGenerics;\n\n return {\n genericTypes,\n nestedGenerics: out\n };\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { ancestorsOf } from "@tsed/core";
2
- import { getJsonEntityStore } from "./getJsonEntityStore";
2
+ import { getJsonEntityStore } from "./getJsonEntityStore.js";
3
3
  /**
4
4
  * Return store and his inherited stores
5
5
  * @param target
@@ -1,9 +1,9 @@
1
1
  import { DecoratorTypes } from "@tsed/core";
2
- import { JsonEntitiesContainer, JsonEntityStore } from "../domain/JsonEntityStore";
3
- import { JsonClassStore } from "../domain/JsonClassStore";
4
- import { JsonPropertyStore } from "../domain/JsonPropertyStore";
5
- import { JsonParameterStore } from "../domain/JsonParameterStore";
6
- import { JsonMethodStore } from "../domain/JsonMethodStore";
2
+ import { JsonEntitiesContainer, JsonEntityStore } from "../domain/JsonEntityStore.js";
3
+ import { JsonClassStore } from "../domain/JsonClassStore.js";
4
+ import { JsonPropertyStore } from "../domain/JsonPropertyStore.js";
5
+ import { JsonParameterStore } from "../domain/JsonParameterStore.js";
6
+ import { JsonMethodStore } from "../domain/JsonMethodStore.js";
7
7
  JsonEntitiesContainer.set(DecoratorTypes.CLASS, JsonClassStore);
8
8
  JsonEntitiesContainer.set(DecoratorTypes.PROP, JsonPropertyStore);
9
9
  JsonEntitiesContainer.set(DecoratorTypes.PARAM, JsonParameterStore);
@@ -1,7 +1,17 @@
1
- import "../components";
2
- import { SpecTypes } from "../domain/SpecTypes";
3
- import { execMapper } from "../registries/JsonSchemaMapperContainer";
4
- import { getJsonEntityStore } from "./getJsonEntityStore";
1
+ import { SpecTypes } from "../domain/SpecTypes.js";
2
+ import { execMapper } from "../registries/JsonSchemaMapperContainer.js";
3
+ import { getJsonEntityStore } from "./getJsonEntityStore.js";
4
+ import "../components/anyMapper.js";
5
+ import "../components/classMapper.js";
6
+ import "../components/genericsMapper.js";
7
+ import "../components/inheritedClassMapper.js";
8
+ import "../components/itemMapper.js";
9
+ import "../components/lazyRefMapper.js";
10
+ import "../components/mapMapper.js";
11
+ import "../components/objectMapper.js";
12
+ import "../components/ofMapper.js";
13
+ import "../components/propertiesMapper.js";
14
+ import "../components/schemaMapper.js";
5
15
  /**
6
16
  * @ignore
7
17
  */
@@ -1 +1 @@
1
- {"version":3,"file":"getJsonSchema.js","sourceRoot":"","sources":["../../../src/utils/getJsonSchema.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAC;AAEvB,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,UAAU,EAAC,MAAM,yCAAyC,CAAC;AACnE,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAExD;;GAEG;AACH,MAAM,SAAS,GAAG,gBAAgB,CAAC;AAEnC;;GAE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AAC;YACtC,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,MAAM,EAAE,MAAA,MAAM,CAAC,SAAS,0CAAE,MAAM;SACjC,CAAC;KACH;IAED,OAAO,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport \"../components\";\nimport type {JsonEntityStore} from \"../domain/JsonEntityStore\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {JsonSchemaOptions} from \"../interfaces\";\nimport {execMapper} from \"../registries/JsonSchemaMapperContainer\";\nimport {getJsonEntityStore} from \"./getJsonEntityStore\";\n\n/**\n * @ignore\n */\nconst CACHE_KEY = \"$cache:schemes\";\n\n/**\n * @ignore\n */\nfunction getKey(options: any) {\n return JSON.stringify(options);\n}\n\n/**\n * @ignore\n */\nfunction get(entity: JsonEntityStore, options: any) {\n const cache: Map<string, any> = entity.store.get(CACHE_KEY) || new Map();\n const key = getKey(options);\n\n if (!cache.has(key)) {\n const schema = execMapper(\"schema\", entity.schema, options);\n\n if (Object.keys(options.schemas).length) {\n schema.definitions = options.schemas;\n }\n\n cache.set(key, schema);\n }\n\n entity.store.set(CACHE_KEY, cache);\n\n return cache.get(key);\n}\n\nexport function getJsonSchema(model: Type<any> | any, options: JsonSchemaOptions = {}) {\n const entity = getJsonEntityStore(model);\n\n options = {\n endpoint: true,\n groups: [],\n ...options,\n specType: options.specType || SpecTypes.JSON,\n schemas: {}\n };\n\n if (entity.decoratorType === \"parameter\") {\n options = {\n ...options,\n genericTypes: entity.nestedGenerics[0],\n nestedGenerics: entity.nestedGenerics,\n groups: entity.parameter?.groups\n };\n }\n\n return get(entity, options);\n}\n"]}
1
+ {"version":3,"file":"getJsonSchema.js","sourceRoot":"","sources":["../../../src/utils/getJsonSchema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,UAAU,EAAC,MAAM,yCAAyC,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UAAU,aAAa,CAAC,KAAsB,EAAE,UAA6B,EAAE;;IACnF,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAEzC,OAAO,GAAG;QACR,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,EAAE;QACV,GAAG,OAAO;QACV,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,SAAS,CAAC,IAAI;QAC5C,OAAO,EAAE,EAAE;KACZ,CAAC;IAEF,IAAI,MAAM,CAAC,aAAa,KAAK,WAAW,EAAE;QACxC,OAAO,GAAG;YACR,GAAG,OAAO;YACV,YAAY,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC;YACtC,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,MAAM,EAAE,MAAA,MAAM,CAAC,SAAS,0CAAE,MAAM;SACjC,CAAC;KACH;IAED,OAAO,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport type {JsonEntityStore} from \"../domain/JsonEntityStore\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\nimport {execMapper} from \"../registries/JsonSchemaMapperContainer\";\nimport {getJsonEntityStore} from \"./getJsonEntityStore\";\nimport \"../components/anyMapper\";\nimport \"../components/classMapper\";\nimport \"../components/genericsMapper\";\nimport \"../components/inheritedClassMapper\";\nimport \"../components/itemMapper\";\nimport \"../components/lazyRefMapper\";\nimport \"../components/mapMapper\";\nimport \"../components/objectMapper\";\nimport \"../components/ofMapper\";\nimport \"../components/propertiesMapper\";\nimport \"../components/schemaMapper\";\n\n/**\n * @ignore\n */\nconst CACHE_KEY = \"$cache:schemes\";\n\n/**\n * @ignore\n */\nfunction getKey(options: any) {\n return JSON.stringify(options);\n}\n\n/**\n * @ignore\n */\nfunction get(entity: JsonEntityStore, options: any) {\n const cache: Map<string, any> = entity.store.get(CACHE_KEY) || new Map();\n const key = getKey(options);\n\n if (!cache.has(key)) {\n const schema = execMapper(\"schema\", entity.schema, options);\n\n if (Object.keys(options.schemas).length) {\n schema.definitions = options.schemas;\n }\n\n cache.set(key, schema);\n }\n\n entity.store.set(CACHE_KEY, cache);\n\n return cache.get(key);\n}\n\nexport function getJsonSchema(model: Type<any> | any, options: JsonSchemaOptions = {}) {\n const entity = getJsonEntityStore(model);\n\n options = {\n endpoint: true,\n groups: [],\n ...options,\n specType: options.specType || SpecTypes.JSON,\n schemas: {}\n };\n\n if (entity.decoratorType === \"parameter\") {\n options = {\n ...options,\n genericTypes: entity.nestedGenerics[0],\n nestedGenerics: entity.nestedGenerics,\n groups: entity.parameter?.groups\n };\n }\n\n return get(entity, options);\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { isArray, isDate, isPrimitiveOrPrimitiveClass, primitiveOf } from "@tsed/core";
1
+ import { isArray, isBuffer, isDate, isPrimitiveOrPrimitiveClass, primitiveOf } from "@tsed/core";
2
2
  /**
3
3
  * @ignore
4
4
  */
@@ -28,7 +28,7 @@ export function getJsonType(value) {
28
28
  if (value === Set) {
29
29
  return "array";
30
30
  }
31
- if (isDate(value)) {
31
+ if (isDate(value) || isBuffer(value)) {
32
32
  return "string";
33
33
  }
34
34
  return "object";
@@ -1 +1 @@
1
- {"version":3,"file":"getJsonType.js","sourceRoot":"","sources":["../../../src/utils/getJsonType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,2BAA2B,EAAE,WAAW,EAAC,MAAM,YAAY,CAAC;AAErF;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAEvG,MAAM,UAAU,WAAW,CAAC,KAAU;IACpC,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,OAAO,MAAM,CAAC;KACf;IAED,IAAI,2BAA2B,CAAC,KAAK,CAAC,EAAE;QACtC,IAAI,UAAU,CAAC,OAAO,CAAC,KAAe,CAAC,GAAG,CAAC,CAAC,EAAE;YAC5C,OAAO,KAAK,CAAC;SACd;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,IAAI,KAAK,KAAK,MAAM,EAAE;gBACpB,OAAO,MAAM,CAAC;aACf;YAED,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;KAC3B;IAED,IAAI,KAAK,KAAK,KAAK,EAAE;QACnB,OAAO,OAAO,CAAC;KAChB;IAED,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE;QAClB,OAAO,KAAK,CAAC,GAAG,CAAC,WAAW,CAAQ,CAAC;KACtC;IAED,IAAI,KAAK,KAAK,GAAG,EAAE;QACjB,OAAO,OAAO,CAAC;KAChB;IAED,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE;QACjB,OAAO,QAAQ,CAAC;KACjB;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {isArray, isDate, isPrimitiveOrPrimitiveClass, primitiveOf} from \"@tsed/core\";\n\n/**\n * @ignore\n */\nexport const JSON_TYPES = [\"string\", \"number\", \"integer\", \"boolean\", \"object\", \"array\", \"null\", \"any\"];\n\nexport function getJsonType(value: any): string {\n if (value === null) {\n return \"null\";\n }\n\n if (isPrimitiveOrPrimitiveClass(value)) {\n if (JSON_TYPES.indexOf(value as string) > -1) {\n return value;\n }\n\n if (typeof value === \"string\") {\n if (value === \"file\") {\n return \"file\";\n }\n\n return \"generic\";\n }\n\n return primitiveOf(value);\n }\n\n if (value === Array) {\n return \"array\";\n }\n\n if (isArray(value)) {\n return value.map(getJsonType) as any;\n }\n\n if (value === Set) {\n return \"array\";\n }\n\n if (isDate(value)) {\n return \"string\";\n }\n\n return \"object\";\n}\n"]}
1
+ {"version":3,"file":"getJsonType.js","sourceRoot":"","sources":["../../../src/utils/getJsonType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,2BAA2B,EAAE,WAAW,EAAC,MAAM,YAAY,CAAC;AAE/F;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAEvG,MAAM,UAAU,WAAW,CAAC,KAAU;IACpC,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,OAAO,MAAM,CAAC;KACf;IAED,IAAI,2BAA2B,CAAC,KAAK,CAAC,EAAE;QACtC,IAAI,UAAU,CAAC,OAAO,CAAC,KAAe,CAAC,GAAG,CAAC,CAAC,EAAE;YAC5C,OAAO,KAAK,CAAC;SACd;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,IAAI,KAAK,KAAK,MAAM,EAAE;gBACpB,OAAO,MAAM,CAAC;aACf;YAED,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;KAC3B;IAED,IAAI,KAAK,KAAK,KAAK,EAAE;QACnB,OAAO,OAAO,CAAC;KAChB;IAED,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE;QAClB,OAAO,KAAK,CAAC,GAAG,CAAC,WAAW,CAAQ,CAAC;KACtC;IAED,IAAI,KAAK,KAAK,GAAG,EAAE;QACjB,OAAO,OAAO,CAAC;KAChB;IAED,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE;QACpC,OAAO,QAAQ,CAAC;KACjB;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {isArray, isBuffer, isDate, isPrimitiveOrPrimitiveClass, primitiveOf} from \"@tsed/core\";\n\n/**\n * @ignore\n */\nexport const JSON_TYPES = [\"string\", \"number\", \"integer\", \"boolean\", \"object\", \"array\", \"null\", \"any\"];\n\nexport function getJsonType(value: any): string {\n if (value === null) {\n return \"null\";\n }\n\n if (isPrimitiveOrPrimitiveClass(value)) {\n if (JSON_TYPES.indexOf(value as string) > -1) {\n return value;\n }\n\n if (typeof value === \"string\") {\n if (value === \"file\") {\n return \"file\";\n }\n\n return \"generic\";\n }\n\n return primitiveOf(value);\n }\n\n if (value === Array) {\n return \"array\";\n }\n\n if (isArray(value)) {\n return value.map(getJsonType) as any;\n }\n\n if (value === Set) {\n return \"array\";\n }\n\n if (isDate(value) || isBuffer(value)) {\n return \"string\";\n }\n\n return \"object\";\n}\n"]}
@@ -1,9 +1,10 @@
1
- import { getOperationsStores } from "./getOperationsStores";
2
- import { JsonOperationRoute } from "../domain/JsonOperationRoute";
3
- import { getJsonEntityStore } from "./getJsonEntityStore";
1
+ import { getOperationsStores } from "./getOperationsStores.js";
2
+ import { JsonOperationRoute } from "../domain/JsonOperationRoute.js";
3
+ import { getJsonEntityStore } from "./getJsonEntityStore.js";
4
+ import { concatPath } from "./concatPath.js";
4
5
  export function getOperationsRoutes(token, options = {}) {
5
6
  const store = token.isStore ? token : getJsonEntityStore(token);
6
- const basePath = ((options.basePath || "") + (store.path || "")).replace(/\/\//gi, "/");
7
+ const basePath = concatPath(options.basePath, store.path);
7
8
  let operationsRoutes = [];
8
9
  if (options.withChildren) {
9
10
  const children = store.get("childrenControllers", []);
@@ -1 +1 @@
1
- {"version":3,"file":"getOperationsRoutes.js","sourceRoot":"","sources":["../../../src/utils/getOperationsRoutes.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,kBAAkB,EAAC,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAOxD,MAAM,UAAU,mBAAmB,CACjC,KAAsB,EACtB,UAAsC,EAAE;IAExC,MAAM,KAAK,GAAoB,KAAK,CAAC,OAAO,CAAC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ute} from \"../domain/JsonOperationRoute\";\nimport {JsonEntityStore} from \"../domain/JsonEntityStore\";\nimport {getJsonEntityStore} from \"./getJsonEntityStore\";\n\nexport interface GetOperationsRoutesOptions {\n withChildren?: boolean;\n basePath?: string;\n}\n\nexport function getOperationsRoutes<Entity extends JsonEntityStore = JsonEntityStore>(\n token: Type<any> | any,\n options: GetOperationsRoutesOptions = {}\n): JsonOperationRoute<Entity>[] {\n const store: JsonEntityStore = token.isStore ? token : getJsonEntityStore(token);\n const basePath = ((options.basePath || \"\") + (store.path || \"\")).replace(/\\/\\//gi, \"/\");\n let operationsRoutes: JsonOperationRoute<Entity>[] = [];\n\n if (options.withChildren) {\n const children = store.get<Type[]>(\"childrenControllers\", []);\n\n operationsRoutes = children.reduce((operationsRoutes, token) => {\n return operationsRoutes.concat(\n getOperationsRoutes(token, {\n ...options,\n basePath\n })\n );\n }, operationsRoutes);\n }\n\n return [...getOperationsStores(token).values()].reduce((routes, endpoint) => {\n const {operation} = endpoint;\n\n if (operation) {\n operation.operationPaths.forEach((operationPath) => {\n routes.push(\n new JsonOperationRoute<Entity>({\n basePath,\n token,\n endpoint,\n operationPath\n })\n );\n });\n }\n\n return routes;\n }, operationsRoutes);\n}\n"]}
1
+ {"version":3,"file":"getOperationsRoutes.js","sourceRoot":"","sources":["../../../src/utils/getOperationsRoutes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,kBAAkB,EAAC,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAOxC,MAAM,UAAU,mBAAmB,CACjC,KAAsB,EACtB,UAAsC,EAAE;IAExC,MAAM,KAAK,GAAoB,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACjF,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1D,IAAI,gBAAgB,GAAiC,EAAE,CAAC;IAExD,IAAI,OAAO,CAAC,YAAY,EAAE;QACxB,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAS,qBAAqB,EAAE,EAAE,CAAC,CAAC;QAE9D,gBAAgB,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,gBAAgB,EAAE,KAAK,EAAE,EAAE;YAC7D,OAAO,gBAAgB,CAAC,MAAM,CAC5B,mBAAmB,CAAC,KAAK,EAAE;gBACzB,GAAG,OAAO;gBACV,QAAQ;aACT,CAAC,CACH,CAAC;QACJ,CAAC,EAAE,gBAAgB,CAAC,CAAC;KACtB;IAED,OAAO,CAAC,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE;QAC1E,MAAM,EAAC,SAAS,EAAC,GAAG,QAAQ,CAAC;QAE7B,IAAI,SAAS,EAAE;YACb,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE;gBACjD,MAAM,CAAC,IAAI,CACT,IAAI,kBAAkB,CAAS;oBAC7B,QAAQ;oBACR,KAAK;oBACL,QAAQ;oBACR,aAAa;iBACd,CAAC,CACH,CAAC;YACJ,CAAC,CAAC,CAAC;SACJ;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,gBAAgB,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {JsonMethodStore} from \"../domain/JsonMethodStore\";\nimport {getOperationsStores} from \"./getOperationsStores\";\nimport {JsonOperationRoute} from \"../domain/JsonOperationRoute\";\nimport {JsonEntityStore} from \"../domain/JsonEntityStore\";\nimport {getJsonEntityStore} from \"./getJsonEntityStore\";\nimport {concatPath} from \"./concatPath\";\n\nexport interface GetOperationsRoutesOptions {\n withChildren?: boolean;\n basePath?: string;\n}\n\nexport function getOperationsRoutes<Entity extends JsonMethodStore = JsonMethodStore>(\n token: Type<any> | any,\n options: GetOperationsRoutesOptions = {}\n): JsonOperationRoute<Entity>[] {\n const store: JsonEntityStore = token.isStore ? token : getJsonEntityStore(token);\n const basePath = concatPath(options.basePath, store.path);\n let operationsRoutes: JsonOperationRoute<Entity>[] = [];\n\n if (options.withChildren) {\n const children = store.get<Type[]>(\"childrenControllers\", []);\n\n operationsRoutes = children.reduce((operationsRoutes, token) => {\n return operationsRoutes.concat(\n getOperationsRoutes(token, {\n ...options,\n basePath\n })\n );\n }, operationsRoutes);\n }\n\n return [...getOperationsStores(token).values()].reduce((routes, endpoint) => {\n const {operation} = endpoint;\n\n if (operation) {\n operation.operationPaths.forEach((operationPath) => {\n routes.push(\n new JsonOperationRoute<Entity>({\n basePath,\n token,\n endpoint,\n operationPath\n })\n );\n });\n }\n\n return routes;\n }, operationsRoutes);\n}\n"]}
@@ -1,7 +1,7 @@
1
- import { JsonMethodStore } from "../domain/JsonMethodStore";
2
- import { JsonOperationPathsMap } from "../domain/JsonOperationPathsMap";
3
- import { getInheritedStores } from "./getInheritedStores";
4
- import { getJsonEntityStore } from "./getJsonEntityStore";
1
+ import { JsonMethodStore } from "../domain/JsonMethodStore.js";
2
+ import { JsonOperationPathsMap } from "../domain/JsonOperationPathsMap.js";
3
+ import { getInheritedStores } from "./getInheritedStores.js";
4
+ import { getJsonEntityStore } from "./getJsonEntityStore.js";
5
5
  /**
6
6
  * @ignore
7
7
  */
@@ -1,6 +1,6 @@
1
- import { alterIgnore } from "../hooks/alterIgnore";
2
- import { getInheritedStores } from "./getInheritedStores";
3
- import { getJsonEntityStore } from "./getJsonEntityStore";
1
+ import { alterIgnore } from "../hooks/alterIgnore.js";
2
+ import { getInheritedStores } from "./getInheritedStores.js";
3
+ import { getJsonEntityStore } from "./getJsonEntityStore.js";
4
4
  /**
5
5
  * Return the list of properties including properties from inherited classes
6
6
  * @param target
@@ -1,5 +1,5 @@
1
1
  import { uniq } from "@tsed/core";
2
- import { alterRequiredGroups } from "../hooks/alterRequiredGroups";
2
+ import { alterRequiredGroups } from "../hooks/alterRequiredGroups.js";
3
3
  function applyStringRule(obj, propSchema) {
4
4
  if (!(propSchema === null || propSchema === void 0 ? void 0 : propSchema.$allow.includes(""))) {
5
5
  if ([].concat(propSchema === null || propSchema === void 0 ? void 0 : propSchema.get("type")).includes("string")) {
@@ -1,10 +1,11 @@
1
- import { cleanObject, uniqBy } from "@tsed/core";
2
- import { SpecTypes } from "../domain/SpecTypes";
3
- import { buildPath } from "./buildPath";
4
- import { getJsonEntityStore } from "./getJsonEntityStore";
5
- import { getOperationsStores } from "./getOperationsStores";
6
- import { mergeOperation } from "./mergeOperation";
7
- import { operationIdFormatter } from "./operationIdFormatter";
1
+ import { cleanObject, isArray, uniqBy } from "@tsed/core";
2
+ import { SpecTypes } from "../domain/SpecTypes.js";
3
+ import { buildPath } from "./buildPath.js";
4
+ import { getJsonEntityStore } from "./getJsonEntityStore.js";
5
+ import { getOperationsStores } from "./getOperationsStores.js";
6
+ import { mergeOperation } from "./mergeOperation.js";
7
+ import { operationIdFormatter } from "./operationIdFormatter.js";
8
+ import { mergeSpec } from "./mergeSpec.js";
8
9
  /**
9
10
  * @ignore
10
11
  */
@@ -23,61 +24,75 @@ function get(model, options, cb) {
23
24
  }
24
25
  return cache.get(key);
25
26
  }
27
+ function generate(model, options) {
28
+ const store = getJsonEntityStore(model);
29
+ const { schemas = {}, paths = {}, rootPath = "/", tags = [] } = options;
30
+ const specType = SpecTypes.OPENAPI;
31
+ const ctrlPath = store.path;
32
+ const defaultTags = cleanObject({
33
+ name: store.schema.getName(),
34
+ description: store.schema.get("description")
35
+ });
36
+ const specJson = { paths };
37
+ getOperationsStores(model).forEach((operationStore) => {
38
+ if (operationStore.store.get("hidden")) {
39
+ return;
40
+ }
41
+ const operation = operationStore.operation.toJSON({ ...options, specType, schemas });
42
+ operationStore.operation.operationPaths.forEach(({ path, method }) => {
43
+ if (method) {
44
+ mergeOperation(specJson, operation, {
45
+ rootPath: buildPath(rootPath + ctrlPath),
46
+ path,
47
+ method,
48
+ defaultTags,
49
+ tags,
50
+ specType,
51
+ operationId: (path) => options.operationIdFormatter(operationStore.parent.schema.get("name") || operationStore.parent.targetName, operationStore.propertyName, path)
52
+ });
53
+ }
54
+ });
55
+ });
56
+ specJson.tags = uniqBy(tags, "name");
57
+ if (Object.keys(schemas).length) {
58
+ specJson.components = {
59
+ schemas
60
+ };
61
+ }
62
+ return specJson;
63
+ }
26
64
  /**
27
65
  * Return the swagger or open spec for the given class.
28
66
  * @param model
29
67
  * @param options
30
68
  */
31
69
  export function getSpec(model, options = {}) {
32
- if (!options.specType) {
33
- options.specType = SpecTypes.OPENAPI;
34
- }
35
70
  options = {
36
71
  ...options,
37
72
  operationIdFormatter: options.operationIdFormatter || operationIdFormatter(options.operationIdPattern),
38
- root: false,
39
- specType: options.specType
73
+ root: false
40
74
  };
41
- return get(model, options, () => {
42
- const store = getJsonEntityStore(model);
43
- const { specType = SpecTypes.OPENAPI, schemas = {}, paths = {}, rootPath = "/", tags = [] } = options;
44
- const ctrlPath = store.path;
45
- const defaultTags = cleanObject({
46
- name: store.schema.getName(),
47
- description: store.schema.get("description")
48
- });
49
- const specJson = { paths };
50
- getOperationsStores(model).forEach((operationStore) => {
51
- if (operationStore.store.get("hidden")) {
52
- return;
75
+ if (isArray(model)) {
76
+ let finalSpec = {};
77
+ options = {
78
+ ...options,
79
+ specType: SpecTypes.OPENAPI,
80
+ paths: {},
81
+ tags: [],
82
+ schemas: {},
83
+ append(spec) {
84
+ finalSpec = mergeSpec(finalSpec, spec);
53
85
  }
54
- const operation = operationStore.operation.toJSON({ ...options, specType, schemas });
55
- operationStore.operation.operationPaths.forEach(({ path, method }) => {
56
- if (method) {
57
- mergeOperation(specJson, operation, {
58
- rootPath: buildPath(rootPath + ctrlPath),
59
- path,
60
- method,
61
- defaultTags,
62
- tags,
63
- specType,
64
- operationId: (path) => options.operationIdFormatter(operationStore.parent.schema.get("name") || operationStore.parent.targetName, operationStore.propertyName, path)
65
- });
66
- }
86
+ };
87
+ model.forEach(({ token, ...opts }) => {
88
+ const spec = getSpec(token, {
89
+ ...options,
90
+ ...opts
67
91
  });
92
+ options.append(spec);
68
93
  });
69
- specJson.tags = uniqBy(tags, "name");
70
- if (Object.keys(schemas).length) {
71
- if (specType === SpecTypes.OPENAPI) {
72
- specJson.components = {
73
- schemas
74
- };
75
- }
76
- else {
77
- specJson.definitions = schemas;
78
- }
79
- }
80
- return specJson;
81
- });
94
+ return finalSpec;
95
+ }
96
+ return get(model, options, () => generate(model, options));
82
97
  }
83
98
  //# sourceMappingURL=getSpec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getSpec.js","sourceRoot":"","sources":["../../../src/utils/getSpec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAQ,MAAM,EAAC,MAAM,YAAY,CAAC;AAErD,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAsB5D;;GAEG;AACH,MAAM,MAAM,GAAqC,IAAI,GAAG,EAAE,CAAC;AAE3D;;GAEG;AACH,SAAS,GAAG,CAAC,KAAgB,EAAE,OAAY,EAAE,EAAO;IAClD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QACtB,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;KAC9B;IAED,MAAM,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AClB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {cleanObject, Type, uniqBy} from \"@tsed/core\";\nimport {OpenSpec3} from \"@tsed/openspec\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {JsonSchemaOptions} from \"../interfaces\";\nimport {buildPath} from \"./buildPath\";\nimport {getJsonEntityStore} from \"./getJsonEntityStore\";\nimport {getOperationsStores} from \"./getOperationsStores\";\nimport {mergeOperation} from \"./mergeOperation\";\nimport {operationIdFormatter} from \"./operationIdFormatter\";\n\nexport interface SpecSerializerOptions extends JsonSchemaOptions {\n specType?: SpecTypes.OPENAPI;\n /**\n * Paths\n */\n paths?: any;\n /**\n * Root path. This paths will be added to all generated paths Object.\n */\n rootPath?: string;\n /**\n * A function to generate the operationId.\n */\n operationIdFormatter?: (name: string, propertyKey: string, path: string) => string;\n /**\n * A pattern to generate the operationId.\n */\n operationIdPattern?: string;\n}\n\n/**\n * @ignore\n */\nconst caches: Map<Type<any>, Map<string, any>> = new Map();\n\n/**\n * @ignore\n */\nfunction get(model: Type<any>, options: any, cb: any) {\n if (!caches.has(model)) {\n caches.set(model, new Map());\n }\n\n const cache = caches.get(model)!;\n const key = JSON.stringify(options);\n\n if (!cache.has(key)) {\n cache.set(key, cb());\n }\n\n return cache.get(key);\n}\n\n/**\n * Return the swagger or open spec for the given class.\n * @param model\n * @param options\n */\nexport function getSpec(model: Type<any>, options: SpecSerializerOptions = {}): Partial<OpenSpec3> {\n if (!options.specType) {\n options.specType = SpecTypes.OPENAPI;\n }\n\n options = {\n ...options,\n operationIdFormatter: options.operationIdFormatter || operationIdFormatter(options.operationIdPattern),\n root: false,\n specType: options.specType\n };\n\n return get(model, options, () => {\n const store = getJsonEntityStore(model);\n const {specType = SpecTypes.OPENAPI, schemas = {}, paths = {}, rootPath = \"/\", tags = []} = options;\n const ctrlPath = store.path;\n const defaultTags = cleanObject({\n name: store.schema.getName(),\n description: store.schema.get(\"description\")\n });\n\n const specJson: any = {paths};\n\n getOperationsStores(model).forEach((operationStore) => {\n if (operationStore.store.get(\"hidden\")) {\n return;\n }\n\n const operation = operationStore.operation!.toJSON({...options, specType, schemas});\n\n operationStore.operation!.operationPaths.forEach(({path, method}: {path: string; method: string}) => {\n if (method) {\n mergeOperation(specJson, operation, {\n rootPath: buildPath(rootPath + ctrlPath),\n path,\n method,\n defaultTags,\n tags,\n specType,\n operationId: (path: string) =>\n options.operationIdFormatter!(\n operationStore.parent.schema.get(\"name\") || operationStore.parent.targetName,\n operationStore.propertyName,\n path\n )\n });\n }\n });\n });\n\n specJson.tags = uniqBy(tags, \"name\");\n\n if (Object.keys(schemas).length) {\n if (specType === SpecTypes.OPENAPI) {\n specJson.components = {\n schemas\n };\n } else {\n specJson.definitions = schemas;\n }\n }\n\n return specJson;\n });\n}\n"]}
1
+ {"version":3,"file":"getSpec.js","sourceRoot":"","sources":["../../../src/utils/getSpec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,OAAO,EAAQ,MAAM,EAAC,MAAM,YAAY,CAAC;AAE9D,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAuBtC;;GAEG;AACH,MAAM,MAAM,GAAqC,IAAI,GAAG,EAAE,CAAC;AAE3D;;GAEG;AACH,SAAS,GAAG,CAAC,KAAgB,EAAE,OAAY,EAAE,EAAO;IAClD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QACtB,MAAM,CAAC,GAAG,CAAC,KA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E;YACR,OAAO,EAAE,EAAE;YACX,MAAM,CAAC,IAAS;gBACd,SAAS,GAAG,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YACzC,CAAC;SACF,CAAC;QAEF,KAAK,CAAC,OAAO,CAAC,CAAC,EAAC,KAAK,EAAE,GAAG,IAAI,EAAC,EAAE,EAAE;YACjC,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE;gBAC1B,GAAG,OAAO;gBACV,GAAG,IAAI;aACR,CAAC,CAAC;YAEH,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAC7D,CAAC","sourcesContent":["import {cleanObject, isArray, Type, uniqBy} from \"@tsed/core\";\nimport {OpenSpec3} from \"@tsed/openspec\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\nimport {buildPath} from \"./buildPath\";\nimport {getJsonEntityStore} from \"./getJsonEntityStore\";\nimport {getOperationsStores} from \"./getOperationsStores\";\nimport {mergeOperation} from \"./mergeOperation\";\nimport {operationIdFormatter} from \"./operationIdFormatter\";\nimport {mergeSpec} from \"./mergeSpec\";\n\nexport type JsonTokenOptions = ({token: Type<any>} & Partial<SpecSerializerOptions>)[];\n\nexport interface SpecSerializerOptions extends JsonSchemaOptions {\n /**\n * Paths\n */\n paths?: any;\n /**\n * Root path. This paths will be added to all generated paths Object.\n */\n rootPath?: string;\n /**\n * A function to generate the operationId.\n */\n operationIdFormatter?: (name: string, propertyKey: string, path: string) => string;\n /**\n * A pattern to generate the operationId.\n */\n operationIdPattern?: string;\n}\n\n/**\n * @ignore\n */\nconst caches: Map<Type<any>, Map<string, any>> = new Map();\n\n/**\n * @ignore\n */\nfunction get(model: Type<any>, options: any, cb: any) {\n if (!caches.has(model)) {\n caches.set(model, new Map());\n }\n\n const cache = caches.get(model)!;\n const key = JSON.stringify(options);\n\n if (!cache.has(key)) {\n cache.set(key, cb());\n }\n\n return cache.get(key);\n}\n\nfunction generate(model: Type<any>, options: SpecSerializerOptions) {\n const store = getJsonEntityStore(model);\n const {schemas = {}, paths = {}, rootPath = \"/\", tags = []} = options;\n const specType = SpecTypes.OPENAPI;\n const ctrlPath = store.path;\n const defaultTags = cleanObject({\n name: store.schema.getName(),\n description: store.schema.get(\"description\")\n });\n\n const specJson: any = {paths};\n\n getOperationsStores(model).forEach((operationStore) => {\n if (operationStore.store.get(\"hidden\")) {\n return;\n }\n\n const operation = operationStore.operation!.toJSON({...options, specType, schemas});\n\n operationStore.operation!.operationPaths.forEach(({path, method}: {path: string; method: string}) => {\n if (method) {\n mergeOperation(specJson, operation, {\n rootPath: buildPath(rootPath + ctrlPath),\n path,\n method,\n defaultTags,\n tags,\n specType,\n operationId: (path: string) =>\n options.operationIdFormatter!(\n operationStore.parent.schema.get(\"name\") || operationStore.parent.targetName,\n operationStore.propertyName,\n path\n )\n });\n }\n });\n });\n\n specJson.tags = uniqBy(tags, \"name\");\n\n if (Object.keys(schemas).length) {\n specJson.components = {\n schemas\n };\n }\n\n return specJson;\n}\n\n/**\n * Return the swagger or open spec for the given class.\n * @param model\n * @param options\n */\nexport function getSpec(model: Type<any> | JsonTokenOptions, options: SpecSerializerOptions = {}): Partial<OpenSpec3> {\n options = {\n ...options,\n operationIdFormatter: options.operationIdFormatter || operationIdFormatter(options.operationIdPattern),\n root: false\n };\n\n if (isArray(model)) {\n let finalSpec: any = {};\n\n options = {\n ...options,\n specType: SpecTypes.OPENAPI,\n paths: {},\n tags: [],\n schemas: {},\n append(spec: any) {\n finalSpec = mergeSpec(finalSpec, spec);\n }\n };\n\n model.forEach(({token, ...opts}) => {\n const spec = getSpec(token, {\n ...options,\n ...opts\n });\n\n options.append(spec);\n });\n\n return finalSpec;\n }\n\n return get(model, options, () => generate(model, options));\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import { SpecTypes } from "../domain/SpecTypes.js";
2
+ /**
3
+ * @ignore
4
+ * @param version
5
+ */
6
+ export function getSpecType(version) {
7
+ return version.startsWith("3.") ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;
8
+ }
9
+ /**
10
+ * @ignore
11
+ * @param spec
12
+ */
13
+ export function getSpecTypeFromSpec(spec) {
14
+ return "openapi" in spec ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;
15
+ }
16
+ //# sourceMappingURL=getSpecType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSpecType.js","sourceRoot":"","sources":["../../../src/utils/getSpecType.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC;AAC1E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAoC;IACtE,OAAO,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC;AACnE,CAAC","sourcesContent":["import {OpenSpec2, OpenSpec3} from \"@tsed/openspec\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\n\n/**\n * @ignore\n * @param version\n */\nexport function getSpecType(version: string) {\n return version.startsWith(\"3.\") ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;\n}\n\n/**\n * @ignore\n * @param spec\n */\nexport function getSpecTypeFromSpec(spec: Partial<OpenSpec2 | OpenSpec3>) {\n return \"openapi\" in spec ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;\n}\n"]}
@@ -1,10 +1,10 @@
1
1
  import { uniq } from "@tsed/core";
2
- import { SpecTypes } from "../domain/SpecTypes";
2
+ import { SpecTypes } from "../domain/SpecTypes.js";
3
3
  function hasNullable(obj) {
4
4
  return obj.oneOf.find((o) => o.type === "null");
5
5
  }
6
6
  export function mapNullableType(obj, schema, options) {
7
- if (!schema.isNullable) {
7
+ if (!(schema === null || schema === void 0 ? void 0 : schema.isNullable)) {
8
8
  return obj;
9
9
  }
10
10
  let types = [].concat(obj.type).filter(Boolean);
@@ -1 +1 @@
1
- {"version":3,"file":"mapNullableType.js","sourceRoot":"","sources":["../../../src/utils/mapNullableType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,YAAY,CAAC;AAEhC,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAG9C,SAAS,WAAW,CAAC,GAAQ;IAC3B,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAQ,EAAE,MAAkB,EAAE,OAA0B;IACtF,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;QACtB,OAAO,GAAG,CAAC;KACZ;IACD,IAAI,KAAK,GAAa,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAE1D,QAAQ,OAAO,CAAC,QAAQ,EAAE;QACxB,QAAQ;QACR,KAAK,SAAS,CAAC,IAAI;YACjB,IAAI,GAAG,CAAC,KAAK,EAAE;gBACb,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE;oBACrB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC;wBAChB,IAAI,EAAE,MAAM;qBACb,CAAC,CAAC;iBACJ;aACF;iBAAM;gBACL,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;aACrC;YACD,MAAM;QAER,KAAK,SAAS,CAAC,OAAO;YACpB,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC;YAEpB,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE;gBACd,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;oBACpB,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAC,IAAI,EAAC,CAAC,CAAC,CAAC;oBAC1C,OAAO,GAAG,CAAC,IAAI,CAAC;iBACjB;qBAAM;oBACL,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;iBACrB;aACF;YACD,MAAM;KACT;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import {uniq} from \"@tsed/core\";\nimport type {JsonSchema} from \"../domain/JsonSchema\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport type {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\n\nfunction hasNullable(obj: any) {\n return obj.oneOf.find((o: any) => o.type === \"null\");\n}\n\nexport function mapNullableType(obj: any, schema: JsonSchema, options: JsonSchemaOptions) {\n if (!schema.isNullable) {\n return obj;\n }\n let types: string[] = [].concat(obj.type).filter(Boolean);\n\n switch (options.specType) {\n default:\n case SpecTypes.JSON:\n if (obj.oneOf) {\n if (!hasNullable(obj)) {\n obj.oneOf.unshift({\n type: \"null\"\n });\n }\n } else {\n obj.type = uniq([\"null\", ...types]);\n }\n break;\n\n case SpecTypes.OPENAPI:\n obj.nullable = true;\n\n if (!obj.oneOf) {\n if (types.length > 1) {\n obj.oneOf = types.map((type) => ({type}));\n delete obj.type;\n } else {\n obj.type = types[0];\n }\n }\n break;\n }\n\n return obj;\n}\n"]}
1
+ {"version":3,"file":"mapNullableType.js","sourceRoot":"","sources":["../../../src/utils/mapNullableType.ts"],"names":[],"mappings":"AAAA,OAAO,EA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I,CAAC;iBACjB;qBAAM;oBACL,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;iBACrB;aACF;YACD,MAAM;KACT;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import {uniq} from \"@tsed/core\";\nimport type {JsonSchema} from \"../domain/JsonSchema\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport type {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\n\nfunction hasNullable(obj: any) {\n return obj.oneOf.find((o: any) => o.type === \"null\");\n}\n\nexport function mapNullableType(obj: any, schema: JsonSchema | null, options: JsonSchemaOptions) {\n if (!schema?.isNullable) {\n return obj;\n }\n let types: string[] = [].concat(obj.type).filter(Boolean);\n\n switch (options.specType) {\n default:\n case SpecTypes.JSON:\n if (obj.oneOf) {\n if (!hasNullable(obj)) {\n obj.oneOf.unshift({\n type: \"null\"\n });\n }\n } else {\n obj.type = uniq([\"null\", ...types]);\n }\n break;\n\n case SpecTypes.OPENAPI:\n obj.nullable = true;\n\n if (!obj.oneOf) {\n if (types.length > 1) {\n obj.oneOf = types.map((type) => ({type}));\n delete obj.type;\n } else {\n obj.type = types[0];\n }\n }\n break;\n }\n\n return obj;\n}\n"]}
@@ -0,0 +1,37 @@
1
+ import { getValue, setValue } from "@tsed/core";
2
+ import { getSpecType } from "./getSpecType.js";
3
+ import { mapOpenSpec2 } from "./mapOpenSpec2.js";
4
+ import { SpecTypes } from "../domain/SpecTypes.js";
5
+ import { mapOpenSpec3 } from "./mapOpenSpec3.js";
6
+ import { mergeSpec } from "./mergeSpec.js";
7
+ /**
8
+ * @ignore
9
+ * @param spec
10
+ * @param fileSpec
11
+ * @param version
12
+ * @param acceptMimes
13
+ * @param specVersion
14
+ */
15
+ export function mapOpenSpec(spec, { fileSpec, acceptMimes, specVersion, version }) {
16
+ specVersion = specVersion || getValue(spec, "openapi", getValue(spec, "swagger", "2.0"));
17
+ const options = {
18
+ specVersion,
19
+ acceptMimes
20
+ };
21
+ switch (getSpecType(specVersion)) {
22
+ case SpecTypes.OPENAPI:
23
+ spec = mapOpenSpec3(spec, options);
24
+ fileSpec = fileSpec ? mapOpenSpec3(fileSpec, options) : fileSpec;
25
+ break;
26
+ default:
27
+ case SpecTypes.SWAGGER:
28
+ spec = mapOpenSpec2(spec, options);
29
+ fileSpec = fileSpec ? mapOpenSpec2(fileSpec, options) : fileSpec;
30
+ break;
31
+ }
32
+ spec = mergeSpec(spec, fileSpec);
33
+ setValue(spec, "info.title", getValue(spec, "info.title", "Api documentation"));
34
+ setValue(spec, "info.version", getValue(spec, "info.version", version));
35
+ return spec;
36
+ }
37
+ //# sourceMappingURL=mapOpenSpec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapOpenSpec.js","sourceRoot":"","sources":["../../../src/utils/mapOpenSpec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,IAAS,EAAE,EAAC,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAM;IACvF,WAAW,GAAG,WAAW,IAAI,QAAQ,CAAmB,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IAE3G,MAAM,OAAO,GAAG;QACd,WAAW;QACX,WAAW;KACZ,CAAC;IAEF,QAAQ,WAAW,CAAC,WAAW,CAAC,EAAE;QAChC,KAAK,SAAS,CAAC,OAAO;YACpB,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACnC,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;YACjE,MAAM;QACR,QAAQ;QACR,KAAK,SAAS,CAAC,OAAO;YACpB,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACnC,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;YACjE,MAAM;KACT;IAED,IAAI,GAAG,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAEjC,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAChF,QAAQ,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;IAExE,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import {getValue, setValue} from \"@tsed/core\";\nimport {OpenSpec2, OpenSpec3, OpenSpecVersions} from \"@tsed/openspec\";\nimport {getSpecType} from \"./getSpecType\";\nimport {mapOpenSpec2} from \"./mapOpenSpec2\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {mapOpenSpec3} from \"./mapOpenSpec3\";\nimport {mergeSpec} from \"./mergeSpec\";\n\n/**\n * @ignore\n * @param spec\n * @param fileSpec\n * @param version\n * @param acceptMimes\n * @param specVersion\n */\nexport function mapOpenSpec(spec: any, {fileSpec, acceptMimes, specVersion, version}: any): Partial<OpenSpec2 | OpenSpec3> {\n specVersion = specVersion || getValue<OpenSpecVersions>(spec, \"openapi\", getValue(spec, \"swagger\", \"2.0\"));\n\n const options = {\n specVersion,\n acceptMimes\n };\n\n switch (getSpecType(specVersion)) {\n case SpecTypes.OPENAPI:\n spec = mapOpenSpec3(spec, options);\n fileSpec = fileSpec ? mapOpenSpec3(fileSpec, options) : fileSpec;\n break;\n default:\n case SpecTypes.SWAGGER:\n spec = mapOpenSpec2(spec, options);\n fileSpec = fileSpec ? mapOpenSpec2(fileSpec, options) : fileSpec;\n break;\n }\n\n spec = mergeSpec(spec, fileSpec);\n\n setValue(spec, \"info.title\", getValue(spec, \"info.title\", \"Api documentation\"));\n setValue(spec, \"info.version\", getValue(spec, \"info.version\", version));\n\n return spec;\n}\n"]}