@asyncapi/react-component 1.0.0-next.5 → 1.0.0-next.51

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 (288) hide show
  1. package/README.md +75 -4
  2. package/browser/index.js +8 -14
  3. package/browser/index.js.LICENSE.txt +88 -0
  4. package/browser/standalone/index.js +8 -0
  5. package/browser/standalone/index.js.LICENSE.txt +112 -0
  6. package/browser/standalone/without-parser.js +8 -0
  7. package/browser/standalone/without-parser.js.LICENSE.txt +110 -0
  8. package/browser/without-parser.js +8 -12
  9. package/browser/without-parser.js.LICENSE.txt +86 -0
  10. package/lib/cjs/components/Bindings.js +14 -5
  11. package/lib/cjs/components/Bindings.js.map +1 -1
  12. package/lib/cjs/components/CollapseButton.js +11 -7
  13. package/lib/cjs/components/CollapseButton.js.map +1 -1
  14. package/lib/cjs/components/Extensions.js +4 -3
  15. package/lib/cjs/components/Extensions.js.map +1 -1
  16. package/lib/cjs/components/Href.js +2 -1
  17. package/lib/cjs/components/Href.js.map +1 -1
  18. package/lib/cjs/components/JSONSnippet.js +17 -0
  19. package/lib/cjs/components/JSONSnippet.js.map +1 -0
  20. package/lib/cjs/components/Markdown.js +4 -4
  21. package/lib/cjs/components/Markdown.js.map +1 -1
  22. package/lib/cjs/components/Schema.js +77 -60
  23. package/lib/cjs/components/Schema.js.map +1 -1
  24. package/lib/cjs/components/Tag.js +3 -2
  25. package/lib/cjs/components/Tag.js.map +1 -1
  26. package/lib/cjs/components/Tags.js +3 -2
  27. package/lib/cjs/components/Tags.js.map +1 -1
  28. package/lib/cjs/components/index.js +6 -2
  29. package/lib/cjs/components/index.js.map +1 -1
  30. package/lib/cjs/config/config.js.map +1 -1
  31. package/lib/cjs/config/default.js +9 -1
  32. package/lib/cjs/config/default.js.map +1 -1
  33. package/lib/cjs/config/index.js +5 -1
  34. package/lib/cjs/config/index.js.map +1 -1
  35. package/lib/cjs/constants.js +5 -48
  36. package/lib/cjs/constants.js.map +1 -1
  37. package/lib/cjs/containers/AsyncApi/AsyncApi.js +29 -13
  38. package/lib/cjs/containers/AsyncApi/AsyncApi.js.map +1 -1
  39. package/lib/cjs/containers/AsyncApi/Layout.js +33 -21
  40. package/lib/cjs/containers/AsyncApi/Layout.js.map +1 -1
  41. package/lib/cjs/containers/AsyncApi/Standalone.js +9 -3
  42. package/lib/cjs/containers/AsyncApi/Standalone.js.map +1 -1
  43. package/lib/cjs/containers/Error/Error.js +4 -3
  44. package/lib/cjs/containers/Error/Error.js.map +1 -1
  45. package/lib/cjs/containers/Info/Info.js +11 -10
  46. package/lib/cjs/containers/Info/Info.js.map +1 -1
  47. package/lib/cjs/containers/Messages/Message.js +23 -10
  48. package/lib/cjs/containers/Messages/Message.js.map +1 -1
  49. package/lib/cjs/containers/Messages/MessageExample.js +26 -14
  50. package/lib/cjs/containers/Messages/MessageExample.js.map +1 -1
  51. package/lib/cjs/containers/Messages/Messages.js +15 -7
  52. package/lib/cjs/containers/Messages/Messages.js.map +1 -1
  53. package/lib/cjs/containers/Operations/Operation.js +88 -38
  54. package/lib/cjs/containers/Operations/Operation.js.map +1 -1
  55. package/lib/cjs/containers/Operations/Operations.js +20 -13
  56. package/lib/cjs/containers/Operations/Operations.js.map +1 -1
  57. package/lib/cjs/containers/Schemas/Schema.js +21 -0
  58. package/lib/cjs/containers/Schemas/Schema.js.map +1 -0
  59. package/lib/cjs/containers/Schemas/Schemas.js +32 -0
  60. package/lib/cjs/containers/Schemas/Schemas.js.map +1 -0
  61. package/lib/cjs/containers/Servers/Security.js +150 -0
  62. package/lib/cjs/containers/Servers/Security.js.map +1 -0
  63. package/lib/cjs/containers/Servers/Server.js +15 -8
  64. package/lib/cjs/containers/Servers/Server.js.map +1 -1
  65. package/lib/cjs/containers/Servers/Servers.js +11 -6
  66. package/lib/cjs/containers/Servers/Servers.js.map +1 -1
  67. package/lib/cjs/containers/Sidebar/Sidebar.js +213 -140
  68. package/lib/cjs/containers/Sidebar/Sidebar.js.map +1 -1
  69. package/lib/cjs/contexts/index.js +6 -1
  70. package/lib/cjs/contexts/index.js.map +1 -1
  71. package/lib/cjs/contexts/useConfig.js +10 -0
  72. package/lib/cjs/contexts/useConfig.js.map +1 -0
  73. package/lib/cjs/contexts/useSpec.js +7 -3
  74. package/lib/cjs/contexts/useSpec.js.map +1 -1
  75. package/lib/cjs/helpers/common.js +17 -0
  76. package/lib/cjs/helpers/common.js.map +1 -0
  77. package/lib/cjs/helpers/index.js +7 -4
  78. package/lib/cjs/helpers/index.js.map +1 -1
  79. package/lib/cjs/helpers/marked.js +34 -0
  80. package/lib/cjs/helpers/marked.js.map +1 -0
  81. package/lib/cjs/helpers/message.js +39 -9
  82. package/lib/cjs/helpers/message.js.map +1 -1
  83. package/lib/cjs/helpers/parser.js +15 -16
  84. package/lib/cjs/helpers/parser.js.map +1 -1
  85. package/lib/cjs/helpers/schema.js +186 -149
  86. package/lib/cjs/helpers/schema.js.map +1 -1
  87. package/lib/cjs/helpers/server.js +49 -0
  88. package/lib/cjs/helpers/server.js.map +1 -1
  89. package/lib/cjs/helpers/specification.js +36 -21
  90. package/lib/cjs/helpers/specification.js.map +1 -1
  91. package/lib/cjs/index.js +3 -1
  92. package/lib/cjs/index.js.map +1 -1
  93. package/lib/cjs/types.js +4 -51
  94. package/lib/cjs/types.js.map +1 -1
  95. package/lib/cjs/without-parser.js +3 -0
  96. package/lib/cjs/without-parser.js.map +1 -1
  97. package/lib/esm/components/Bindings.js +12 -4
  98. package/lib/esm/components/Bindings.js.map +1 -1
  99. package/lib/esm/components/CollapseButton.js +9 -6
  100. package/lib/esm/components/CollapseButton.js.map +1 -1
  101. package/lib/esm/components/Extensions.js +2 -2
  102. package/lib/esm/components/Extensions.js.map +1 -1
  103. package/lib/esm/components/Href.js.map +1 -1
  104. package/lib/esm/components/JSONSnippet.js +10 -0
  105. package/lib/esm/components/JSONSnippet.js.map +1 -0
  106. package/lib/esm/components/Markdown.js +2 -3
  107. package/lib/esm/components/Markdown.js.map +1 -1
  108. package/lib/esm/components/Schema.js +71 -59
  109. package/lib/esm/components/Schema.js.map +1 -1
  110. package/lib/esm/components/Tag.js +1 -1
  111. package/lib/esm/components/Tag.js.map +1 -1
  112. package/lib/esm/components/Tags.js +1 -1
  113. package/lib/esm/components/Tags.js.map +1 -1
  114. package/lib/esm/components/index.js +1 -1
  115. package/lib/esm/components/index.js.map +1 -1
  116. package/lib/esm/config/config.js.map +1 -1
  117. package/lib/esm/config/default.js +9 -1
  118. package/lib/esm/config/default.js.map +1 -1
  119. package/lib/esm/config/index.js.map +1 -1
  120. package/lib/esm/constants.js +3 -47
  121. package/lib/esm/constants.js.map +1 -1
  122. package/lib/esm/containers/AsyncApi/AsyncApi.js +23 -11
  123. package/lib/esm/containers/AsyncApi/AsyncApi.js.map +1 -1
  124. package/lib/esm/containers/AsyncApi/Layout.js +28 -20
  125. package/lib/esm/containers/AsyncApi/Layout.js.map +1 -1
  126. package/lib/esm/containers/AsyncApi/Standalone.js +4 -2
  127. package/lib/esm/containers/AsyncApi/Standalone.js.map +1 -1
  128. package/lib/esm/containers/Error/Error.js +2 -2
  129. package/lib/esm/containers/Error/Error.js.map +1 -1
  130. package/lib/esm/containers/Info/Info.js +8 -8
  131. package/lib/esm/containers/Info/Info.js.map +1 -1
  132. package/lib/esm/containers/Messages/Message.js +21 -9
  133. package/lib/esm/containers/Messages/Message.js.map +1 -1
  134. package/lib/esm/containers/Messages/MessageExample.js +19 -13
  135. package/lib/esm/containers/Messages/MessageExample.js.map +1 -1
  136. package/lib/esm/containers/Messages/Messages.js +14 -7
  137. package/lib/esm/containers/Messages/Messages.js.map +1 -1
  138. package/lib/esm/containers/Operations/Operation.js +87 -39
  139. package/lib/esm/containers/Operations/Operation.js.map +1 -1
  140. package/lib/esm/containers/Operations/Operations.js +19 -13
  141. package/lib/esm/containers/Operations/Operations.js.map +1 -1
  142. package/lib/esm/containers/Schemas/Schema.js +14 -0
  143. package/lib/esm/containers/Schemas/Schema.js.map +1 -0
  144. package/lib/esm/containers/Schemas/Schemas.js +25 -0
  145. package/lib/esm/containers/Schemas/Schemas.js.map +1 -0
  146. package/lib/esm/containers/Servers/Security.js +143 -0
  147. package/lib/esm/containers/Servers/Security.js.map +1 -0
  148. package/lib/esm/containers/Servers/Server.js +15 -9
  149. package/lib/esm/containers/Servers/Server.js.map +1 -1
  150. package/lib/esm/containers/Servers/Servers.js +10 -6
  151. package/lib/esm/containers/Servers/Servers.js.map +1 -1
  152. package/lib/esm/containers/Sidebar/Sidebar.js +203 -135
  153. package/lib/esm/containers/Sidebar/Sidebar.js.map +1 -1
  154. package/lib/esm/contexts/index.js +1 -0
  155. package/lib/esm/contexts/index.js.map +1 -1
  156. package/lib/esm/contexts/useConfig.js +6 -0
  157. package/lib/esm/contexts/useConfig.js.map +1 -0
  158. package/lib/esm/contexts/useSpec.js +2 -2
  159. package/lib/esm/contexts/useSpec.js.map +1 -1
  160. package/lib/esm/helpers/common.js +14 -0
  161. package/lib/esm/helpers/common.js.map +1 -0
  162. package/lib/esm/helpers/index.js +2 -3
  163. package/lib/esm/helpers/index.js.map +1 -1
  164. package/lib/esm/helpers/marked.js +27 -0
  165. package/lib/esm/helpers/marked.js.map +1 -0
  166. package/lib/esm/helpers/message.js +38 -8
  167. package/lib/esm/helpers/message.js.map +1 -1
  168. package/lib/esm/helpers/parser.js +16 -14
  169. package/lib/esm/helpers/parser.js.map +1 -1
  170. package/lib/esm/helpers/schema.js +182 -142
  171. package/lib/esm/helpers/schema.js.map +1 -1
  172. package/lib/esm/helpers/server.js +49 -0
  173. package/lib/esm/helpers/server.js.map +1 -1
  174. package/lib/esm/helpers/specification.js +36 -18
  175. package/lib/esm/helpers/specification.js.map +1 -1
  176. package/lib/esm/index.js +2 -1
  177. package/lib/esm/index.js.map +1 -1
  178. package/lib/esm/types.js +2 -46
  179. package/lib/esm/types.js.map +1 -1
  180. package/lib/esm/without-parser.js +2 -0
  181. package/lib/esm/without-parser.js.map +1 -1
  182. package/lib/types/components/Bindings.d.ts +2 -1
  183. package/lib/types/components/Bindings.d.ts.map +1 -1
  184. package/lib/types/components/CollapseButton.d.ts +1 -0
  185. package/lib/types/components/CollapseButton.d.ts.map +1 -1
  186. package/lib/types/components/Extensions.d.ts.map +1 -1
  187. package/lib/types/components/JSONSnippet.d.ts +7 -0
  188. package/lib/types/components/JSONSnippet.d.ts.map +1 -0
  189. package/lib/types/components/Markdown.d.ts.map +1 -1
  190. package/lib/types/components/Schema.d.ts +5 -4
  191. package/lib/types/components/Schema.d.ts.map +1 -1
  192. package/lib/types/components/Tag.d.ts +2 -2
  193. package/lib/types/components/Tag.d.ts.map +1 -1
  194. package/lib/types/components/Tags.d.ts +2 -2
  195. package/lib/types/components/Tags.d.ts.map +1 -1
  196. package/lib/types/components/index.d.ts +1 -1
  197. package/lib/types/components/index.d.ts.map +1 -1
  198. package/lib/types/config/config.d.ts +8 -0
  199. package/lib/types/config/config.d.ts.map +1 -1
  200. package/lib/types/config/default.d.ts.map +1 -1
  201. package/lib/types/constants.d.ts +3 -26
  202. package/lib/types/constants.d.ts.map +1 -1
  203. package/lib/types/containers/AsyncApi/AsyncApi.d.ts +4 -4
  204. package/lib/types/containers/AsyncApi/AsyncApi.d.ts.map +1 -1
  205. package/lib/types/containers/AsyncApi/Layout.d.ts +2 -2
  206. package/lib/types/containers/AsyncApi/Layout.d.ts.map +1 -1
  207. package/lib/types/containers/AsyncApi/Standalone.d.ts +4 -4
  208. package/lib/types/containers/AsyncApi/Standalone.d.ts.map +1 -1
  209. package/lib/types/containers/Info/Info.d.ts.map +1 -1
  210. package/lib/types/containers/Messages/Message.d.ts +3 -2
  211. package/lib/types/containers/Messages/Message.d.ts.map +1 -1
  212. package/lib/types/containers/Messages/MessageExample.d.ts +5 -4
  213. package/lib/types/containers/Messages/MessageExample.d.ts.map +1 -1
  214. package/lib/types/containers/Messages/Messages.d.ts.map +1 -1
  215. package/lib/types/containers/Operations/Operation.d.ts +4 -3
  216. package/lib/types/containers/Operations/Operation.d.ts.map +1 -1
  217. package/lib/types/containers/Operations/Operations.d.ts.map +1 -1
  218. package/lib/types/containers/Schemas/Schema.d.ts +9 -0
  219. package/lib/types/containers/Schemas/Schema.d.ts.map +1 -0
  220. package/lib/types/containers/Schemas/Schemas.d.ts +3 -0
  221. package/lib/types/containers/Schemas/Schemas.d.ts.map +1 -0
  222. package/lib/types/containers/Servers/Security.d.ts +10 -0
  223. package/lib/types/containers/Servers/Security.d.ts.map +1 -0
  224. package/lib/types/containers/Servers/Server.d.ts +2 -2
  225. package/lib/types/containers/Servers/Server.d.ts.map +1 -1
  226. package/lib/types/containers/Servers/Servers.d.ts.map +1 -1
  227. package/lib/types/containers/Sidebar/Sidebar.d.ts +1 -9
  228. package/lib/types/containers/Sidebar/Sidebar.d.ts.map +1 -1
  229. package/lib/types/contexts/index.d.ts +1 -0
  230. package/lib/types/contexts/index.d.ts.map +1 -1
  231. package/lib/types/contexts/useConfig.d.ts +5 -0
  232. package/lib/types/contexts/useConfig.d.ts.map +1 -0
  233. package/lib/types/contexts/useSpec.d.ts +3 -5
  234. package/lib/types/contexts/useSpec.d.ts.map +1 -1
  235. package/lib/types/helpers/common.d.ts +5 -0
  236. package/lib/types/helpers/common.d.ts.map +1 -0
  237. package/lib/types/helpers/index.d.ts +2 -3
  238. package/lib/types/helpers/index.d.ts.map +1 -1
  239. package/lib/types/helpers/marked.d.ts +4 -0
  240. package/lib/types/helpers/marked.d.ts.map +1 -0
  241. package/lib/types/helpers/message.d.ts +4 -3
  242. package/lib/types/helpers/message.d.ts.map +1 -1
  243. package/lib/types/helpers/parser.d.ts.map +1 -1
  244. package/lib/types/helpers/schema.d.ts +16 -12
  245. package/lib/types/helpers/schema.d.ts.map +1 -1
  246. package/lib/types/helpers/server.d.ts +6 -1
  247. package/lib/types/helpers/server.d.ts.map +1 -1
  248. package/lib/types/helpers/specification.d.ts +7 -4
  249. package/lib/types/helpers/specification.d.ts.map +1 -1
  250. package/lib/types/index.d.ts +2 -1
  251. package/lib/types/index.d.ts.map +1 -1
  252. package/lib/types/types.d.ts +12 -305
  253. package/lib/types/types.d.ts.map +1 -1
  254. package/lib/types/without-parser.d.ts +2 -0
  255. package/lib/types/without-parser.d.ts.map +1 -1
  256. package/package.json +43 -19
  257. package/styles/default.css +929 -646
  258. package/styles/default.min.css +4 -2
  259. package/lib/cjs/components/Code.js +0 -15
  260. package/lib/cjs/components/Code.js.map +0 -1
  261. package/lib/cjs/containers/Servers/ServerSecurity.js +0 -101
  262. package/lib/cjs/containers/Servers/ServerSecurity.js.map +0 -1
  263. package/lib/cjs/helpers/bemClasses.js +0 -49
  264. package/lib/cjs/helpers/bemClasses.js.map +0 -1
  265. package/lib/cjs/helpers/formatJsonHighlight.js +0 -61
  266. package/lib/cjs/helpers/formatJsonHighlight.js.map +0 -1
  267. package/lib/cjs/helpers/toKebabCase.js +0 -15
  268. package/lib/cjs/helpers/toKebabCase.js.map +0 -1
  269. package/lib/esm/components/Code.js +0 -9
  270. package/lib/esm/components/Code.js.map +0 -1
  271. package/lib/esm/containers/Servers/ServerSecurity.js +0 -95
  272. package/lib/esm/containers/Servers/ServerSecurity.js.map +0 -1
  273. package/lib/esm/helpers/bemClasses.js +0 -46
  274. package/lib/esm/helpers/bemClasses.js.map +0 -1
  275. package/lib/esm/helpers/formatJsonHighlight.js +0 -57
  276. package/lib/esm/helpers/formatJsonHighlight.js.map +0 -1
  277. package/lib/esm/helpers/toKebabCase.js +0 -11
  278. package/lib/esm/helpers/toKebabCase.js.map +0 -1
  279. package/lib/types/components/Code.d.ts +0 -7
  280. package/lib/types/components/Code.d.ts.map +0 -1
  281. package/lib/types/containers/Servers/ServerSecurity.d.ts +0 -8
  282. package/lib/types/containers/Servers/ServerSecurity.d.ts.map +0 -1
  283. package/lib/types/helpers/bemClasses.d.ts +0 -14
  284. package/lib/types/helpers/bemClasses.d.ts.map +0 -1
  285. package/lib/types/helpers/formatJsonHighlight.d.ts +0 -2
  286. package/lib/types/helpers/formatJsonHighlight.d.ts.map +0 -1
  287. package/lib/types/helpers/toKebabCase.d.ts +0 -2
  288. package/lib/types/helpers/toKebabCase.d.ts.map +0 -1
