@adobe/jsonschema2md 6.1.1 → 7.0.0

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 (294) hide show
  1. package/{.eslintrc.js → .eslintrc.cjs} +3 -17
  2. package/{.releaserc.js → .releaserc.cjs} +0 -0
  3. package/CHANGELOG.md +47 -0
  4. package/cli.js +1 -1
  5. package/lib/formatInfo.js +17 -19
  6. package/lib/formattingTools.js +6 -8
  7. package/lib/index.js +176 -81
  8. package/lib/keywords.js +2 -4
  9. package/lib/locales/update.js +2 -2
  10. package/lib/markdownBuilder.js +62 -44
  11. package/lib/readmeBuilder.js +13 -12
  12. package/lib/schemaProxy.js +32 -26
  13. package/lib/symbols.js +14 -2
  14. package/lib/traverseSchema.js +5 -5
  15. package/lib/writeMarkdown.js +87 -41
  16. package/lib/writeSchema.js +46 -21
  17. package/package.json +40 -29
  18. package/types/api.d.ts +72 -0
  19. package/types/formatInfo.d.ts +19 -0
  20. package/types/formattingTools.d.ts +2 -0
  21. package/types/index.d.ts +75 -0
  22. package/types/keywords.d.ts +2 -0
  23. package/types/markdownBuilder.d.ts +8 -0
  24. package/types/readmeBuilder.d.ts +5 -0
  25. package/types/schemaProxy.d.ts +1 -0
  26. package/types/symbols.d.ts +11 -0
  27. package/types/traverseSchema.d.ts +6 -0
  28. package/types/writeMarkdown.d.ts +56 -0
  29. package/types/writeSchema.d.ts +19 -0
  30. package/.circleci/config.yml +0 -83
  31. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -23
  32. package/.github/workflows/semantic-release.yaml +0 -55
  33. package/.github/workflows/semver-check.yaml +0 -16
  34. package/.renovaterc.json +0 -3
  35. package/.tidelift.yml +0 -32
  36. package/crowdin.yml +0 -4
  37. package/examples/abstract.md +0 -3
  38. package/examples/docs/README.md +0 -121
  39. package/examples/docs/abstract-definitions-first-properties-foo.md +0 -15
  40. package/examples/docs/abstract-definitions-first-properties-nonfoo.md +0 -23
  41. package/examples/docs/abstract-definitions-first.md +0 -66
  42. package/examples/docs/abstract-definitions-second-properties-bar.md +0 -15
  43. package/examples/docs/abstract-definitions-second.md +0 -39
  44. package/examples/docs/abstract-definitions.md +0 -15
  45. package/examples/docs/abstract.md +0 -104
  46. package/examples/docs/arrays-properties-boollist-items.md +0 -15
  47. package/examples/docs/arrays-properties-boollist.md +0 -19
  48. package/examples/docs/arrays-properties-coordinatelist-items-items.md +0 -21
  49. package/examples/docs/arrays-properties-coordinatelist-items.md +0 -21
  50. package/examples/docs/arrays-properties-coordinatelist.md +0 -19
  51. package/examples/docs/arrays-properties-intlist-items.md +0 -15
  52. package/examples/docs/arrays-properties-intlist.md +0 -21
  53. package/examples/docs/arrays-properties-jointypelist-items-oneof-0-properties-foo.md +0 -21
  54. package/examples/docs/arrays-properties-jointypelist-items-oneof-0.md +0 -45
  55. package/examples/docs/arrays-properties-jointypelist-items-oneof-1-properties-bar.md +0 -21
  56. package/examples/docs/arrays-properties-jointypelist-items-oneof-1.md +0 -45
  57. package/examples/docs/arrays-properties-jointypelist-items.md +0 -21
  58. package/examples/docs/arrays-properties-jointypelist.md +0 -15
  59. package/examples/docs/arrays-properties-list-items.md +0 -15
  60. package/examples/docs/arrays-properties-list.md +0 -15
  61. package/examples/docs/arrays-properties-listlist-items.md +0 -15
  62. package/examples/docs/arrays-properties-listlist.md +0 -15
  63. package/examples/docs/arrays-properties-numlist-items.md +0 -19
  64. package/examples/docs/arrays-properties-numlist.md +0 -19
  65. package/examples/docs/arrays-properties-objectlist-items-properties-a.md +0 -15
  66. package/examples/docs/arrays-properties-objectlist-items-properties-b.md +0 -15
  67. package/examples/docs/arrays-properties-objectlist-items.md +0 -58
  68. package/examples/docs/arrays-properties-objectlist.md +0 -15
  69. package/examples/docs/arrays-properties-stringlistlist-items-items.md +0 -15
  70. package/examples/docs/arrays-properties-stringlistlist-items.md +0 -15
  71. package/examples/docs/arrays-properties-stringlistlist.md +0 -15
  72. package/examples/docs/arrays-properties-tuple-items-negative-integer.md +0 -19
  73. package/examples/docs/arrays-properties-tuple-items-positive-integer.md +0 -19
  74. package/examples/docs/arrays-properties-tuple-zero.md +0 -23
  75. package/examples/docs/arrays-properties-tuple.md +0 -21
  76. package/examples/docs/arrays.md +0 -240
  77. package/examples/docs/complex-additionalproperties.md +0 -15
  78. package/examples/docs/complex-patternproperties-int.md +0 -15
  79. package/examples/docs/complex-patternproperties-str.md +0 -15
  80. package/examples/docs/complex-patternproperties.md +0 -15
  81. package/examples/docs/complex-properties-and-allof-0.md +0 -19
  82. package/examples/docs/complex-properties-and-allof-1.md +0 -19
  83. package/examples/docs/complex-properties-and.md +0 -21
  84. package/examples/docs/complex-properties-or-anyof-0.md +0 -15
  85. package/examples/docs/complex-properties-or-anyof-1.md +0 -19
  86. package/examples/docs/complex-properties-or.md +0 -21
  87. package/examples/docs/complex-properties-reflocalfiledef.md +0 -39
  88. package/examples/docs/complex-properties-refnestedobj-properties-refobj.md +0 -39
  89. package/examples/docs/complex-properties-refnestedobj.md +0 -39
  90. package/examples/docs/complex-properties-refobj.md +0 -39
  91. package/examples/docs/complex-properties-xor-oneof-0.md +0 -19
  92. package/examples/docs/complex-properties-xor-oneof-1.md +0 -19
  93. package/examples/docs/complex-properties-xor.md +0 -21
  94. package/examples/docs/complex.md +0 -285
  95. package/examples/docs/constants-properties-hello.md +0 -23
  96. package/examples/docs/constants.md +0 -47
  97. package/examples/docs/custom-allof-0.md +0 -15
  98. package/examples/docs/custom-allof-1.md +0 -39
  99. package/examples/docs/custom-allof-2.md +0 -39
  100. package/examples/docs/custom-definitions-first-properties-foo.md +0 -15
  101. package/examples/docs/custom-definitions-first-properties.md +0 -15
  102. package/examples/docs/custom-definitions-first.md +0 -39
  103. package/examples/docs/custom-definitions-second-properties-bar.md +0 -15
  104. package/examples/docs/custom-definitions-second-properties.md +0 -15
  105. package/examples/docs/custom-definitions-second.md +0 -39
  106. package/examples/docs/custom-definitions.md +0 -15
  107. package/examples/docs/custom.md +0 -85
  108. package/examples/docs/deepextending-allof-0.md +0 -49
  109. package/examples/docs/deepextending-allof-1.md +0 -89
  110. package/examples/docs/deepextending-allof-3.md +0 -39
  111. package/examples/docs/deepextending-definitions-fourth-properties-hey.md +0 -15
  112. package/examples/docs/deepextending-definitions-fourth-properties.md +0 -15
  113. package/examples/docs/deepextending-definitions-fourth.md +0 -39
  114. package/examples/docs/deepextending-definitions.md +0 -15
  115. package/examples/docs/deepextending.md +0 -57
  116. package/examples/docs/definitions-definitions-myid-properties-id-1.md +0 -19
  117. package/examples/docs/definitions-definitions-myid-properties-id.md +0 -19
  118. package/examples/docs/definitions-definitions-myid-properties-metaid.md +0 -19
  119. package/examples/docs/definitions-definitions-myid-properties.md +0 -15
  120. package/examples/docs/definitions-definitions-myid.md +0 -89
  121. package/examples/docs/definitions-definitions.md +0 -15
  122. package/examples/docs/definitions.md +0 -117
  123. package/examples/docs/enums-properties-enumerated-nested-properties-test.md +0 -25
  124. package/examples/docs/enums-properties-enumerated-nested.md +0 -49
  125. package/examples/docs/enums-properties-hello.md +0 -24
  126. package/examples/docs/enums.md +0 -67
  127. package/examples/docs/example-properties-bar.md +0 -25
  128. package/examples/docs/example-properties-foo.md +0 -21
  129. package/examples/docs/example.md +0 -83
  130. package/examples/docs/examples-properties-bar.md +0 -25
  131. package/examples/docs/examples-properties-foo.md +0 -21
  132. package/examples/docs/examples.md +0 -90
  133. package/examples/docs/extending-definitions-third-properties-baaaz.md +0 -21
  134. package/examples/docs/extending-definitions-third.md +0 -45
  135. package/examples/docs/extending-definitions.md +0 -15
  136. package/examples/docs/extending.md +0 -61
  137. package/examples/docs/extensible-definitions-first-properties-foo.md +0 -21
  138. package/examples/docs/extensible-definitions-first-properties.md +0 -15
  139. package/examples/docs/extensible-definitions-first.md +0 -45
  140. package/examples/docs/extensible-definitions-second-properties-bar.md +0 -25
  141. package/examples/docs/extensible-definitions-second-properties.md +0 -15
  142. package/examples/docs/extensible-definitions-second.md +0 -49
  143. package/examples/docs/extensible-definitions.md +0 -15
  144. package/examples/docs/extensible.md +0 -93
  145. package/examples/docs/identifiable-properties-id.md +0 -19
  146. package/examples/docs/identifiable.md +0 -43
  147. package/examples/docs/join-oneof-0-not-oneof-0-properties-foo.md +0 -21
  148. package/examples/docs/join-oneof-0-not-oneof-0.md +0 -45
  149. package/examples/docs/join-oneof-0-not-oneof-1-properties-bar.md +0 -21
  150. package/examples/docs/join-oneof-0-not-oneof-1.md +0 -45
  151. package/examples/docs/join-oneof-0-not.md +0 -21
  152. package/examples/docs/join-oneof-0.md +0 -23
  153. package/examples/docs/join-oneof-1-allof-0-properties-foo.md +0 -21
  154. package/examples/docs/join-oneof-1-allof-0.md +0 -45
  155. package/examples/docs/join-oneof-1.md +0 -19
  156. package/examples/docs/join-oneof-2-anyof-0-properties-bar.md +0 -21
  157. package/examples/docs/join-oneof-2-anyof-0.md +0 -45
  158. package/examples/docs/join-oneof-2.md +0 -19
  159. package/examples/docs/join.md +0 -33
  160. package/examples/docs/nestedobj-properties-settings-properties-collaborators-patternproperties-.md +0 -15
  161. package/examples/docs/nestedobj-properties-settings-properties-collaborators-patternproperties.md +0 -15
  162. package/examples/docs/nestedobj-properties-settings-properties-collaborators-properties-id.md +0 -15
  163. package/examples/docs/nestedobj-properties-settings-properties-collaborators.md +0 -58
  164. package/examples/docs/nestedobj-properties-settings.md +0 -39
  165. package/examples/docs/nestedobj.md +0 -39
  166. package/examples/docs/pattern-patternproperties-0-9.md +0 -21
  167. package/examples/docs/pattern-patternproperties.md +0 -15
  168. package/examples/docs/pattern.md +0 -45
  169. package/examples/docs/simple-properties-id.md +0 -19
  170. package/examples/docs/simple.md +0 -43
  171. package/examples/docs/simpletypes-properties-integer_threes.md +0 -23
  172. package/examples/docs/simpletypes-properties-interger_constrained.md +0 -19
  173. package/examples/docs/simpletypes-properties-interger_unconstrained.md +0 -15
  174. package/examples/docs/simpletypes-properties-number_constrained.md +0 -19
  175. package/examples/docs/simpletypes-properties-number_unconstrained.md +0 -15
  176. package/examples/docs/simpletypes-properties-string_date.md +0 -19
  177. package/examples/docs/simpletypes-properties-string_email.md +0 -19
  178. package/examples/docs/simpletypes-properties-string_hostname.md +0 -19
  179. package/examples/docs/simpletypes-properties-string_ipv4.md +0 -19
  180. package/examples/docs/simpletypes-properties-string_ipv6.md +0 -19
  181. package/examples/docs/simpletypes-properties-string_length.md +0 -31
  182. package/examples/docs/simpletypes-properties-string_pattern-metaenum.md +0 -15
  183. package/examples/docs/simpletypes-properties-string_pattern.md +0 -39
  184. package/examples/docs/simpletypes-properties-string_pattern_noexample.md +0 -25
  185. package/examples/docs/simpletypes-properties-string_pattern_singleexample.md +0 -31
  186. package/examples/docs/simpletypes-properties-string_unconstrained.md +0 -21
  187. package/examples/docs/simpletypes-properties-string_uri.md +0 -19
  188. package/examples/docs/simpletypes-properties-yesno.md +0 -15
  189. package/examples/docs/simpletypes.md +0 -455
  190. package/examples/docs/stabilizing-properties-id.md +0 -19
  191. package/examples/docs/stabilizing.md +0 -43
  192. package/examples/docs/subdir-allof-0.md +0 -43
  193. package/examples/docs/subdir-definitions-content-properties-id.md +0 -19
  194. package/examples/docs/subdir-definitions-content-properties.md +0 -15
  195. package/examples/docs/subdir-definitions-content.md +0 -43
  196. package/examples/docs/subdir-definitions.md +0 -15
  197. package/examples/docs/subdir.md +0 -55
  198. package/examples/docs/typearrays-properties-null.md +0 -15
  199. package/examples/docs/typearrays-properties-string-or-null.md +0 -15
  200. package/examples/docs/typearrays-properties-string-or-number-null.md +0 -15
  201. package/examples/docs/typearrays-properties-string-or-number.md +0 -15
  202. package/examples/docs/typearrays.md +0 -96
  203. package/examples/docsWithoutHeader/arrays.schema.md +0 -254
  204. package/examples/generated-schemas/abstract.schema.json +0 -1
  205. package/examples/generated-schemas/arrays.schema.json +0 -1
  206. package/examples/generated-schemas/complex.schema.json +0 -1
  207. package/examples/generated-schemas/constants.schema.json +0 -1
  208. package/examples/generated-schemas/custom.schema.json +0 -1
  209. package/examples/generated-schemas/deepextending.schema.json +0 -1
  210. package/examples/generated-schemas/definitions.schema.json +0 -1
  211. package/examples/generated-schemas/enums.schema.json +0 -1
  212. package/examples/generated-schemas/example.schema.json +0 -1
  213. package/examples/generated-schemas/examples.schema.json +0 -1
  214. package/examples/generated-schemas/extending.schema.json +0 -1
  215. package/examples/generated-schemas/extensible.schema.json +0 -1
  216. package/examples/generated-schemas/identifiable.schema.json +0 -1
  217. package/examples/generated-schemas/join.schema.json +0 -1
  218. package/examples/generated-schemas/nestedobj.schema.json +0 -1
  219. package/examples/generated-schemas/pattern.schema.json +0 -1
  220. package/examples/generated-schemas/simple.schema.json +0 -1
  221. package/examples/generated-schemas/simpletypes.schema.json +0 -1
  222. package/examples/generated-schemas/stabilizing.schema.json +0 -1
  223. package/examples/generated-schemas/subdir/subdir.schema.json +0 -1
  224. package/examples/generated-schemas/typearrays.schema.json +0 -1
  225. package/examples/schemas/abstract.schema.json +0 -44
  226. package/examples/schemas/arrays.schema.json +0 -185
  227. package/examples/schemas/complex.schema.json +0 -123
  228. package/examples/schemas/constants.schema.json +0 -25
  229. package/examples/schemas/custom.schema.json +0 -41
  230. package/examples/schemas/deepextending.schema.json +0 -37
  231. package/examples/schemas/definitions.description.md +0 -17
  232. package/examples/schemas/definitions.schema.json +0 -46
  233. package/examples/schemas/enums.schema.json +0 -42
  234. package/examples/schemas/example.example.1.json +0 -4
  235. package/examples/schemas/example.schema.json +0 -29
  236. package/examples/schemas/examples.example.1.json +0 -4
  237. package/examples/schemas/examples.example.2.json +0 -4
  238. package/examples/schemas/examples.schema.json +0 -32
  239. package/examples/schemas/extending.schema.json +0 -38
  240. package/examples/schemas/extensible.schema.json +0 -38
  241. package/examples/schemas/identifiable.schema.json +0 -22
  242. package/examples/schemas/join.schema.json +0 -88
  243. package/examples/schemas/nestedobj.schema.json +0 -35
  244. package/examples/schemas/pattern.schema.json +0 -21
  245. package/examples/schemas/simple.schema.json +0 -22
  246. package/examples/schemas/simpletypes.schema.json +0 -151
  247. package/examples/schemas/stabilizing.schema.json +0 -23
  248. package/examples/schemas/subdir/subdir.schema.json +0 -29
  249. package/examples/schemas/typearrays.schema.json +0 -39
  250. package/examples/status.md +0 -3
  251. package/test/api.test.js +0 -55
  252. package/test/cyclicSchemaIntegration.test.js +0 -87
  253. package/test/fixtures/additionalprops/additionalprops.schema.json +0 -6
  254. package/test/fixtures/additionalprops/arrays.schema.json +0 -9
  255. package/test/fixtures/arrays/arrays.schema.json +0 -201
  256. package/test/fixtures/arrays/tuple.schema.json +0 -35
  257. package/test/fixtures/content/html.schema.json +0 -5
  258. package/test/fixtures/content/jwt.schema.json +0 -26
  259. package/test/fixtures/content/png.schema.json +0 -6
  260. package/test/fixtures/cyclic/one.description.md +0 -1
  261. package/test/fixtures/cyclic/one.example.1.json +0 -1
  262. package/test/fixtures/cyclic/one.schema.json +0 -17
  263. package/test/fixtures/cyclic/three.schema.json +0 -17
  264. package/test/fixtures/cyclic/two.schema.json +0 -17
  265. package/test/fixtures/deadref/deadref.schema.json +0 -6
  266. package/test/fixtures/enums/arrayenums.schema.json +0 -29
  267. package/test/fixtures/enums/enums.schema.json +0 -29
  268. package/test/fixtures/example/example.schema.json +0 -52
  269. package/test/fixtures/format/format.schema.json +0 -25
  270. package/test/fixtures/identifiable/identifiable.schema.json +0 -22
  271. package/test/fixtures/not/not.schema.json +0 -7
  272. package/test/fixtures/null/null.schema.json +0 -14
  273. package/test/fixtures/nullable/array.schema.json +0 -17
  274. package/test/fixtures/readme-1/abstract.schema.json +0 -50
  275. package/test/fixtures/readme-1/complex.schema.json +0 -107
  276. package/test/fixtures/readme-1/simple.schema.json +0 -30
  277. package/test/fixtures/skipproperties/complete.schema.json +0 -29
  278. package/test/fixtures/stringformats/simpletypes.schema.json +0 -211
  279. package/test/fixtures/title/meta.schema.json +0 -53
  280. package/test/fixtures/type/button.schema.json +0 -28
  281. package/test/fixtures/type/type.schema.json +0 -20
  282. package/test/fixtures/types/merged.schema.json +0 -10
  283. package/test/fixtures/types/object.schema.json +0 -3
  284. package/test/fixtures/types/objectorarray.schema.json +0 -3
  285. package/test/fixtures/types/undefined.schema.json +0 -3
  286. package/test/fixtures/types/wrong.schema.json +0 -6
  287. package/test/formatting.test.js +0 -59
  288. package/test/markdownBuilder.test.js +0 -441
  289. package/test/readmeBuilder.test.js +0 -105
  290. package/test/schemaProxy.test.js +0 -187
  291. package/test/testUtils.js +0 -88
  292. package/test/testintegration.test.js +0 -65
  293. package/test/traverseSchema.test.js +0 -111
  294. package/test/zSchemaCoverage.test.js +0 -186
