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

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 (286) hide show
  1. package/README.md +75 -4
  2. package/browser/index.js +32 -14
  3. package/browser/index.js.LICENSE.txt +88 -0
  4. package/browser/standalone/index.js +32 -0
  5. package/browser/standalone/index.js.LICENSE.txt +112 -0
  6. package/browser/standalone/without-parser.js +14 -0
  7. package/browser/standalone/without-parser.js.LICENSE.txt +110 -0
  8. package/browser/without-parser.js +14 -12
  9. package/browser/without-parser.js.LICENSE.txt +86 -0
  10. package/lib/cjs/components/Bindings.js +12 -4
  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 +75 -58
  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 +2 -1
  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 +8 -2
  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 +8 -2
  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 +11 -7
  52. package/lib/cjs/containers/Messages/Messages.js.map +1 -1
  53. package/lib/cjs/containers/Operations/Operation.js +73 -37
  54. package/lib/cjs/containers/Operations/Operation.js.map +1 -1
  55. package/lib/cjs/containers/Operations/Operations.js +16 -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 +28 -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 +7 -4
  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 +14 -15
  84. package/lib/cjs/helpers/parser.js.map +1 -1
  85. package/lib/cjs/helpers/schema.js +157 -135
  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 +10 -3
  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 +69 -57
  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.map +1 -1
  113. package/lib/esm/components/index.js +1 -1
  114. package/lib/esm/components/index.js.map +1 -1
  115. package/lib/esm/config/config.js.map +1 -1
  116. package/lib/esm/config/default.js +9 -1
  117. package/lib/esm/config/default.js.map +1 -1
  118. package/lib/esm/config/index.js.map +1 -1
  119. package/lib/esm/constants.js +3 -47
  120. package/lib/esm/constants.js.map +1 -1
  121. package/lib/esm/containers/AsyncApi/AsyncApi.js +2 -0
  122. package/lib/esm/containers/AsyncApi/AsyncApi.js.map +1 -1
  123. package/lib/esm/containers/AsyncApi/Layout.js +28 -20
  124. package/lib/esm/containers/AsyncApi/Layout.js.map +1 -1
  125. package/lib/esm/containers/AsyncApi/Standalone.js +3 -1
  126. package/lib/esm/containers/AsyncApi/Standalone.js.map +1 -1
  127. package/lib/esm/containers/Error/Error.js +2 -2
  128. package/lib/esm/containers/Error/Error.js.map +1 -1
  129. package/lib/esm/containers/Info/Info.js +8 -8
  130. package/lib/esm/containers/Info/Info.js.map +1 -1
  131. package/lib/esm/containers/Messages/Message.js +21 -9
  132. package/lib/esm/containers/Messages/Message.js.map +1 -1
  133. package/lib/esm/containers/Messages/MessageExample.js +19 -13
  134. package/lib/esm/containers/Messages/MessageExample.js.map +1 -1
  135. package/lib/esm/containers/Messages/Messages.js +10 -7
  136. package/lib/esm/containers/Messages/Messages.js.map +1 -1
  137. package/lib/esm/containers/Operations/Operation.js +72 -38
  138. package/lib/esm/containers/Operations/Operation.js.map +1 -1
  139. package/lib/esm/containers/Operations/Operations.js +15 -13
  140. package/lib/esm/containers/Operations/Operations.js.map +1 -1
  141. package/lib/esm/containers/Schemas/Schema.js +14 -0
  142. package/lib/esm/containers/Schemas/Schema.js.map +1 -0
  143. package/lib/esm/containers/Schemas/Schemas.js +21 -0
  144. package/lib/esm/containers/Schemas/Schemas.js.map +1 -0
  145. package/lib/esm/containers/Servers/Security.js +143 -0
  146. package/lib/esm/containers/Servers/Security.js.map +1 -0
  147. package/lib/esm/containers/Servers/Server.js +15 -9
  148. package/lib/esm/containers/Servers/Server.js.map +1 -1
  149. package/lib/esm/containers/Servers/Servers.js +5 -3
  150. package/lib/esm/containers/Servers/Servers.js.map +1 -1
  151. package/lib/esm/containers/Sidebar/Sidebar.js +203 -135
  152. package/lib/esm/containers/Sidebar/Sidebar.js.map +1 -1
  153. package/lib/esm/contexts/index.js +1 -0
  154. package/lib/esm/contexts/index.js.map +1 -1
  155. package/lib/esm/contexts/useConfig.js +6 -0
  156. package/lib/esm/contexts/useConfig.js.map +1 -0
  157. package/lib/esm/contexts/useSpec.js +2 -2
  158. package/lib/esm/contexts/useSpec.js.map +1 -1
  159. package/lib/esm/helpers/common.js +14 -0
  160. package/lib/esm/helpers/common.js.map +1 -0
  161. package/lib/esm/helpers/index.js +2 -3
  162. package/lib/esm/helpers/index.js.map +1 -1
  163. package/lib/esm/helpers/marked.js +27 -0
  164. package/lib/esm/helpers/marked.js.map +1 -0
  165. package/lib/esm/helpers/message.js +38 -8
  166. package/lib/esm/helpers/message.js.map +1 -1
  167. package/lib/esm/helpers/parser.js +15 -13
  168. package/lib/esm/helpers/parser.js.map +1 -1
  169. package/lib/esm/helpers/schema.js +152 -127
  170. package/lib/esm/helpers/schema.js.map +1 -1
  171. package/lib/esm/helpers/server.js +49 -0
  172. package/lib/esm/helpers/server.js.map +1 -1
  173. package/lib/esm/helpers/specification.js +36 -18
  174. package/lib/esm/helpers/specification.js.map +1 -1
  175. package/lib/esm/index.js +2 -1
  176. package/lib/esm/index.js.map +1 -1
  177. package/lib/esm/types.js +2 -46
  178. package/lib/esm/types.js.map +1 -1
  179. package/lib/esm/without-parser.js +2 -0
  180. package/lib/esm/without-parser.js.map +1 -1
  181. package/lib/types/components/Bindings.d.ts.map +1 -1
  182. package/lib/types/components/CollapseButton.d.ts +1 -0
  183. package/lib/types/components/CollapseButton.d.ts.map +1 -1
  184. package/lib/types/components/Extensions.d.ts.map +1 -1
  185. package/lib/types/components/JSONSnippet.d.ts +7 -0
  186. package/lib/types/components/JSONSnippet.d.ts.map +1 -0
  187. package/lib/types/components/Markdown.d.ts.map +1 -1
  188. package/lib/types/components/Schema.d.ts +5 -4
  189. package/lib/types/components/Schema.d.ts.map +1 -1
  190. package/lib/types/components/Tag.d.ts +2 -2
  191. package/lib/types/components/Tag.d.ts.map +1 -1
  192. package/lib/types/components/Tags.d.ts +2 -2
  193. package/lib/types/components/Tags.d.ts.map +1 -1
  194. package/lib/types/components/index.d.ts +1 -1
  195. package/lib/types/components/index.d.ts.map +1 -1
  196. package/lib/types/config/config.d.ts +8 -0
  197. package/lib/types/config/config.d.ts.map +1 -1
  198. package/lib/types/config/default.d.ts.map +1 -1
  199. package/lib/types/constants.d.ts +3 -26
  200. package/lib/types/constants.d.ts.map +1 -1
  201. package/lib/types/containers/AsyncApi/AsyncApi.d.ts +2 -2
  202. package/lib/types/containers/AsyncApi/AsyncApi.d.ts.map +1 -1
  203. package/lib/types/containers/AsyncApi/Layout.d.ts +2 -2
  204. package/lib/types/containers/AsyncApi/Layout.d.ts.map +1 -1
  205. package/lib/types/containers/AsyncApi/Standalone.d.ts +2 -2
  206. package/lib/types/containers/AsyncApi/Standalone.d.ts.map +1 -1
  207. package/lib/types/containers/Info/Info.d.ts.map +1 -1
  208. package/lib/types/containers/Messages/Message.d.ts +3 -2
  209. package/lib/types/containers/Messages/Message.d.ts.map +1 -1
  210. package/lib/types/containers/Messages/MessageExample.d.ts +5 -4
  211. package/lib/types/containers/Messages/MessageExample.d.ts.map +1 -1
  212. package/lib/types/containers/Messages/Messages.d.ts.map +1 -1
  213. package/lib/types/containers/Operations/Operation.d.ts +4 -3
  214. package/lib/types/containers/Operations/Operation.d.ts.map +1 -1
  215. package/lib/types/containers/Operations/Operations.d.ts.map +1 -1
  216. package/lib/types/containers/Schemas/Schema.d.ts +9 -0
  217. package/lib/types/containers/Schemas/Schema.d.ts.map +1 -0
  218. package/lib/types/containers/Schemas/Schemas.d.ts +3 -0
  219. package/lib/types/containers/Schemas/Schemas.d.ts.map +1 -0
  220. package/lib/types/containers/Servers/Security.d.ts +10 -0
  221. package/lib/types/containers/Servers/Security.d.ts.map +1 -0
  222. package/lib/types/containers/Servers/Server.d.ts +2 -2
  223. package/lib/types/containers/Servers/Server.d.ts.map +1 -1
  224. package/lib/types/containers/Servers/Servers.d.ts.map +1 -1
  225. package/lib/types/containers/Sidebar/Sidebar.d.ts +1 -9
  226. package/lib/types/containers/Sidebar/Sidebar.d.ts.map +1 -1
  227. package/lib/types/contexts/index.d.ts +1 -0
  228. package/lib/types/contexts/index.d.ts.map +1 -1
  229. package/lib/types/contexts/useConfig.d.ts +5 -0
  230. package/lib/types/contexts/useConfig.d.ts.map +1 -0
  231. package/lib/types/contexts/useSpec.d.ts +3 -5
  232. package/lib/types/contexts/useSpec.d.ts.map +1 -1
  233. package/lib/types/helpers/common.d.ts +5 -0
  234. package/lib/types/helpers/common.d.ts.map +1 -0
  235. package/lib/types/helpers/index.d.ts +2 -3
  236. package/lib/types/helpers/index.d.ts.map +1 -1
  237. package/lib/types/helpers/marked.d.ts +4 -0
  238. package/lib/types/helpers/marked.d.ts.map +1 -0
  239. package/lib/types/helpers/message.d.ts +4 -3
  240. package/lib/types/helpers/message.d.ts.map +1 -1
  241. package/lib/types/helpers/parser.d.ts.map +1 -1
  242. package/lib/types/helpers/schema.d.ts +16 -12
  243. package/lib/types/helpers/schema.d.ts.map +1 -1
  244. package/lib/types/helpers/server.d.ts +6 -1
  245. package/lib/types/helpers/server.d.ts.map +1 -1
  246. package/lib/types/helpers/specification.d.ts +7 -4
  247. package/lib/types/helpers/specification.d.ts.map +1 -1
  248. package/lib/types/index.d.ts +2 -1
  249. package/lib/types/index.d.ts.map +1 -1
  250. package/lib/types/types.d.ts +12 -305
  251. package/lib/types/types.d.ts.map +1 -1
  252. package/lib/types/without-parser.d.ts +2 -0
  253. package/lib/types/without-parser.d.ts.map +1 -1
  254. package/package.json +43 -19
  255. package/styles/default.css +907 -642
  256. package/styles/default.min.css +4 -2
  257. package/lib/cjs/components/Code.js +0 -15
  258. package/lib/cjs/components/Code.js.map +0 -1
  259. package/lib/cjs/containers/Servers/ServerSecurity.js +0 -101
  260. package/lib/cjs/containers/Servers/ServerSecurity.js.map +0 -1
  261. package/lib/cjs/helpers/bemClasses.js +0 -49
  262. package/lib/cjs/helpers/bemClasses.js.map +0 -1
  263. package/lib/cjs/helpers/formatJsonHighlight.js +0 -61
  264. package/lib/cjs/helpers/formatJsonHighlight.js.map +0 -1
  265. package/lib/cjs/helpers/toKebabCase.js +0 -15
  266. package/lib/cjs/helpers/toKebabCase.js.map +0 -1
  267. package/lib/esm/components/Code.js +0 -9
  268. package/lib/esm/components/Code.js.map +0 -1
  269. package/lib/esm/containers/Servers/ServerSecurity.js +0 -95
  270. package/lib/esm/containers/Servers/ServerSecurity.js.map +0 -1
  271. package/lib/esm/helpers/bemClasses.js +0 -46
  272. package/lib/esm/helpers/bemClasses.js.map +0 -1
  273. package/lib/esm/helpers/formatJsonHighlight.js +0 -57
  274. package/lib/esm/helpers/formatJsonHighlight.js.map +0 -1
  275. package/lib/esm/helpers/toKebabCase.js +0 -11
  276. package/lib/esm/helpers/toKebabCase.js.map +0 -1
  277. package/lib/types/components/Code.d.ts +0 -7
  278. package/lib/types/components/Code.d.ts.map +0 -1
  279. package/lib/types/containers/Servers/ServerSecurity.d.ts +0 -8
  280. package/lib/types/containers/Servers/ServerSecurity.d.ts.map +0 -1
  281. package/lib/types/helpers/bemClasses.d.ts +0 -14
  282. package/lib/types/helpers/bemClasses.d.ts.map +0 -1
  283. package/lib/types/helpers/formatJsonHighlight.d.ts +0 -2
  284. package/lib/types/helpers/formatJsonHighlight.d.ts.map +0 -1
  285. package/lib/types/helpers/toKebabCase.d.ts +0 -2
  286. 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 }); });