@@ -26,24 +26,54 @@ var MessageHelpers = (function () {
26
26
  return schema;
27
27
  };
28
28
  MessageHelpers.getPayloadExamples = function (msg) {
29
- var examples = msg.examples();
30
- if (Array.isArray(examples) && examples.some(function (e) { return e.payload; })) {
31
- return examples.flatMap(function (e) { return e.payload; }).filter(Boolean);
29
+ var _a;
30
+ var examples = msg.examples().all();
31
+ if (examples.some(function (e) { return e.hasPayload(); })) {
32
+ var messageExamples = examples
33
+ .flatMap(function (e) {
34
+ if (!e.payload()) {
35
+ return;
36
+ }
37
+ return {
38
+ name: e.name(),
39
+ summary: e.summary(),
40
+ example: e.payload(),
41
+ };
42
+ })
43
+ .filter(Boolean);
44
+ if (messageExamples.length > 0) {
45
+ return messageExamples;
46
+ }
32
47
  }
33
48
  var payload = msg.payload();
34
49
  if (payload && payload.examples()) {
35
- return payload.examples();
50
+ return (_a = payload.examples()) === null || _a === void 0 ? void 0 : _a.map(function (example) { return ({ example: example }); });
36
51
  }
37
52
  return;
38
53
  };
39
54
  MessageHelpers.getHeadersExamples = function (msg) {
40
- var examples = msg.examples();
41
- if (Array.isArray(examples) && examples.some(function (e) { return e.headers; })) {
42
- return examples.flatMap(function (e) { return e.headers; }).filter(Boolean);
55
+ var _a;
56
+ var examples = msg.examples().all();
57
+ if (examples.some(function (e) { return e.hasHeaders(); })) {
58
+ var messageExamples = examples
59
+ .flatMap(function (e) {
60
+ if (!e.hasHeaders()) {
61
+ return;
62
+ }
63
+ return {
64
+ name: e.name(),
65
+ summary: e.summary(),
66
+ example: e.headers(),
67
+ };
68
+ })
69
+ .filter(Boolean);
70
+ if (messageExamples.length > 0) {
71
+ return messageExamples;
72
+ }
43
73
  }
44
74
  var headers = msg.headers();
45
75
  if (headers && headers.examples()) {
46
- return headers.examples();
76
+ return (_a = headers.examples()) === null || _a === void 0 ? void 0 : _a.map(function (example) { return ({ example: example }); });
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OAAA,CAAC,EAAE,OAAO,SAAA,EAAE,CAAC,EAAb,CAAa,CAAC,CAAC;SAC1D;QAED,OAAO;IACT,CAAC;IACH,qBAAC;AAAD,CAAC,AAtFD,IAsFC","sourcesContent":["import { MessageInterface } from '@asyncapi/parser';\n// @ts-ignore\nimport { sample } from 'openapi-sampler';\n\nimport { MessageExample } from '../types';\n\nexport class MessageHelpers {\n static generateExample(schema: any, options: any = {}) {\n try {\n return this.sanitizeExample(sample(schema, options)) || '';\n } catch (e) {\n return '';\n }\n }\n\n static sanitizeExample(schema: any): any {\n if (typeof schema === 'object' && schema && !Array.isArray(schema)) {\n return Object.entries(schema).reduce((obj, [propertyName, property]) => {\n if (\n !propertyName.startsWith('x-parser-') &&\n !propertyName.startsWith('x-schema-private-')\n ) {\n obj[propertyName] = this.sanitizeExample(property);\n }\n return obj;\n }, {});\n }\n return schema;\n }\n\n static getPayloadExamples(\n msg: MessageInterface,\n ): MessageExample[] | undefined {\n const examples = msg.examples().all();\n\n if (examples.some(e => e.hasPayload())) {\n const messageExamples = examples\n .flatMap(e => {\n if (!e.payload()) {\n return;\n }\n return {\n name: e.name(),\n summary: e.summary(),\n example: e.payload(),\n };\n })\n .filter(Boolean) as MessageExample[];\n\n if (messageExamples.length > 0) {\n return messageExamples;\n }\n }\n\n const payload = msg.payload();\n if (payload && payload.examples()) {\n return payload.examples()?.map(example => ({ example }));\n }\n\n return;\n }\n\n static getHeadersExamples(\n msg: MessageInterface,\n ): MessageExample[] | undefined {\n const examples = msg.examples().all();\n if (examples.some(e => e.hasHeaders())) {\n const messageExamples = examples\n .flatMap(e => {\n if (!e.hasHeaders()) {\n return;\n }\n return {\n name: e.name(),\n summary: e.summary(),\n example: e.headers(),\n };\n })\n .filter(Boolean) as MessageExample[];\n\n if (messageExamples.length > 0) {\n return messageExamples;\n }\n }\n\n const headers = msg.headers();\n if (headers && headers.examples()) {\n return headers.examples()?.map(example => ({ example }));\n }\n\n return;\n }\n}\n"]}
@@ -13,7 +13,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
13
13
  function verb(n) { return function (v) { return step([n, v]); }; }
14
14
  function step(op) {
15
15
  if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
17
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
18
  if (y = 0, t) op = [op[0] & 2, t.value];
19
19
  switch (op[0]) {
@@ -34,26 +34,27 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
- import { parse, parseFromUrl, registerSchemaParser } from '@asyncapi/parser';
38
- import openapiSchemaParser from '@asyncapi/openapi-schema-parser';
39
- import avroSchemaParser from '@asyncapi/avro-schema-parser';
37
+ import { Parser as AsyncapiParser, fromURL } from '@asyncapi/parser';
38
+ import { OpenAPISchemaParser } from '@asyncapi/openapi-schema-parser';
39
+ import { AvroSchemaParser } from '@asyncapi/avro-schema-parser';
40
40
  import { VALIDATION_ERRORS_TYPE } from '../constants';
41
- registerSchemaParser(openapiSchemaParser);
42
- registerSchemaParser(avroSchemaParser);
41
+ var asyncapiParser = new AsyncapiParser();
42
+ asyncapiParser.registerSchemaParser(OpenAPISchemaParser());
43
+ asyncapiParser.registerSchemaParser(AvroSchemaParser());
43
44
  var Parser = (function () {
44
45
  function Parser() {
45
46
  }
46
47
  Parser.parse = function (content, parserOptions) {
47
48
  return __awaiter(this, void 0, void 0, function () {
48
- var asyncapi, err_1;
49
+ var document_1, err_1;
49
50
  return __generator(this, function (_a) {
50
51
  switch (_a.label) {
51
52
  case 0:
52
53
  _a.trys.push([0, 2, , 3]);
53
- return [4, parse(content, parserOptions)];
54
+ return [4, asyncapiParser.parse(content, parserOptions)];
54
55
  case 1:
55
- asyncapi = _a.sent();
56
- return [2, { asyncapi: asyncapi }];
56
+ document_1 = (_a.sent()).document;
57
+ return [2, { asyncapi: document_1 }];
57
58
  case 2:
58
59
  err_1 = _a.sent();
59
60
  return [2, this.handleError(err_1)];
@@ -64,15 +65,16 @@ var Parser = (function () {
64
65
  };
65
66
  Parser.parseFromUrl = function (arg, parserOptions) {
66
67
  return __awaiter(this, void 0, void 0, function () {
67
- var asyncapi, err_2;
68
+ var fromResult, document_2, err_2;
68
69
  return __generator(this, function (_a) {
69
70
  switch (_a.label) {
70
71
  case 0:
71
72
  _a.trys.push([0, 2, , 3]);
72
- return [4, parseFromUrl(arg.url, arg.requestOptions, parserOptions)];
73
+ fromResult = fromURL(asyncapiParser, arg.url, arg.requestOptions);
74
+ return [4, fromResult.parse(parserOptions)];
73
75
  case 1:
74
- asyncapi = _a.sent();
75
- return [2, { asyncapi: asyncapi }];
76
+ document_2 = (_a.sent()).document;
77
+ return [2, { asyncapi: document_2 }];
76
78
  case 2:
77
79
  err_2 = _a.sent();
78
80
  return [2, this.handleError(err_2)];
@@ -1 +1 @@
1
- {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/helpers/parser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7E,OAAO,mBAAmB,MAAM,iCAAiC,CAAC;AAElE,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAI5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,oBAAoB,CAAC,mBAAmB,CAAC,CAAC;AAC1C,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;AAEvC;IAAA;IAqCA,CAAC;IApCc,YAAK,GAAlB,UACE,OAAqB,EACrB,aAAmB;;;;;;;wBAGA,WAAM,KAAK,CAAC,OAAO,EAAE,aAAa,CAAC,EAAA;;wBAA9C,QAAQ,GAAG,SAAmC;wBACp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;;;;wBAGI,WAAM,cAAc,CAAC,KAAK,CAAC,OAAO,EAAE,aAAa,CAAC,EAAA;;wBAA/D,aAAa,CAAA,SAAkD,CAAA,SAAvD;wBAChB,WAAO,EAAE,QAAQ,EAAE,UAAQ,EAAE,EAAC;;;wBAE9B,WAAO,IAAI,CAAC,WAAW,CAAC,KAAkB,CAAC,EAAC;;;;;KAE/C;IAEY,mBAAY,GAAzB,UACE,GAA4B,EAC5B,aAAmB;;;;;;;wBAGX,UAAU,GAAG,OAAO,CACxB,cAAc,EACd,GAAG,CAAC,GAAG,EACP,GAAG,CAAC,cAAqB,CAC1B,CAAC;wBACmB,WAAM,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC,EAAA;;wBAAlD,aAAa,CAAA,SAAqC,CAAA,SAA1C;wBAChB,WAAO,EAAE,QAAQ,EAAE,UAAQ,EAAE,EAAC;;;wBAE9B,WAAO,IAAI,CAAC,WAAW,CAAC,KAAkB,CAAC,EAAC;;;;;KAE/C;IAEc,kBAAW,GAAG,UAAC,GAAgB;QAC5C,IAAI,GAAG,CAAC,IAAI,KAAK,sBAAsB,EAAE;YACvC,OAAO;gBACL,KAAK,EAAE,GAAG;aACX,CAAC;SACH;QACD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IACxB,CAAC,CAAC;IACJ,aAAC;CAAA,AAtCD,IAsCC;SAtCY,MAAM","sourcesContent":["import { Parser as AsyncapiParser, fromURL } from '@asyncapi/parser';\nimport { OpenAPISchemaParser } from '@asyncapi/openapi-schema-parser';\nimport { AvroSchemaParser } from '@asyncapi/avro-schema-parser';\n// @ts-ignore\nimport protoSchemaParser from '@asyncapi/protobuf-schema-parser';\n\nimport { ErrorObject, ParserReturn, FetchingSchemaInterface } from '../types';\n\nimport { VALIDATION_ERRORS_TYPE } from '../constants';\n\nconst asyncapiParser = new AsyncapiParser();\nasyncapiParser.registerSchemaParser(OpenAPISchemaParser());\nasyncapiParser.registerSchemaParser(AvroSchemaParser());\n// Waiting for schema parser to be upgraded\n// asyncapiParser.registerSchemaParser(protoSchemaParser);\n\nexport class Parser {\n static async parse(\n content: string | any,\n parserOptions?: any,\n ): Promise<ParserReturn> {\n try {\n const { document } = await asyncapiParser.parse(content, parserOptions);\n return { asyncapi: document };\n } catch (err) {\n return this.handleError(err as ErrorObject);\n }\n }\n\n static async parseFromUrl(\n arg: FetchingSchemaInterface,\n parserOptions?: any,\n ): Promise<ParserReturn> {\n try {\n const fromResult = fromURL(\n asyncapiParser,\n arg.url,\n arg.requestOptions as any,\n );\n const { document } = await fromResult.parse(parserOptions);\n return { asyncapi: document };\n } catch (err) {\n return this.handleError(err as ErrorObject);\n }\n }\n\n private static handleError = (err: ErrorObject): ParserReturn => {\n if (err.type === VALIDATION_ERRORS_TYPE) {\n return {\n error: err,\n };\n }\n return { error: err };\n };\n}\n"]}
@@ -1,17 +1,80 @@
1
- import SchemaClass from '@asyncapi/parser/lib/models/schema';
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { SchemaV2 as SchemaClass, } from '@asyncapi/parser';
13
+ export var SchemaCustomTypes;
14
+ (function (SchemaCustomTypes) {
15
+ SchemaCustomTypes["ANY"] = "any";
16
+ SchemaCustomTypes["RESTRICTED_ANY"] = "restricted any";
17
+ SchemaCustomTypes["NEVER"] = "never";
18
+ SchemaCustomTypes["UNKNOWN"] = "unknown";
19
+ })(SchemaCustomTypes || (SchemaCustomTypes = {}));
20
+ var jsonSchemaTypes = [
21
+ 'string',
22
+ 'number',
23
+ 'integer',
24
+ 'boolean',
25
+ 'array',
26
+ 'object',
27
+ 'null',
28
+ ];
29
+ var jsonSchemaKeywordTypes = {
30
+ maxLength: 'string',
31
+ minLength: 'string',
32
+ pattern: 'string',
33
+ contentMediaType: 'string',
34
+ contentEncoding: 'string',
35
+ multipleOf: 'number',
36
+ maximum: 'number',
37
+ exclusiveMaximum: 'number',
38
+ minimum: 'number',
39
+ exclusiveMinimum: 'number',
40
+ items: 'array',
41
+ maxItems: 'array',
42
+ minItems: 'array',
43
+ uniqueItems: 'array',
44
+ contains: 'array',
45
+ additionalItems: 'array',
46
+ maxProperties: 'object',
47
+ minProperties: 'object',
48
+ required: 'object',
49
+ properties: 'object',
50
+ patternProperties: 'object',
51
+ propertyNames: 'object',
52
+ dependencies: 'object',
53
+ additionalProperties: 'object',
54
+ };
55
+ var jsonSchemaKeywords = Object.keys(jsonSchemaKeywordTypes);
2
56
  var SchemaHelpers = (function () {
3
57
  function SchemaHelpers() {
4
58
  }
5
59
  SchemaHelpers.toSchemaType = function (schema) {
6
60
  var _this = this;
7
- if (schema === true) {
8
- return 'any';
61
+ if (!schema || typeof schema.json !== 'function') {
62
+ return SchemaCustomTypes.UNKNOWN;
9
63
  }
10
- if (schema === false) {
11
- return 'never';
64
+ if (schema.isBooleanSchema()) {
65
+ if (schema.json() === true) {
66
+ return SchemaCustomTypes.ANY;
67
+ }
68
+ else {
69
+ return SchemaCustomTypes.NEVER;
70
+ }
12
71
  }
13
72
  if (Object.keys(schema.json()).length === 0) {
14
- return 'any';
73
+ return SchemaCustomTypes.ANY;
74
+ }
75
+ var not = schema.not();
76
+ if (not && this.inferType(not) === SchemaCustomTypes.ANY) {
77
+ return SchemaCustomTypes.NEVER;
15
78
  }
16
79
  var type = this.inferType(schema);
17
80
  if (Array.isArray(type)) {
@@ -20,23 +83,24 @@ var SchemaHelpers = (function () {
20
83
  type = this.toType(type, schema);
21
84
  var combinedType = this.toCombinedType(schema);
22
85
  if (type && combinedType) {
23
- return type + " " + combinedType;
86
+ return "".concat(type, " ").concat(combinedType);
24
87
  }
25
88
  if (combinedType) {
26
89
  return combinedType;
27
90
  }
28
91
  return type;
29
92
  };
30
- SchemaHelpers.prettifyValue = function (value) {
93
+ SchemaHelpers.prettifyValue = function (value, strict) {
94
+ if (strict === void 0) { strict = true; }
31
95
  var typeOf = typeof value;
32
96
  if (typeOf === 'string') {
33
- return "\"" + value + "\"";
97
+ return strict ? "\"".concat(value, "\"") : value;
34
98
  }
35
99
  if (typeOf === 'number' || typeOf === 'bigint' || typeOf === 'boolean') {
36
- return value;
100
+ return "".concat(value);
37
101
  }
38
102
  if (Array.isArray(value)) {
39
- return "[" + value.toString() + "]";
103
+ return "[".concat(value.toString(), "]");
40
104
  }
41
105
  return JSON.stringify(value);
42
106
  };
@@ -74,6 +138,8 @@ var SchemaHelpers = (function () {
74
138
  if (schema.oneOf() ||
75
139
  schema.anyOf() ||
76
140
  schema.allOf() ||
141
+ Object.keys(schema.properties() || {}).length > 0 ||
142
+ schema.items() ||
77
143
  schema.not() ||
78
144
  schema.if() ||
79
145
  schema.then() ||
@@ -88,20 +154,19 @@ var SchemaHelpers = (function () {
88
154
  };
89
155
  SchemaHelpers.serverVariablesToSchema = function (urlVariables) {
90
156
  var _a;
91
- if (!urlVariables || !Object.keys(urlVariables).length) {
157
+ if (!urlVariables || urlVariables.length === 0) {
92
158
  return undefined;
93
159
  }
160
+ var obj = {};
161
+ urlVariables.all().forEach(function (variable) {
162
+ obj[variable.id()] = __assign({}, (variable.json() || {}));
163
+ obj[variable.id()].type = 'string';
164
+ });
94
165
  var json = (_a = {
95
166
  type: 'object',
96
- properties: Object.entries(urlVariables).reduce(function (obj, _a) {
97
- var urlName = _a[0], url = _a[1];
98
- obj[urlName] = Object.assign({}, url.json());
99
- obj[urlName].type = 'string';
100
- return obj;
101
- }, {}),
102
- required: Object.keys(urlVariables)
167
+ properties: obj,
168
+ required: Object.keys(obj)
103
169
  },
104
- _a[this.extRenderType] = false,
105
170
  _a[this.extRenderAdditionalInfo] = false,
106
171
  _a);
107
172
  return new SchemaClass(json);
@@ -109,22 +174,26 @@ var SchemaHelpers = (function () {
109
174
  SchemaHelpers.parametersToSchema = function (parameters) {
110
175
  var _a;
111
176
  var _this = this;
112
- if (!parameters || !Object.keys(parameters).length) {
177
+ if (!parameters || parameters.isEmpty()) {
113
178
  return undefined;
114
179
  }
180
+ var obj = {};
181
+ parameters.all().forEach(function (parameter) {
182
+ var _a;
183
+ var parameterSchema = parameter.schema();
184
+ obj[parameter.id()] = __assign({}, ((_a = parameterSchema === null || parameterSchema === void 0 ? void 0 : parameterSchema.json()) !== null && _a !== void 0 ? _a : {}));
185
+ obj[parameter.id()].description = parameter.hasDescription()
186
+ ? parameter.description()
187
+ : undefined;
188
+ obj[parameter.id()][_this.extParameterLocation] = parameter.hasLocation()
189
+ ? parameter.location()
190
+ : undefined;
191
+ });
115
192
  var json = (_a = {
116
193
  type: 'object',
117
- properties: Object.entries(parameters).reduce(function (obj, _a) {
118
- var paramaterName = _a[0], parameter = _a[1];
119
- obj[paramaterName] = Object.assign({}, parameter.schema().json());
120
- obj[paramaterName].description =
121
- parameter.description() || obj[paramaterName].description;
122
- obj[paramaterName][_this.extParameterLocation] = parameter.location();
123
- return obj;
124
- }, {}),
125
- required: Object.keys(parameters)
194
+ properties: obj,
195
+ required: Object.keys(obj)
126
196
  },
127
- _a[this.extRenderType] = false,
128
197
  _a[this.extRenderAdditionalInfo] = false,
129
198
  _a);
130
199
  return new SchemaClass(json);
@@ -137,14 +206,17 @@ var SchemaHelpers = (function () {
137
206
  if (!value || typeof value.extensions !== 'function') {
138
207
  return;
139
208
  }
140
- return Object.entries(value.extensions() || {}).reduce(function (obj, _a) {
141
- var extName = _a[0], ext = _a[1];
142
- if (!extName.startsWith('x-parser-') &&
143
- !extName.startsWith('x-schema-private-')) {
144
- obj[extName] = ext;
209
+ var extensions = value.extensions();
210
+ var filteredExtensions = {};
211
+ for (var _i = 0, _a = extensions.all(); _i < _a.length; _i++) {
212
+ var ext = _a[_i];
213
+ var extType = ext;
214
+ if (!extType.id().startsWith('x-parser-') &&
215
+ !extType.id().startsWith('x-schema-private-')) {
216
+ filteredExtensions[extType.id()] = extType.value();
145
217
  }
146
- return obj;
147
- }, {});
218
+ }
219
+ return filteredExtensions;
148
220
  };
149
221
  SchemaHelpers.getDependentRequired = function (propertyName, schema) {
150
222
  var dependentRequired = [];
@@ -180,34 +252,46 @@ var SchemaHelpers = (function () {
180
252
  type: 'object',
181
253
  properties: Object.entries(records).reduce(function (obj, _a) {
182
254
  var propertyName = _a[0], propertySchema = _a[1];
183
- obj[propertyName] = Object.assign({}, propertySchema.json());
255
+ obj[propertyName] = __assign({}, (propertySchema.json() || {}));
184
256
  return obj;
185
257
  }, {})
186
258
  },
187
- _a[this.extRenderType] = false,
188
259
  _a[this.extRenderAdditionalInfo] = false,
189
260
  _a);
190
261
  return new SchemaClass(json);
191
262
  };
192
263
  SchemaHelpers.toType = function (type, schema) {
193
- var _this = this;
264
+ if (schema.isCircular()) {
265
+ return type;
266
+ }
194
267
  if (type === 'array') {
195
268
  var items = schema.items();
196
- var types = void 0;
197
269
  if (Array.isArray(items)) {
198
- types = items.map(function (item) { return _this.toSchemaType(item); }).join(', ');
199
- types = types.length ? types : 'unknown';
270
+ return this.toItemsType(items, schema);
200
271
  }
201
- else if (items) {
202
- types = this.toSchemaType(items);
203
- types = types || 'unknown';
272
+ if (!items) {
273
+ return "array<".concat(SchemaCustomTypes.ANY, ">");
204
274
  }
205
- return "array<" + types + ">";
275
+ return "array<".concat(this.toSchemaType(items) || SchemaCustomTypes.UNKNOWN, ">");
206
276
  }
207
277
  return type;
208
278
  };
279
+ SchemaHelpers.toItemsType = function (items, schema) {
280
+ var _this = this;
281
+ var types = items.map(function (item) { return _this.toSchemaType(item); }).join(', ');
282
+ var additionalItems = schema.additionalItems();
283
+ if (additionalItems !== undefined && additionalItems !== false) {
284
+ var additionalType = additionalItems === true
285
+ ? SchemaCustomTypes.ANY
286
+ : this.toSchemaType(additionalItems);
287
+ return "tuple<".concat(types ||
288
+ SchemaCustomTypes.UNKNOWN, ", ...optional<").concat(additionalType, ">>");
289
+ }
290
+ return "tuple<".concat(types || SchemaCustomTypes.UNKNOWN, ">");
291
+ };
209
292
  SchemaHelpers.toCombinedType = function (schema) {
210
- if (schema.oneOf()) {
293
+ var oneOf = schema.oneOf();
294
+ if (oneOf) {
211
295
  return 'oneOf';
212
296
  }
213
297
  if (schema.anyOf()) {
@@ -219,49 +303,36 @@ var SchemaHelpers = (function () {
219
303
  return;
220
304
  };
221
305
  SchemaHelpers.inferType = function (schema) {
222
- var jsonSchema = schema.json();
223
- var keywords = Object.keys(this.jsonSchemaKeywordTypes);
224
- var keywordsLength = keywords.length;
225
- var possibleTypes = {};
226
- var jsonTypes = jsonSchema.type;
227
- if (jsonTypes !== undefined) {
228
- if (Array.isArray(jsonTypes)) {
229
- for (var i = 0, l = jsonTypes.length; i < l; i++) {
230
- possibleTypes[jsonTypes[i]] = undefined;
306
+ var types = schema.type();
307
+ if (types !== undefined) {
308
+ if (Array.isArray(types)) {
309
+ if (types.includes('integer') && types.includes('number')) {
310
+ types = types.filter(function (t) { return t !== 'integer'; });
231
311
  }
312
+ return types.length === 1 ? types[0] : types;
232
313
  }
233
- else {
234
- possibleTypes[jsonTypes] = undefined;
235
- }
236
- }
237
- for (var i = 0; i < keywordsLength; i++) {
238
- var keyword = keywords[i];
239
- if (jsonSchema[keyword] !== undefined) {
240
- possibleTypes[this.jsonSchemaKeywordTypes[keyword]] = undefined;
241
- }
314
+ return types;
242
315
  }
243
- if (jsonSchema.enum) {
244
- for (var _i = 0, _a = jsonSchema.enum; _i < _a.length; _i++) {
245
- var value = _a[_i];
246
- possibleTypes[typeof value] = undefined;
247
- }
248
- }
249
- var types = Object.keys(possibleTypes);
250
- if (types.length === 1) {
251
- return types[0];
316
+ var constValue = schema.const();
317
+ if (constValue !== undefined) {
318
+ return typeof constValue;
252
319
  }
253
- if (jsonTypes === 'integer') {
254
- return types.filter(function (t) { return t !== 'number'; });
320
+ var enumValue = schema.enum();
321
+ if (Array.isArray(enumValue) && enumValue.length) {
322
+ var inferredType = Array.from(new Set(enumValue.map(function (e) { return typeof e; })));
323
+ return inferredType.length === 1 ? inferredType[0] : inferredType;
255
324
  }
256
- if (Array.isArray(jsonTypes) &&
257
- jsonTypes.includes('integer') &&
258
- !jsonTypes.includes('number')) {
259
- return types.filter(function (t) { return t !== 'number'; });
325
+ var schemaKeys = Object.keys(schema.json() || {}) || [];
326
+ var hasInferredTypes = jsonSchemaKeywords.some(function (key) {
327
+ return schemaKeys.includes(key);
328
+ });
329
+ if (hasInferredTypes === true) {
330
+ return SchemaCustomTypes.RESTRICTED_ANY;
260
331
  }
261
- if (types.includes('integer') && types.includes('number')) {
262
- return types.filter(function (t) { return t !== 'integer'; });
332
+ if (this.toCombinedType(schema)) {
333
+ return '';
263
334
  }
264
- return types;
335
+ return SchemaCustomTypes.ANY;
265
336
  };
266
337
  SchemaHelpers.humanizeNumberRangeConstraint = function (min, exclusiveMin, max, exclusiveMax) {
267
338
  var hasExclusiveMin = exclusiveMin !== undefined;
@@ -292,58 +363,65 @@ var SchemaHelpers = (function () {
292
363
  }
293
364
  var strigifiedMultipleOf = multipleOf.toString(10);
294
365
  if (!/^0\.0*1$/.test(strigifiedMultipleOf)) {
295
- return "multiple of " + strigifiedMultipleOf;
366
+ return "multiple of ".concat(strigifiedMultipleOf);
296
367
  }
297
- return "decimal places <= " + strigifiedMultipleOf.split('.')[1].length;
368
+ return "decimal places <= ".concat(strigifiedMultipleOf.split('.')[1].length);
298
369
  };
299
370
  SchemaHelpers.humanizeRangeConstraint = function (description, min, max) {
300
371
  var stringRange;
301
372
  if (min !== undefined && max !== undefined) {
302
373
  if (min === max) {
303
- stringRange = min + " " + description;
374
+ stringRange = "".concat(min, " ").concat(description);
304
375
  }
305
376
  else {
306
- stringRange = "[ " + min + " .. " + max + " ] " + description;
377
+ stringRange = "[ ".concat(min, " .. ").concat(max, " ] ").concat(description);
307
378
  }
308
379
  }
309
380
  else if (max !== undefined) {
310
- stringRange = "<= " + max + " " + description;
381
+ stringRange = "<= ".concat(max, " ").concat(description);
311
382
  }
312
383
  else if (min !== undefined) {
313
384
  if (min === 1) {
314
385
  stringRange = 'non-empty';
315
386
  }
316
387
  else {
317
- stringRange = ">= " + min + " " + description;
388
+ stringRange = ">= ".concat(min, " ").concat(description);
318
389
  }
319
390
  }
320
391
  return stringRange;
321
392
  };
322
393
  SchemaHelpers.jsonFieldToSchema = function (value) {
323
- var _a, _b, _c;
394
+ var _a, _b, _c, _d;
324
395
  var _this = this;
325
- if (typeof value !== 'object') {
326
- var str = typeof value.toString === 'function' ? value.toString() : value;
396
+ if (value === undefined || value === null) {
327
397
  return _a = {
328
398
  type: 'string',
329
- const: str
399
+ const: ''
330
400
  },
331
401
  _a[this.extRawValue] = true,
332
402
  _a;
333
403
  }
404
+ if (typeof value !== 'object') {
405
+ var str = typeof value.toString === 'function' ? value.toString() : value;
406
+ return _b = {
407
+ type: 'string',
408
+ const: str
409
+ },
410
+ _b[this.extRawValue] = true,
411
+ _b;
412
+ }
334
413
  if (this.isJSONSchema(value)) {
335
414
  return value;
336
415
  }
337
416
  if (Array.isArray(value)) {
338
- return _b = {
417
+ return _c = {
339
418
  type: 'array',
340
419
  items: value.map(function (v) { return _this.jsonFieldToSchema(v); })
341
420
  },
342
- _b[this.extRenderType] = false,
343
- _b[this.extRenderAdditionalInfo] = false,
344
- _b;
421
+ _c[this.extRenderAdditionalInfo] = false,
422
+ _c;
345
423
  }
346
- return _c = {
424
+ return _d = {
347
425
  type: 'object',
348
426
  properties: Object.entries(value).reduce(function (obj, _a) {
349
427
  var k = _a[0], v = _a[1];
@@ -351,60 +429,22 @@ var SchemaHelpers = (function () {
351
429
  return obj;
352
430
  }, {})
353
431
  },
354
- _c[this.extRenderType] = false,
355
- _c[this.extRenderAdditionalInfo] = false,
356
- _c;
432
+ _d[this.extRenderAdditionalInfo] = false,
433
+ _d;
357
434
  };
358
435
  SchemaHelpers.isJSONSchema = function (value) {
359
- var _this = this;
360
436
  if (value &&
361
437
  typeof value === 'object' &&
362
- (this.jsonSchemaTypes.includes(value.type) ||
438
+ (jsonSchemaTypes.includes(value.type) ||
363
439
  (Array.isArray(value.type) &&
364
- value.type.some(function (t) { return !_this.jsonSchemaTypes.includes(t); })))) {
440
+ value.type.some(function (t) { return !jsonSchemaTypes.includes(t); })))) {
365
441
  return true;
366
442
  }
367
443
  return false;
368
444
  };
369
- SchemaHelpers.extRenderType = 'x-schema-private-render-type';
370
445
  SchemaHelpers.extRenderAdditionalInfo = 'x-schema-private-render-additional-info';
371
446
  SchemaHelpers.extRawValue = 'x-schema-private-raw-value';
372
447
  SchemaHelpers.extParameterLocation = 'x-schema-private-parameter-location';
373
- SchemaHelpers.jsonSchemaTypes = [
374
- 'string',
375
- 'number',
376
- 'integer',
377
- 'boolean',
378
- 'array',
379
- 'object',
380
- 'null',
381
- ];
382
- SchemaHelpers.jsonSchemaKeywordTypes = {
383
- maxLength: 'string',
384
- minLength: 'string',
385
- pattern: 'string',
386
- contentMediaType: 'string',
387
- contentEncoding: 'string',
388
- multipleOf: 'number',
389
- maximum: 'number',
390
- exclusiveMaximum: 'number',
391
- minimum: 'number',
392
- exclusiveMinimum: 'number',
393
- items: 'array',
394
- maxItems: 'array',
395
- minItems: 'array',
396
- uniqueItems: 'array',
397
- contains: 'array',
398
- additionalItems: 'array',
399
- maxProperties: 'object',
400
- minProperties: 'object',
401
- required: 'object',
402
- properties: 'object',
403
- patternProperties: 'object',
404
- propertyNames: 'object',
405
- dependencies: 'object',
406
- additionalProperties: 'object',
407
- };
408
448
  return SchemaHelpers;
409
449
  }());
410
450
  export { SchemaHelpers };