@@ -9,22 +9,35 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const {
13
- map, list: flist, flat, filter, size, foldl,
14
- } = require('ferrum');
15
- const {
16
- root, paragraph, text, heading, code, table,
17
- tableRow, tableCell, link, inlineCode, list, listItem, strong,
12
+ import {
13
+ map, list as flist, flat, filter, size, foldl,
14
+ } from 'ferrum';
15
+ import {
16
+ root,
17
+ paragraph,
18
+ text,
19
+ heading,
20
+ code,
21
+ table,
22
+ tableRow,
23
+ tableCell,
24
+ link,
25
+ inlineCode,
26
+ list,
27
+ listItem,
28
+ strong,
18
29
  blockquote,
19
- } = require('mdast-builder');
20
- const i18n = require('es2015-i18n-tag').default;
21
- const ghslugger = require('github-slugger');
22
- const yaml = require('js-yaml');
23
- const s = require('./symbols');
24
- const { gentitle } = require('./formattingTools');
25
- const { keyword } = require('./keywords');
26
-
27
- function build({
30
+ } from 'mdast-builder';
31
+ import i from 'es2015-i18n-tag';
32
+ import GhSlugger from 'github-slugger';
33
+ import yaml from 'js-yaml';
34
+ import s from './symbols.js';
35
+ import { gentitle } from './formattingTools.js';
36
+ import { keyword } from './keywords.js';
37
+
38
+ const { default: i18n } = i;
39
+
40
+ export default function build({
28
41
  header,
29
42
  links = {},
30
43
  includeProperties = [],
@@ -249,31 +262,31 @@ function build({
249
262
  table('left', [
250
263
  // iterate over header
251
264
  tableRow(
252
- flist(
253
- map(headerprops,
254
- ({ name, title }) => {
255
- if (links[name]) {
256
- return tableCell(link(links[name], i18n`What does ${title} mean?`, text(title)));
257
- }
258
- return tableCell(text(title));
259
- }), Array,
260
- ),
265
+ flist(map(
266
+ headerprops,
267
+ ({ name, title }) => {
268
+ if (links[name]) {
269
+ return tableCell(link(links[name], i18n`What does ${title} mean?`, text(title)));
270
+ }
271
+ return tableCell(text(title));
272
+ },
273
+ ), Array),
261
274
  ),
262
275
  tableRow(
263
- flist(
264
- map(headerprops,
265
- (prop) => {
266
- // this is a linked property
267
- if (schema[s.meta]
276
+ flist(map(
277
+ headerprops,
278
+ (prop) => {
279
+ // this is a linked property
280
+ if (schema[s.meta]
268
281
  && typeof schema[s.meta][prop.name] === 'object'
269
282
  && schema[s.meta][prop.name].link
270
283
  && schema[s.meta][prop.name].text) {
271
- return tableCell(link(rewritelinks(schema[s.meta][prop.name].link), i18n`open original schema`, [text(schema[s.meta][prop.name].text)]));
272
- }
273
- const value = schema[s.meta] ? schema[s.meta][prop.name] : undefined;
274
- return tableCell(text(prop[`${String(value)}label`] || i18n`Unknown`));
275
- }), Array,
276
- ),
284
+ return tableCell(link(rewritelinks(schema[s.meta][prop.name].link), i18n`open original schema`, [text(schema[s.meta][prop.name].text)]));
285
+ }
286
+ const value = schema[s.meta] ? schema[s.meta][prop.name] : undefined;
287
+ return tableCell(text(prop[`${String(value)}label`] || i18n`Unknown`));
288
+ },
289
+ ), Array),
277
290
  ),
278
291
  ]),
279
292
  ];
@@ -314,8 +327,11 @@ function build({
314
327
  tableCell(type(definition)),
315
328
  tableCell(text(required.indexOf(name) > -1 ? i18n`Required` : i18n`Optional`)),
316
329
  tableCell(nullable(definition)),
317
- tableCell(link(`${definition[s.slug]}.md`, `${definition[s.id]}#${definition[s.pointer]}`,
318
- text(definition[s.titles] && definition[s.titles][0] ? definition[s.titles][0] : i18n`Untitled schema`))),
330
+ tableCell(link(
331
+ `${definition[s.slug]}.md`,
332
+ `${definition[s.id]}#${definition[s.pointer]}`,
333
+ text(definition[s.titles] && definition[s.titles][0] ? definition[s.titles][0] : i18n`Untitled schema`),
334
+ )),
319
335
  ]);
320
336
  }
321
337
 
@@ -370,7 +386,8 @@ function build({
370
386
  }
371
387
  return listItem([
372
388
  paragraph([text(i18n`Type: `), text(i18n`an array where each item follows the corresponding schema in the following list:`)]),
373
- list('ordered',
389
+ list(
390
+ 'ordered',
374
391
  [...items.map((schema) => listItem(paragraph(link(
375
392
  `${schema[s.slug]}.md`,
376
393
  i18n`check type definition`,
@@ -389,7 +406,8 @@ function build({
389
406
  }
390
407
  return [];
391
408
  })(),
392
- ])]);
409
+ ],
410
+ )]);
393
411
  }
394
412
 
395
413
  function maketypefact(definition, isarray = '') {
@@ -719,11 +737,13 @@ function build({
719
737
  return [];
720
738
  }
721
739
 
722
- function makeproplist(properties = {},
740
+ function makeproplist(
741
+ properties = {},
723
742
  patternProperties = {},
724
743
  additionalProperties,
725
744
  required,
726
- level = 2) {
745
+ level = 2,
746
+ ) {
727
747
  return [
728
748
  ...flist(flat(Object.entries(properties || {}).map(([name, definition]) => {
729
749
  const description = definition[s.meta] && definition[s.meta].longdescription ? definition[s.meta].longdescription : paragraph(text(i18n`no description`));
@@ -853,7 +873,7 @@ function build({
853
873
 
854
874
  console.log('generating markdown');
855
875
  return (schemas) => foldl(schemas, {}, (pv, schema) => {
856
- const slugger = ghslugger();
876
+ const slugger = new GhSlugger();
857
877
  // eslint-disable-next-line no-param-reassign
858
878
  pv[schema[s.slug]] = root([
859
879
  // todo add more elements
@@ -868,5 +888,3 @@ function build({
868
888
  return pv;
869
889
  });
870
890
  }
871
-
872
- module.exports = build;
@@ -9,16 +9,18 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const {
13
- map, pipe, filter, list: flist, mapSort, uniq,
14
- } = require('ferrum');
15
- const {
12
+ import {
13
+ map, pipe, filter, list as flist, mapSort, uniq,
14
+ } from 'ferrum';
15
+ import {
16
16
  root, paragraph, text, heading, list, listItem, link, inlineCode,
17
- } = require('mdast-builder');
18
- const i18n = require('es2015-i18n-tag').default;
19
- const s = require('./symbols');
20
- const { gentitle, gendescription } = require('./formattingTools');
21
- const { keyword } = require('./keywords');
17
+ } from 'mdast-builder';
18
+ import i from 'es2015-i18n-tag';
19
+ import s from './symbols.js';
20
+ import { gentitle, gendescription } from './formattingTools.js';
21
+ import { keyword } from './keywords.js';
22
+
23
+ const { default: i18n } = i;
22
24
 
23
25
  function makeversionnote(schemas) {
24
26
  const versions = flist(uniq(schemas
@@ -41,7 +43,7 @@ function makeversionnote(schemas) {
41
43
  * Generate the README.md
42
44
  * @param {object} opts
43
45
  */
44
- function build({ readme = true }) {
46
+ export default function build({ readme = true }) {
45
47
  return (schemas) => {
46
48
  if (readme) {
47
49
  console.log('building readme');
@@ -60,6 +62,7 @@ function build({ readme = true }) {
60
62
  schemas,
61
63
  filter((schema) => schema[keyword`type`] === type), // remove schemas without matching type
62
64
  filter((schema) => !!schema[s.parent]), // keep only schemas with a parent
65
+ filter((schema) => !schema.$ref), // it is not a reference
63
66
  mapSort((schema) => gentitle(schema[s.titles], schema[keyword`type`])),
64
67
  map((schema) => listItem(paragraph([
65
68
  link(`./${schema[s.slug]}.md`, gendescription(schema), [text(gentitle(schema[s.titles], schema[keyword`type`]))]),
@@ -91,5 +94,3 @@ function build({ readme = true }) {
91
94
  return null;
92
95
  };
93
96
  }
94
-
95
- module.exports = build;
@@ -9,20 +9,24 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const ghslugger = require('github-slugger');
13
- const path = require('path');
14
- const { URL } = require('url');
15
- const { formatmeta } = require('./formatInfo');
16
- const symbols = require('./symbols');
17
- const { keyword } = require('./keywords');
12
+ import GhSlugger from 'github-slugger';
13
+ import path from 'path';
14
+ import fs from 'fs-extra';
15
+ import { URL } from 'url';
16
+ import formatmeta from './formatInfo.js';
17
+ import symbols from './symbols.js';
18
+ import { keyword } from './keywords.js';
18
19
 
19
20
  const myslug = Symbol('myslug');
20
21
 
22
+ /**
23
+ * @param {string} file
24
+ * @param {number} [num=1]
25
+ */
21
26
  function loadExamples(file, num = 1) {
22
27
  const examplefile = path.resolve(path.dirname(file), path.basename(file).replace(/\..*$/, `.example.${num}.json`));
23
28
  try {
24
- // eslint-disable-next-line import/no-dynamic-require, global-require
25
- const example = require(examplefile);
29
+ const example = fs.readJSONSync(examplefile);
26
30
  return [example, ...loadExamples(file, num + 1)];
27
31
  } catch {
28
32
  return [];
@@ -30,13 +34,14 @@ function loadExamples(file, num = 1) {
30
34
  }
31
35
 
32
36
  const handler = ({
33
- root = '', filename = '.', schemas, parent, slugger,
37
+ root = '', fullpath = null, filename = '.', schemas, parent = null, slugger,
34
38
  }) => {
35
39
  const meta = {};
36
40
 
37
41
  meta[symbols.parent] = () => parent;
38
42
  meta[symbols.pointer] = () => root;
39
43
  meta[symbols.filename] = () => filename;
44
+ meta[symbols.fullpath] = () => fullpath;
40
45
  meta[symbols.id] = (target) => {
41
46
  // if the schema has it's own ID, use it
42
47
  if (target[keyword`$id`]) {
@@ -62,7 +67,7 @@ const handler = ({
62
67
  };
63
68
 
64
69
  meta[symbols.resolve] = (target, prop, receiver) => (proppath) => {
65
- // console.log('trying to resolve', proppath, 'in', receiver[symbols.filename]);
70
+ // console.log('trying to resolve', proppath, 'in', receiver[symbols.fullpath]);
66
71
  if (proppath === undefined) {
67
72
  return receiver;
68
73
  }
@@ -78,7 +83,7 @@ const handler = ({
78
83
  meta[symbols.slug] = (target, prop, receiver) => {
79
84
  if (!receiver[myslug] && !parent && receiver[symbols.filename]) {
80
85
  // eslint-disable-next-line no-param-reassign
81
- receiver[myslug] = slugger.slug(path.basename(receiver[symbols.filename]).replace(/\..*$/, ''));
86
+ receiver[myslug] = slugger.slug(receiver[symbols.filename].replace(/\..*$/, ''));
82
87
  }
83
88
  if (!receiver[myslug]) {
84
89
  const parentslug = parent[symbols.slug];
@@ -106,13 +111,13 @@ const handler = ({
106
111
  }
107
112
 
108
113
  const retval = Reflect.get(target, prop, receiver);
109
- if (retval === undefined && prop === keyword`examples` && !receiver[symbols.parent]) {
110
- return loadExamples(receiver[symbols.filename], 1);
114
+ if (retval === undefined && receiver[symbols.fullpath] && prop === keyword`examples` && !receiver[symbols.parent]) {
115
+ return loadExamples(receiver[symbols.fullpath], 1);
111
116
  }
112
117
  if (typeof retval === 'object' && retval !== null) {
113
118
  if (retval[keyword`$ref`]) {
114
119
  const [uri, pointer] = retval.$ref.split('#');
115
- // console.log('resolving ref', uri, pointer, 'from', receiver[symbols.filename]);
120
+ // console.log('resolving ref', uri, pointer, 'from', receiver[symbols.fullpath]);
116
121
  const basedoc = uri || receiver[symbols.id];
117
122
  let referenced = null;
118
123
 
@@ -121,7 +126,7 @@ const handler = ({
121
126
  if (schemas.known[basedoc]) {
122
127
  referenced = schemas.known[basedoc][symbols.resolve](pointer);
123
128
  } else if (path.parse(basedoc)) {
124
- const basepath = path.dirname(meta[symbols.filename]());
129
+ const basepath = path.dirname(meta[symbols.fullpath]());
125
130
  let reldoc = uri;
126
131
 
127
132
  // if uri is a URI then only try to resolve it locally if the scheme is 'file:'
@@ -160,6 +165,7 @@ const handler = ({
160
165
  const subschema = new Proxy(retval, handler({
161
166
  root: `${root}/${prop}`,
162
167
  parent: receiver,
168
+ fullpath,
163
169
  filename,
164
170
  schemas,
165
171
  slugger,
@@ -177,30 +183,30 @@ const handler = ({
177
183
  };
178
184
  };
179
185
 
180
- module.exports = {
181
- ...symbols,
182
- };
183
-
184
- module.exports.loader = () => {
186
+ export default function loader() {
185
187
  const schemas = {
186
188
  loaded: [],
187
189
  known: {},
188
190
  files: {},
189
191
  };
190
192
 
191
- const slugger = ghslugger();
193
+ const slugger = new GhSlugger();
192
194
 
193
- return (schema, filename) => {
194
- // console.log('loading', filename);
195
- const proxied = new Proxy(schema, handler({ filename, schemas, slugger }));
195
+ return (/** @type {string} */ name, /** @type {any} */ schema) => {
196
+ // console.log('loading', name);
197
+ const filename = path.basename(name);
198
+ const fullpath = name === filename ? undefined : name;
199
+ const proxied = new Proxy(schema, handler({
200
+ filename, fullpath, schemas, slugger,
201
+ }));
196
202
  schemas.loaded.push(proxied);
197
203
  if (proxied[keyword`$id`]) {
198
204
  // stow away the schema for lookup
199
205
  schemas.known[proxied[keyword`$id`]] = proxied;
200
206
  }
201
207
 
202
- schemas.files[filename] = proxied;
208
+ schemas.files[fullpath || filename] = proxied;
203
209
 
204
210
  return proxied;
205
211
  };
206
- };
212
+ }
package/lib/symbols.js CHANGED
@@ -9,9 +9,21 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
+
13
+ /**
14
+ * @typedef {import("../types/api").UniqueSymbols} UniqueSymbols
15
+ */
16
+
17
+ export const filename = Symbol('filename');
18
+ export const fullpath = Symbol('fullpath');
19
+
20
+ /**
21
+ * @type {UniqueSymbols}
22
+ * */
12
23
  const symbols = {
13
24
  pointer: Symbol('pointer'),
14
- filename: Symbol('filename'),
25
+ filename,
26
+ fullpath,
15
27
  id: Symbol('id'),
16
28
  titles: Symbol('titles'),
17
29
  resolve: Symbol('resolve'),
@@ -20,4 +32,4 @@ const symbols = {
20
32
  parent: Symbol('parent'),
21
33
  };
22
34
 
23
- module.exports = symbols;
35
+ export default symbols;
@@ -10,8 +10,10 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- const { list, eq, contains } = require('ferrum');
14
- const { parent, pointer } = require('./symbols');
13
+ import { list, eq, contains } from 'ferrum';
14
+ import s from './symbols.js';
15
+
16
+ const { parent, pointer } = s;
15
17
 
16
18
  function isSkippableKeyword(schema) {
17
19
  const skippableKeywords = ['examples', 'required', 'properties'];
@@ -49,8 +51,6 @@ function reducer({ seen, ids }, schema) {
49
51
  * which are then emitted as asequence.
50
52
  * @param {Schema} node
51
53
  */
52
- function traverse(schemas) {
54
+ export default function traverse(schemas) {
53
55
  return Array.from(list(schemas).reduce(reducer, { seen: new Set(), ids: [] }).seen);
54
56
  }
55
-
56
- module.exports = traverse;
@@ -9,77 +9,123 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const { each, pairs } = require('ferrum');
13
- const stringify = require('remark-stringify');
14
- const unified = require('unified');
15
- const gfm = require('remark-gfm');
16
- const path = require('path');
17
- const fs = require('fs-extra');
18
- const yaml = require('js-yaml');
12
+ import { each, pairs } from 'ferrum';
13
+ import stringify from 'remark-stringify';
14
+ import { unified } from 'unified';
15
+ import gfm from 'remark-gfm';
16
+ import path from 'path';
17
+ import fs from 'fs-extra';
18
+ import yaml from 'js-yaml';
19
19
 
20
- function writemarkdown({
20
+ /**
21
+ * @typedef {import("../types/api").MarkdownAst} MarkdownAst
22
+ */
23
+ /**
24
+ * @typedef {import("../types/api").MarkdownContent} MarkdownContent
25
+ */
26
+ /**
27
+ * @typedef {import("../types/api").ReadmeContent} ReadmeContent
28
+ */
29
+ /**
30
+ * @typedef {{ [name: string]: MarkdownAst }} MarkdownAstFiles
31
+ */
32
+
33
+ /**
34
+ * Write the Markdown to filesystem or an object
35
+ * @param {Object} options
36
+ * @param {string} [options.out] - (optional) Directory where the files will be saved
37
+ * @param {Function} [options.error] - (optional) Error logger
38
+ * @param {Function} [options.info] - (optional) Info logger
39
+ * @param {Function} [options.debug] - (optional) Debug logger
40
+ * @param {{ [key: string]: string }} [options.meta] - (optional) Metadata to be added to Markdown
41
+ * @returns {(astFiles: MarkdownAstFiles) => MarkdownContent[]}
42
+ */
43
+ export function writemarkdown({
21
44
  out, error, meta,
22
45
  }) {
23
46
  const processor = unified()
24
47
  .use(gfm)
25
48
  .use(stringify);
26
49
 
27
- fs.mkdirpSync(out);
28
-
29
50
  return (schemas) => {
30
- each(pairs(schemas), ([name, markdown]) => {
31
- const fileName = path.resolve(out, `${name}.md`);
51
+ /** @type {MarkdownContent[]} */
52
+ const output = [];
53
+ each(pairs(schemas), (tuple) => {
54
+ /** @type {[ string, MarkdownAst ]} */
55
+ const [name, markdownAst] = tuple;
32
56
 
33
57
  // add YAML frontmatter
34
- const output = (!meta ? '' : '---\n')
58
+ const content = (!meta ? '' : '---\n')
35
59
  + (!meta ? '' : yaml.dump(meta))
36
60
  + (!meta ? '' : '---\n\n')
37
61
 
38
- + processor.stringify(markdown);
62
+ + processor.stringify(markdownAst);
39
63
 
40
- fs.writeFile(fileName, output, (err) => {
41
- if (err) {
64
+ const fileName = `${name}.md`;
65
+ let fullPath;
66
+ if (out) {
67
+ fullPath = path.resolve(out, fileName);
68
+ try {
69
+ fs.outputFileSync(fullPath, content);
70
+ } catch (err) {
42
71
  error(err);
43
72
  }
44
73
  // info(`${fileName} created`);
74
+ }
75
+ output.push({
76
+ fileName,
77
+ fullPath,
78
+ markdownAst,
79
+ content,
45
80
  });
46
81
  });
47
82
 
48
- return schemas;
83
+ return output;
49
84
  };
50
85
  }
51
86
 
52
- function writereadme({
53
- out, error, info, meta, readme,
87
+ /**
88
+ * Write the Readme Markdown to filesystem or an object
89
+ * @param {Object} options
90
+ * @param {string} [options.out] - (optional) Directory where the files will be saved
91
+ * @param {Function} [options.error] - (optional) Error logger
92
+ * @param {Function} [options.info] - (optional) Info logger
93
+ * @param {Function} [options.debug] - (optional) Debug logger
94
+ * @param {{ [key: string]: string }} [options.meta] - (optional) Metadata to be added to Markdown
95
+ * @returns {(markdownAst: MarkdownAst) => ReadmeContent}
96
+ */
97
+ export function writereadme({
98
+ out, error, info, meta,
54
99
  }) {
55
100
  const processor = unified()
56
101
  .use(gfm)
57
102
  .use(stringify);
58
103
 
59
- if (readme) {
60
- fs.mkdirpSync(out);
104
+ return (markdownAst) => {
105
+ // add YAML frontmatter
106
+ const content = (!meta ? '' : '---\n')
107
+ + (!meta ? '' : yaml.dump(meta))
108
+ + (!meta ? '' : '---\n\n')
61
109
 
62
- return (readmeast) => {
63
- const fileName = path.resolve(out, 'README.md');
64
- // add YAML frontmatter
65
- const output = (!meta ? '' : '---\n')
66
- + (!meta ? '' : yaml.dump(meta))
67
- + (!meta ? '' : '---\n\n')
110
+ + processor.stringify(markdownAst);
68
111
 
69
- + processor.stringify(readmeast);
70
-
71
- fs.writeFile(fileName, output, (err) => {
72
- if (err) {
73
- error(err);
74
- }
75
- info(`${fileName} created`);
76
- });
112
+ const fileName = 'README.md';
113
+ let fullPath;
114
+ if (out) {
115
+ fullPath = path.resolve(out, fileName);
116
+ try {
117
+ fs.outputFileSync(fullPath, content);
118
+ } catch (err) {
119
+ error(err);
120
+ }
121
+ info(`${fileName} created`);
122
+ }
77
123
 
78
- return fileName;
124
+ return {
125
+ fileName,
126
+ fullPath,
127
+ markdownAst,
128
+ content,
79
129
  };
80
- } else {
81
- return (args) => args;
82
- }
130
+ };
83
131
  }
84
-
85
- module.exports = { writemarkdown, writereadme };
@@ -9,35 +9,60 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const fs = require('fs-extra');
13
- const path = require('path');
14
- const s = require('./symbols');
12
+ import fs from 'fs-extra';
13
+ import path from 'path';
14
+ import s from './symbols.js';
15
15
 
16
- function writeSchema({ schemadir, origindir }) {
17
- const targetpath = (filename) => path.resolve(schemadir, path.relative(origindir, filename));
16
+ /**
17
+ * @typedef {import("../types/api").ExtendedJsonSchema} ExtendedJsonSchema
18
+ */
19
+ /**
20
+ * @typedef {import("../types/api").SchemaContent} SchemaContent
21
+ */
18
22
 
23
+ /**
24
+ * Write the JSON Schemas to filesystem or an object
25
+ * @param {Object} options
26
+ * @param {string} [options.schemadir] - (optional) Directory where the files will be saved
27
+ * @param {string} [options.origindir] - (optional) Directory where the files were loaded from
28
+ * @returns {(schemas: ExtendedJsonSchema[]) => SchemaContent[]}
29
+ */
30
+ export default function writeSchema({ schemadir, origindir }) {
19
31
  return (schemas) => {
20
- console.log('writing schemas to', schemadir);
32
+ // eslint-disable-next-line no-console
33
+ console.log('preparing schemas');
21
34
 
22
35
  const realschemas = Object.values(schemas).filter((schema) => !schema[s.parent]);
23
- realschemas.forEach((schema) => {
24
- // console.log('writing', schema[s.filename], 'to ', targetpath(schema[s.filename]));
25
- const filename = targetpath(schema[s.filename]);
26
- const dirname = path.dirname(filename);
36
+ return realschemas.map((schema) => {
37
+ const fileName = schema[s.filename];
38
+ const inputPath = schema[s.fullpath] || (origindir && path.join(origindir, fileName));
39
+ let content = schema;
27
40
 
28
- const out = fs.readJSONSync(schema[s.filename]);
29
- if (schema[s.meta] && schema[s.meta].description) {
30
- // copy description from external file
31
- out.description = schema[s.meta].description;
41
+ if (inputPath) {
42
+ content = fs.readJsonSync(inputPath);
43
+ if (schema[s.meta] && schema[s.meta].description) {
44
+ // copy description from external file
45
+ content.description = schema[s.meta].description;
46
+ }
47
+ if (schema.examples && Array.isArray(schema.examples) && schema.examples.length > 0) {
48
+ // copy examples from external files
49
+ content.examples = [...schema.examples];
50
+ }
32
51
  }
33
- if (schema.examples && Array.isArray(schema.examples) && schema.examples.length > 0) {
34
- // copy examples from external files
35
- out.examples = [...schema.examples];
52
+
53
+ let fullPath;
54
+ if (schemadir) {
55
+ // eslint-disable-next-line no-console
56
+ console.log('writing schemas to', schemadir);
57
+ fullPath = path.resolve(schemadir, fileName);
58
+ fs.outputJsonSync(fullPath, content);
36
59
  }
37
- fs.mkdirpSync(dirname);
38
- fs.writeJsonSync(filename, out);
60
+
61
+ return {
62
+ fileName,
63
+ fullPath,
64
+ content,
65
+ };
39
66
  });
40
67
  };
41
68
  }
42
-
43
- module.exports = { writeSchema };