47
77
  }
48
78
  return;
49
79
  };
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","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AAC;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"]}
@@ -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;wBACpD,WAAO,EAAE,QAAQ,UAAA,EAAE,EAAC;;;wBAEpB,WAAO,IAAI,CAAC,WAAW,CAAC,KAAG,CAAC,EAAC;;;;;KAEhC;IAEY,mBAAY,GAAzB,UACE,GAA4B,EAC5B,aAAmB;;;;;;;wBAGA,WAAM,YAAY,CACjC,GAAG,CAAC,GAAG,EACP,GAAG,CAAC,cAAc,EAClB,aAAa,CACd,EAAA;;wBAJK,QAAQ,GAAG,SAIhB;wBACD,WAAO,EAAE,QAAQ,UAAA,EAAE,EAAC;;;wBAEpB,WAAO,IAAI,CAAC,WAAW,CAAC,KAAG,CAAC,EAAC;;;;;KAEhC;IAEc,kBAAW,G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AAC,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,AAlCD,IAkCC;SAlCY,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(asyncapiParser, arg.url, arg.requestOptions);\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,69 @@
1
- import SchemaClass from '@asyncapi/parser/lib/models/schema';
1
+ import { SchemaV2 as SchemaClass, } from '@asyncapi/parser';
2
+ export var SchemaCustomTypes;
3
+ (function (SchemaCustomTypes) {
4
+ SchemaCustomTypes["ANY"] = "any";
5
+ SchemaCustomTypes["RESTRICTED_ANY"] = "restricted any";
6
+ SchemaCustomTypes["NEVER"] = "never";
7
+ SchemaCustomTypes["UNKNOWN"] = "unknown";
8
+ })(SchemaCustomTypes || (SchemaCustomTypes = {}));
9
+ var jsonSchemaTypes = [
10
+ 'string',
11
+ 'number',
12
+ 'integer',
13
+ 'boolean',
14
+ 'array',
15
+ 'object',
16
+ 'null',
17
+ ];
18
+ var jsonSchemaKeywordTypes = {
19
+ maxLength: 'string',
20
+ minLength: 'string',
21
+ pattern: 'string',
22
+ contentMediaType: 'string',
23
+ contentEncoding: 'string',
24
+ multipleOf: 'number',
25
+ maximum: 'number',
26
+ exclusiveMaximum: 'number',
27
+ minimum: 'number',
28
+ exclusiveMinimum: 'number',
29
+ items: 'array',
30
+ maxItems: 'array',
31
+ minItems: 'array',
32
+ uniqueItems: 'array',
33
+ contains: 'array',
34
+ additionalItems: 'array',
35
+ maxProperties: 'object',
36
+ minProperties: 'object',
37
+ required: 'object',
38
+ properties: 'object',
39
+ patternProperties: 'object',
40
+ propertyNames: 'object',
41
+ dependencies: 'object',
42
+ additionalProperties: 'object',
43
+ };
44
+ var jsonSchemaKeywords = Object.keys(jsonSchemaKeywordTypes);
2
45
  var SchemaHelpers = (function () {
3
46
  function SchemaHelpers() {
4
47
  }
5
48
  SchemaHelpers.toSchemaType = function (schema) {
6
49
  var _this = this;
7
- if (schema === true) {
8
- return 'any';
50
+ if (!schema || typeof schema.json !== 'function') {
51
+ return SchemaCustomTypes.UNKNOWN;
9
52
  }
10
- if (schema === false) {
11
- return 'never';
53
+ if (schema.isBooleanSchema()) {
54
+ if (schema.json() === true) {
55
+ return SchemaCustomTypes.ANY;
56
+ }
57
+ else {
58
+ return SchemaCustomTypes.NEVER;
59
+ }
12
60
  }
13
61
  if (Object.keys(schema.json()).length === 0) {
14
- return 'any';
62
+ return SchemaCustomTypes.ANY;
63
+ }
64
+ var not = schema.not();
65
+ if (not && this.inferType(not) === SchemaCustomTypes.ANY) {
66
+ return SchemaCustomTypes.NEVER;
15
67
  }
16
68
  var type = this.inferType(schema);
17
69
  if (Array.isArray(type)) {
@@ -20,23 +72,24 @@ var SchemaHelpers = (function () {
20
72
  type = this.toType(type, schema);
21
73
  var combinedType = this.toCombinedType(schema);
22
74
  if (type && combinedType) {
23
- return type + " " + combinedType;
75
+ return "".concat(type, " ").concat(combinedType);
24
76
  }
25
77
  if (combinedType) {
26
78
  return combinedType;
27
79
  }
28
80
  return type;
29
81
  };
30
- SchemaHelpers.prettifyValue = function (value) {
82
+ SchemaHelpers.prettifyValue = function (value, strict) {
83
+ if (strict === void 0) { strict = true; }
31
84
  var typeOf = typeof value;
32
85
  if (typeOf === 'string') {
33
- return "\"" + value + "\"";
86
+ return strict ? "\"".concat(value, "\"") : value;
34
87
  }
35
88
  if (typeOf === 'number' || typeOf === 'bigint' || typeOf === 'boolean') {
36
- return value;
89
+ return "".concat(value);
37
90
  }
38
91
  if (Array.isArray(value)) {
39
- return "[" + value.toString() + "]";
92
+ return "[".concat(value.toString(), "]");
40
93
  }
41
94
  return JSON.stringify(value);
42
95
  };
@@ -74,6 +127,8 @@ var SchemaHelpers = (function () {
74
127
  if (schema.oneOf() ||
75
128
  schema.anyOf() ||
76
129
  schema.allOf() ||
130
+ Object.keys(schema.properties() || {}).length > 0 ||
131
+ schema.items() ||
77
132
  schema.not() ||
78
133
  schema.if() ||
79
134
  schema.then() ||
@@ -94,14 +149,13 @@ var SchemaHelpers = (function () {
94
149
  var json = (_a = {
95
150
  type: 'object',
96
151
  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';
152
+ var variableName = _a[0], variable = _a[1];
153
+ obj[variableName] = Object.assign({}, variable.json() || {});
154
+ obj[variableName].type = 'string';
100
155
  return obj;
101
156
  }, {}),
102
157
  required: Object.keys(urlVariables)
103
158
  },
104
- _a[this.extRenderType] = false,
105
159
  _a[this.extRenderAdditionalInfo] = false,
106
160
  _a);
107
161
  return new SchemaClass(json);
@@ -116,7 +170,8 @@ var SchemaHelpers = (function () {
116
170
  type: 'object',
117
171
  properties: Object.entries(parameters).reduce(function (obj, _a) {
118
172
  var paramaterName = _a[0], parameter = _a[1];
119
- obj[paramaterName] = Object.assign({}, parameter.schema().json());
173
+ var parameterSchema = parameter.schema();
174
+ obj[paramaterName] = Object.assign({}, parameterSchema ? parameterSchema.json() : {});
120
175
  obj[paramaterName].description =
121
176
  parameter.description() || obj[paramaterName].description;
122
177
  obj[paramaterName][_this.extParameterLocation] = parameter.location();
@@ -124,7 +179,6 @@ var SchemaHelpers = (function () {
124
179
  }, {}),
125
180
  required: Object.keys(parameters)
126
181
  },
127
- _a[this.extRenderType] = false,
128
182
  _a[this.extRenderAdditionalInfo] = false,
129
183
  _a);
130
184
  return new SchemaClass(json);
@@ -137,14 +191,17 @@ var SchemaHelpers = (function () {
137
191
  if (!value || typeof value.extensions !== 'function') {
138
192
  return;
139
193
  }
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;
194
+ var extensions = value.extensions();
195
+ var filteredExtensions = {};
196
+ for (var _i = 0, _a = Object.values(extensions.all()); _i < _a.length; _i++) {
197
+ var ext = _a[_i];
198
+ var extType = ext;
199
+ if (!extType.id().startsWith('x-parser-') &&
200
+ !extType.id().startsWith('x-schema-private-')) {
201
+ filteredExtensions[extType.id()] = extType.value();
145
202
  }
146
- return obj;
147
- }, {});
203
+ }
204
+ return filteredExtensions;
148
205
  };
149
206
  SchemaHelpers.getDependentRequired = function (propertyName, schema) {
150
207
  var dependentRequired = [];
@@ -184,30 +241,42 @@ var SchemaHelpers = (function () {
184
241
  return obj;
185
242
  }, {})
186
243
  },
187
- _a[this.extRenderType] = false,
188
244
  _a[this.extRenderAdditionalInfo] = false,
189
245
  _a);
190
246
  return new SchemaClass(json);
191
247
  };
192
248
  SchemaHelpers.toType = function (type, schema) {
193
- var _this = this;
249
+ if (schema.isCircular()) {
250
+ return type;
251
+ }
194
252
  if (type === 'array') {
195
253
  var items = schema.items();
196
- var types = void 0;
197
254
  if (Array.isArray(items)) {
198
- types = items.map(function (item) { return _this.toSchemaType(item); }).join(', ');
199
- types = types.length ? types : 'unknown';
255
+ return this.toItemsType(items, schema);
200
256
  }
201
- else if (items) {
202
- types = this.toSchemaType(items);
203
- types = types || 'unknown';
257
+ if (!items) {
258
+ return "array<".concat(SchemaCustomTypes.ANY, ">");
204
259
  }
205
- return "array<" + types + ">";
260
+ return "array<".concat(this.toSchemaType(items) || SchemaCustomTypes.UNKNOWN, ">");
206
261
  }
207
262
  return type;
208
263
  };
264
+ SchemaHelpers.toItemsType = function (items, schema) {
265
+ var _this = this;
266
+ var types = items.map(function (item) { return _this.toSchemaType(item); }).join(', ');
267
+ var additionalItems = schema.additionalItems();
268
+ if (additionalItems !== undefined && additionalItems !== false) {
269
+ var additionalType = additionalItems === true
270
+ ? SchemaCustomTypes.ANY
271
+ : this.toSchemaType(additionalItems);
272
+ return "tuple<".concat(types ||
273
+ SchemaCustomTypes.UNKNOWN, ", ...optional<").concat(additionalType, ">>");
274
+ }
275
+ return "tuple<".concat(types || SchemaCustomTypes.UNKNOWN, ">");
276
+ };
209
277
  SchemaHelpers.toCombinedType = function (schema) {
210
- if (schema.oneOf()) {
278
+ var oneOf = schema.oneOf();
279
+ if (oneOf) {
211
280
  return 'oneOf';
212
281
  }
213
282
  if (schema.anyOf()) {
@@ -219,49 +288,36 @@ var SchemaHelpers = (function () {
219
288
  return;
220
289
  };
221
290
  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;
291
+ var types = schema.type();
292
+ if (types !== undefined) {
293
+ if (Array.isArray(types)) {
294
+ if (types.includes('integer') && types.includes('number')) {
295
+ types = types.filter(function (t) { return t !== 'integer'; });
231
296
  }
297
+ return types.length === 1 ? types[0] : types;
232
298
  }
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
- }
242
- }
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
- }
299
+ return types;
248
300
  }
249
- var types = Object.keys(possibleTypes);
250
- if (types.length === 1) {
251
- return types[0];
301
+ var constValue = schema.const();
302
+ if (constValue !== undefined) {
303
+ return typeof constValue;
252
304
  }
253
- if (jsonTypes === 'integer') {
254
- return types.filter(function (t) { return t !== 'number'; });
305
+ var enumValue = schema.enum();
306
+ if (Array.isArray(enumValue) && enumValue.length) {
307
+ var inferredType = Array.from(new Set(enumValue.map(function (e) { return typeof e; })));
308
+ return inferredType.length === 1 ? inferredType[0] : inferredType;
255
309
  }
256
- if (Array.isArray(jsonTypes) &&
257
- jsonTypes.includes('integer') &&
258
- !jsonTypes.includes('number')) {
259
- return types.filter(function (t) { return t !== 'number'; });
310
+ var schemaKeys = Object.keys(schema.json() || {}) || [];
311
+ var hasInferredTypes = jsonSchemaKeywords.some(function (key) {
312
+ return schemaKeys.includes(key);
313
+ });
314
+ if (hasInferredTypes === true) {
315
+ return SchemaCustomTypes.RESTRICTED_ANY;
260
316
  }
261
- if (types.includes('integer') && types.includes('number')) {
262
- return types.filter(function (t) { return t !== 'integer'; });
317
+ if (this.toCombinedType(schema)) {
318
+ return '';
263
319
  }
264
- return types;
320
+ return SchemaCustomTypes.ANY;
265
321
  };
266
322
  SchemaHelpers.humanizeNumberRangeConstraint = function (min, exclusiveMin, max, exclusiveMax) {
267
323
  var hasExclusiveMin = exclusiveMin !== undefined;
@@ -292,58 +348,65 @@ var SchemaHelpers = (function () {
292
348
  }
293
349
  var strigifiedMultipleOf = multipleOf.toString(10);
294
350
  if (!/^0\.0*1$/.test(strigifiedMultipleOf)) {
295
- return "multiple of " + strigifiedMultipleOf;
351
+ return "multiple of ".concat(strigifiedMultipleOf);
296
352
  }
297
- return "decimal places <= " + strigifiedMultipleOf.split('.')[1].length;
353
+ return "decimal places <= ".concat(strigifiedMultipleOf.split('.')[1].length);
298
354
  };
299
355
  SchemaHelpers.humanizeRangeConstraint = function (description, min, max) {
300
356
  var stringRange;
301
357
  if (min !== undefined && max !== undefined) {
302
358
  if (min === max) {
303
- stringRange = min + " " + description;
359
+ stringRange = "".concat(min, " ").concat(description);
304
360
  }
305
361
  else {
306
- stringRange = "[ " + min + " .. " + max + " ] " + description;
362
+ stringRange = "[ ".concat(min, " .. ").concat(max, " ] ").concat(description);
307
363
  }
308
364
  }
309
365
  else if (max !== undefined) {
310
- stringRange = "<= " + max + " " + description;
366
+ stringRange = "<= ".concat(max, " ").concat(description);
311
367
  }
312
368
  else if (min !== undefined) {
313
369
  if (min === 1) {
314
370
  stringRange = 'non-empty';
315
371
  }
316
372
  else {
317
- stringRange = ">= " + min + " " + description;
373
+ stringRange = ">= ".concat(min, " ").concat(description);
318
374
  }
319
375
  }
320
376
  return stringRange;
321
377
  };
322
378
  SchemaHelpers.jsonFieldToSchema = function (value) {
323
- var _a, _b, _c;
379
+ var _a, _b, _c, _d;
324
380
  var _this = this;
325
- if (typeof value !== 'object') {
326
- var str = typeof value.toString === 'function' ? value.toString() : value;
381
+ if (value === undefined || value === null) {
327
382
  return _a = {
328
383
  type: 'string',
329
- const: str
384
+ const: ''
330
385
  },
331
386
  _a[this.extRawValue] = true,
332
387
  _a;
333
388
  }
389
+ if (typeof value !== 'object') {
390
+ var str = typeof value.toString === 'function' ? value.toString() : value;
391
+ return _b = {
392
+ type: 'string',
393
+ const: str
394
+ },
395
+ _b[this.extRawValue] = true,
396
+ _b;
397
+ }
334
398
  if (this.isJSONSchema(value)) {
335
399
  return value;
336
400
  }
337
401
  if (Array.isArray(value)) {
338
- return _b = {
402
+ return _c = {
339
403
  type: 'array',
340
404
  items: value.map(function (v) { return _this.jsonFieldToSchema(v); })
341
405
  },
342
- _b[this.extRenderType] = false,
343
- _b[this.extRenderAdditionalInfo] = false,
344
- _b;
406
+ _c[this.extRenderAdditionalInfo] = false,
407
+ _c;
345
408
  }
346
- return _c = {
409
+ return _d = {
347
410
  type: 'object',
348
411
  properties: Object.entries(value).reduce(function (obj, _a) {
349
412
  var k = _a[0], v = _a[1];
@@ -351,60 +414,22 @@ var SchemaHelpers = (function () {
351
414
  return obj;
352
415
  }, {})
353
416
  },
354
- _c[this.extRenderType] = false,
355
- _c[this.extRenderAdditionalInfo] = false,
356
- _c;
417
+ _d[this.extRenderAdditionalInfo] = false,
418
+ _d;
357
419
  };
358
420
  SchemaHelpers.isJSONSchema = function (value) {
359
- var _this = this;
360
421
  if (value &&
361
422
  typeof value === 'object' &&
362
- (this.jsonSchemaTypes.includes(value.type) ||
423
+ (jsonSchemaTypes.includes(value.type) ||
363
424
  (Array.isArray(value.type) &&
364
- value.type.some(function (t) { return !_this.jsonSchemaTypes.includes(t); })))) {
425
+ value.type.some(function (t) { return !jsonSchemaTypes.includes(t); })))) {
365
426
  return true;
366
427
  }
367
428
  return false;
368
429
  };
369
- SchemaHelpers.extRenderType = 'x-schema-private-render-type';
370
430
  SchemaHelpers.extRenderAdditionalInfo = 'x-schema-private-render-additional-info';
371
431
  SchemaHelpers.extRawValue = 'x-schema-private-raw-value';
372
432
  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
433
  return SchemaHelpers;
409
434
  }());
410
435
  export { SchemaHelpers };