@adobe/jsonschema2md 6.1.4 → 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 +26 -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 +15 -15
  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 +39 -28
  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 -118
  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 -106
  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
@@ -19,13 +19,13 @@ module.exports = {
19
19
  // eslintrc files in parent directories.
20
20
  root: true,
21
21
  parserOptions: {
22
- sourceType: 'script',
23
- ecmaVersion: 10,
22
+ sourceType: 'module',
23
+ ecmaVersion: 2020,
24
24
  },
25
25
  plugins: [
26
26
  'header',
27
27
  ],
28
- extends: 'airbnb',
28
+ extends: '@adobe/helix',
29
29
  rules: {
30
30
  strict: 0,
31
31
 
@@ -47,19 +47,5 @@ module.exports = {
47
47
  argsIgnorePattern: '^_.*$',
48
48
  caughtErrorsIgnorePattern: '^_.*$',
49
49
  }],
50
-
51
- // enforce license header (todo: improve plugin to support patterns for multi-lines)
52
- 'header/header': [2, 'block', ['',
53
- { pattern: ' * Copyright \\d{4} Adobe\\. All rights reserved\\.', template: ' * Copyright 2021 Adobe. All rights reserved.' },
54
- ' * This file is licensed to you under the Apache License, Version 2.0 (the "License");',
55
- ' * you may not use this file except in compliance with the License. You may obtain a copy',
56
- ' * of the License at http://www.apache.org/licenses/LICENSE-2.0',
57
- ' *',
58
- ' * Unless required by applicable law or agreed to in writing, software distributed under',
59
- ' * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS',
60
- ' * OF ANY KIND, either express or implied. See the License for the specific language',
61
- ' * governing permissions and limitations under the License.',
62
- ' ',
63
- ]],
64
50
  },
65
51
  };
File without changes
package/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ # [7.0.0](https://github.com/adobe/jsonschema2md/compare/v6.1.4...v7.0.0) (2022-02-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update dependency @adobe/helix-log to v6 ([#363](https://github.com/adobe/jsonschema2md/issues/363)) ([6298ed2](https://github.com/adobe/jsonschema2md/commit/6298ed2808d4797429d907159c762ac79d19627b))
7
+ * **index:** remove reference to single input file ([7324427](https://github.com/adobe/jsonschema2md/commit/732442777d067e6a9091a6af50e21fcfca9fbd47)), closes [#386](https://github.com/adobe/jsonschema2md/issues/386)
8
+ * **symbols:** tweak exports ([d31ab23](https://github.com/adobe/jsonschema2md/commit/d31ab239385cbe51eede6ff794fdfa58d7109717))
9
+ * **tests:** use fileToURLPath for dirname ([352d032](https://github.com/adobe/jsonschema2md/commit/352d032dccbc16e094359ae7e0d6d44e8ffd7863))
10
+
11
+
12
+ ### Code Refactoring
13
+
14
+ * use esm ([a628755](https://github.com/adobe/jsonschema2md/commit/a6287553800fbe98396af193ebf0a56ca3cabde0))
15
+
16
+
17
+ ### Features
18
+
19
+ * **api:** change shape of input and output data ([797090f](https://github.com/adobe/jsonschema2md/commit/797090fce370296ddb7c3c3fe3605330fcde02ff))
20
+ * **api:** create typescript declaration for api ([92426f9](https://github.com/adobe/jsonschema2md/commit/92426f9038c5b9e04fc6ea33fd34fbea7de6a29b))
21
+
22
+
23
+ ### BREAKING CHANGES
24
+
25
+ * `jsonschema2md` now uses ECMAScript Modules (`import`/`export`) instead of CommonJS Modules (`require`/`exports`). This was driven by the desire to stay up to date with dependencies that switched to ESM.
26
+
1
27
  ## [6.1.4](https://github.com/adobe/jsonschema2md/compare/v6.1.3...v6.1.4) (2021-09-20)
2
28
 
3
29
 
package/cli.js CHANGED
@@ -11,6 +11,6 @@
11
11
  * governing permissions and limitations under the License.
12
12
  */
13
13
 
14
- const { main } = require('./lib/index');
14
+ import { main } from './lib/index.js';
15
15
 
16
16
  main(process.argv);
package/lib/formatInfo.js CHANGED
@@ -9,14 +9,14 @@
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');
13
- const path = require('path');
14
- const unified = require('unified');
15
- const parse = require('remark-parse');
16
- const gfm = require('remark-gfm');
17
- const stringify = require('mdast-util-to-string');
18
- const s = require('./symbols');
19
- const { keyword } = require('./keywords');
12
+ import fs from 'fs';
13
+ import path from 'path';
14
+ import { unified } from 'unified';
15
+ import parse from 'remark-parse';
16
+ import gfm from 'remark-gfm';
17
+ import { toString as stringify } from 'mdast-util-to-string';
18
+ import s from './symbols.js';
19
+ import { keyword } from './keywords.js';
20
20
 
21
21
  function isabstract(schema) {
22
22
  return schema.definitions !== undefined
@@ -49,24 +49,24 @@ function iscustom(schema) {
49
49
  function getdefined(schema) {
50
50
  if (schema[s.parent]) {
51
51
  return {
52
- text: `${path.basename(schema[s.filename])}*`,
53
- link: schema[s.filename],
52
+ text: `${schema[s.filename]}*`,
53
+ link: schema[s.fullpath],
54
54
  };
55
55
  }
56
56
  return {
57
- text: path.basename(schema[s.filename]),
58
- link: schema[s.filename],
57
+ text: schema[s.filename],
58
+ link: schema[s.fullpath],
59
59
  };
60
60
  }
61
61
 
62
62
  function plaindescription(schema) {
63
63
  try {
64
- if (schema[s.filename] && !schema[s.parent]) {
65
- const filename = path.resolve(
66
- path.dirname(schema[s.filename]),
64
+ if (schema[s.fullpath] && !schema[s.parent]) {
65
+ const fullPath = path.resolve(
66
+ path.dirname(schema[s.fullpath]),
67
67
  schema[s.filename].replace(/\..*$/, '.description.md'),
68
68
  );
69
- const longdesc = fs.readFileSync(filename);
69
+ const longdesc = fs.readFileSync(fullPath);
70
70
  return longdesc.toString();
71
71
  }
72
72
  } catch {
@@ -119,7 +119,7 @@ function getrestrictions(schema) {
119
119
  return undefined;
120
120
  }
121
121
 
122
- function formatmeta(schema) {
122
+ export default function formatmeta(schema) {
123
123
  return {
124
124
  abstract: isabstract(schema),
125
125
  extensible: isextensible(schema),
@@ -133,5 +133,3 @@ function formatmeta(schema) {
133
133
  ...parsecomment(schema[keyword`$comment`]),
134
134
  };
135
135
  }
136
-
137
- module.exports.formatmeta = formatmeta;
@@ -9,10 +9,12 @@
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 i18n = require('es2015-i18n-tag').default;
13
- const s = require('./symbols');
12
+ import i from 'es2015-i18n-tag';
13
+ import s from './symbols.js';
14
14
 
15
- function gentitle(titles, type) {
15
+ const { default: i18n } = i;
16
+
17
+ export function gentitle(titles, type) {
16
18
  if (!Array.isArray(titles)) {
17
19
  return i18n`Untitled schema`;
18
20
  }
@@ -34,10 +36,6 @@ function gentitle(titles, type) {
34
36
  return i18n`Untitled undefined type in ${firsttitle}`;
35
37
  }
36
38
 
37
- function gendescription(schema) {
39
+ export function gendescription(schema) {
38
40
  return (schema && schema[s.meta]) ? schema[s.meta].shortdescription : '';
39
41
  }
40
-
41
- module.exports = {
42
- gentitle, gendescription,
43
- };
package/lib/index.js CHANGED
@@ -9,67 +9,160 @@
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
- const yargs = require('yargs');
14
- const nodepath = require('path');
15
-
16
- const fs = require('fs');
17
- const readdirp = require('readdirp');
18
- const logger = require('@adobe/helix-log');
19
- const {
12
+ /* @ts-check */
13
+ import yargs from 'yargs';
14
+ import fs from 'fs-extra';
15
+ import readdirp from 'readdirp';
16
+ import { createDefaultLogger, SimpleInterface } from '@adobe/helix-log';
17
+ import {
20
18
  iter, pipe, filter, map, obj,
21
- } = require('ferrum');
22
- const npath = require('path');
23
- const { i18nConfig } = require('es2015-i18n-tag');
24
- const traverse = require('./traverseSchema');
25
- const build = require('./markdownBuilder');
26
- const { writereadme, writemarkdown } = require('./writeMarkdown');
27
- const readme = require('./readmeBuilder');
28
- const { loader } = require('./schemaProxy');
29
- const { writeSchema } = require('./writeSchema');
30
-
31
- const { info, error, debug } = logger;
32
-
33
- function jsonschema2md(schema, {
34
- schemaPath,
35
- out,
36
- meta,
37
- schemaOut,
38
- includeReadme,
39
- links,
40
- i18n,
41
- language,
42
- exampleFormat,
43
- includeProperties,
44
- header,
45
- skipProperties,
46
- }) {
47
- const outOrDefault = out || nodepath.resolve(nodepath.join('.', 'out'));
19
+ } from 'ferrum';
20
+ import nodepath from 'path';
21
+ import { i18nConfig } from 'es2015-i18n-tag';
22
+ import { fileURLToPath } from 'url';
23
+ import traverse from './traverseSchema.js';
24
+ import build from './markdownBuilder.js';
25
+ import { writereadme, writemarkdown } from './writeMarkdown.js';
26
+ import readme from './readmeBuilder.js';
27
+ import loader from './schemaProxy.js';
28
+ import writeSchema from './writeSchema.js';
29
+
30
+ const __filename = fileURLToPath(import.meta.url);
31
+ const __dirname = nodepath.dirname(__filename);
32
+
33
+ const logger = new SimpleInterface({
34
+ logger: createDefaultLogger(),
35
+ });
36
+ const debug = logger.debug.bind(logger);
37
+ const info = logger.info.bind(logger);
38
+ const error = logger.error.bind(logger);
39
+
40
+ /**
41
+ * @typedef {import("../types/api").JsonSchema} JsonSchema
42
+ */
43
+ /**
44
+ * @typedef {import("../types/api").SchemaList} SchemaList
45
+ */
46
+ /**
47
+ * @typedef {import("../types/api").SchemaContent} SchemaContent
48
+ */
49
+ /**
50
+ * @typedef {import("../types/api").SchemaFiles} SchemaFiles
51
+ */
52
+ /**
53
+ * @typedef {import("../types/api").GeneratedOutput} GeneratedOutput
54
+ */
55
+
56
+ /**
57
+ * Public API for jsonschema2md that can be used to turn JSON Schema files
58
+ * into readable Markdown documentation.
59
+ * @param {JsonSchema | SchemaFiles} schema JSON Schema input to get data from
60
+ * @param {Object} options Additional options for generation
61
+ * @param {string} [options.schemaPath] - (optional) Path to directory containing all JSON Schemas
62
+ * or a single JSON Schema file. This will be considered as the baseURL.
63
+ * @param {string} [options.outDir] - (optional) Path to output directory. Generating files will
64
+ * be skipped if directory is not specified.
65
+ * @param {{ [key:string]: string }} [options.metadata] - (optional) Add metadata elements to
66
+ * .md files.
67
+ * @param {string} [options.schemaOut] - (optional) Output JSON Schema files including
68
+ * description and validated examples in the specified folder.
69
+ * @param {boolean} [options.includeReadme=true] - (optional) Generate a README.md file in the
70
+ * output directory.
71
+ * @param {{ [key:string]: string }[]} [options.links] - (optional) Add this file as a link
72
+ * explaining the specified attribute.
73
+ * @param {string} [options.i18n="locales/"] - (optional) Path to a locales folder with
74
+ * JSON files used for internationalization.
75
+ * @param {"en_US" | "de"} [options.language="en_US"] - (optional) Selected language.
76
+ * @param {"json" | "yaml"} [options.exampleFormat="json"] - (optional) How to format examples.
77
+ * @param {string[]} [options.includeProperties=[]] - (optional) Name of custom properties
78
+ * which should be also in the description of an element.
79
+ * @param {boolean} [options.header=true] - (optional) Whether or not to include the header
80
+ * in markdown.
81
+ * @param {string[]} [options.skipProperties=[]] - (optional) Name of a default property to
82
+ * skip in markdown.
83
+ * @returns {GeneratedOutput} List of raw markdown that were generated from input schema.
84
+ */
85
+ export function jsonschema2md(schema, options) {
86
+ const {
87
+ schemaPath,
88
+ outDir,
89
+ metadata,
90
+ schemaOut,
91
+ includeReadme,
92
+ links,
93
+ i18n,
94
+ language,
95
+ exampleFormat,
96
+ includeProperties,
97
+ header,
98
+ skipProperties,
99
+ } = options;
100
+ if (!schema || typeof schema !== 'object') {
101
+ throw Error('Input is not valid. Provide JSON schema either as Object or Array.');
102
+ }
48
103
  const locales = i18n || nodepath.resolve(__dirname, 'locales');
49
- // eslint-disable-next-line import/no-dynamic-require, global-require
50
- i18nConfig(require(nodepath.resolve(locales, `${language || 'en_US'}.json`)));
51
-
52
- const schemas = [].concat(schema);
53
- if (schemaOut) {
54
- console.log('writing schemas');
55
- writeSchema({
56
- schemadir: schemaOut,
57
- origindir: schemaPath,
58
- })(schemas);
104
+ i18nConfig(fs.readJSONSync(nodepath.resolve(locales, `${language || 'en_US'}.json`)));
105
+ let out = outDir;
106
+ if (options.out) {
107
+ // eslint-disable-next-line no-console
108
+ console.warn("Options 'out' has been deprecated. Please, use 'outDir' instead");
109
+ out = options.out;
110
+ }
111
+ let meta = metadata;
112
+ if (options.meta) {
113
+ // eslint-disable-next-line no-console
114
+ console.warn("Options 'meta' has been deprecated. Please, use 'metadata' instead");
115
+ meta = options.meta;
116
+ }
117
+
118
+ /** @type {SchemaFiles} */
119
+ let normalized;
120
+ if (Array.isArray(schema)) {
121
+ normalized = schema;
122
+ } else {
123
+ normalized = [{
124
+ fileName: 'definition.schema.json',
125
+ content: schema,
126
+ }];
59
127
  }
60
128
 
129
+ const schemaLoader = loader();
130
+
131
+ // collect data about the schemas and turn everything into a big object
132
+ const schemas = pipe(
133
+ normalized,
134
+ // Checking if data contains the file path or its contents (JSON schema)
135
+ map(({ fileName, fullPath, content }) => {
136
+ if (!content && fullPath) {
137
+ return schemaLoader(fullPath, fs.readJSONSync(fullPath));
138
+ }
139
+ return schemaLoader(fileName, content);
140
+ }),
141
+ traverse,
142
+ );
143
+
144
+ /**
145
+ * @type {GeneratedOutput}
146
+ */
147
+ const output = {};
148
+
149
+ console.log('preparing schemas...');
150
+ output.schema = writeSchema({
151
+ schemadir: schemaOut,
152
+ origindir: schemaPath,
153
+ })(schemas);
154
+
61
155
  if (includeReadme) {
62
- console.log('writing README');
63
- pipe(
156
+ console.log('preparing README...');
157
+ output.readme = pipe(
64
158
  schemas,
65
159
  // build readme
66
160
  readme({
67
- readme: includeReadme,
161
+ readme: true,
68
162
  }),
69
163
 
70
164
  writereadme({
71
- readme: includeReadme,
72
- out: outOrDefault,
165
+ out,
73
166
  info,
74
167
  error,
75
168
  debug,
@@ -78,8 +171,8 @@ function jsonschema2md(schema, {
78
171
  );
79
172
  }
80
173
 
81
- console.log('writing documentation');
82
- const markdown = pipe(
174
+ console.log('preparing documentation...');
175
+ output.markdown = pipe(
83
176
  schemas,
84
177
  // generate Markdown ASTs
85
178
  build({
@@ -89,21 +182,24 @@ function jsonschema2md(schema, {
89
182
  exampleFormat,
90
183
  skipProperties,
91
184
  rewritelinks: (origin) => {
92
- const mddir = outOrDefault;
185
+ const mddir = out;
186
+ if (!mddir) {
187
+ return origin;
188
+ }
93
189
  const srcdir = schemaPath;
94
190
  const schemadir = schemaOut || schemaPath;
95
191
 
96
- const target = npath.relative(
192
+ const target = nodepath.relative(
97
193
  mddir,
98
- npath.resolve(schemadir, npath.relative(srcdir, origin)),
99
- ).split(npath.sep).join(npath.posix.sep);
194
+ nodepath.resolve(schemadir, nodepath.relative(srcdir, origin)),
195
+ ).split(nodepath.sep).join(nodepath.posix.sep);
100
196
  return target;
101
197
  },
102
198
  }),
103
199
 
104
200
  // write to files
105
201
  writemarkdown({
106
- out: outOrDefault,
202
+ out,
107
203
  info,
108
204
  error,
109
205
  debug,
@@ -111,19 +207,24 @@ function jsonschema2md(schema, {
111
207
  }),
112
208
  );
113
209
 
114
- return markdown;
210
+ return output;
115
211
  }
116
212
 
117
- async function main(args) {
213
+ /**
214
+ * Main function used in the CLI.
215
+ * @param {{ [key:string]: unknown }} args CLI arguments from user input
216
+ * @returns The generated Markdown files to the specified output directory
217
+ */
218
+ export async function main(args) {
118
219
  // parse/process command line arguments
119
220
  const { argv } = yargs(args)
120
221
  .usage('Generate Markdown documentation from JSON Schema.\n\nUsage: $0')
121
222
 
122
223
  .demand('d')
123
224
  .alias('d', 'input')
124
- .describe('d', 'path to directory containing all JSON Schemas or a single JSON Schema file. This will be considered as the baseURL. By default only files ending in .schema.json will be processed, unless the schema-extension is set with the -e flag.')
225
+ .describe('d', 'path to directory containing all JSON Schemas to process. This will be considered as the baseURL. By default only files ending in .schema.json will be processed, unless the schema-extension is set with the -e flag.')
125
226
  .coerce('d', (d) => {
126
- const resolved = nodepath.resolve(d);
227
+ const resolved = d && nodepath.resolve(d);
127
228
  if (fs.existsSync(resolved) && fs.lstatSync(d).isDirectory()) {
128
229
  return resolved;
129
230
  }
@@ -198,8 +299,8 @@ async function main(args) {
198
299
  );
199
300
 
200
301
  const schemaPath = argv.d;
201
- const out = argv.o;
202
- const meta = argv.m;
302
+ const outDir = argv.o;
303
+ const metadata = argv.m;
203
304
  const schemaOut = argv.x !== '-' ? argv.x : null;
204
305
  const includeReadme = !argv.n;
205
306
  const i18n = argv.i;
@@ -211,27 +312,23 @@ async function main(args) {
211
312
 
212
313
  const schemaExtension = argv.e;
213
314
 
214
- const schemaloader = loader();
215
-
216
315
  // list all schema files in the specified directory
217
- const schemafiles = await readdirp.promise(schemaPath, { root: schemaPath, fileFilter: `*.${schemaExtension}` });
316
+ const schemaFiles = await readdirp.promise(schemaPath, { root: schemaPath, fileFilter: `*.${schemaExtension}` });
218
317
 
219
- console.log(`loading ${schemafiles.length} schemas`);
318
+ console.log(`loading ${schemaFiles.length} schemas`);
220
319
 
221
- // then collect data about the schemas and turn everything into a big object
222
- const loadedschemas = pipe(
223
- schemafiles,
224
- map((schema) => schema.fullPath),
225
- // eslint-disable-next-line import/no-dynamic-require, global-require
226
- map((path) => schemaloader(require(path), path)),
227
- // find contained schemas
228
- traverse,
229
- );
320
+ /**
321
+ * @type {SchemaList[]}
322
+ * */
323
+ const schemas = schemaFiles.map((schema) => ({
324
+ fileName: schema.basename,
325
+ fullPath: schema.fullPath,
326
+ }));
230
327
 
231
- jsonschema2md(loadedschemas, {
328
+ jsonschema2md(schemas, {
232
329
  schemaPath,
233
- out,
234
- meta,
330
+ outDir,
331
+ metadata,
235
332
  schemaOut,
236
333
  includeReadme,
237
334
  links,
@@ -245,5 +342,3 @@ async function main(args) {
245
342
 
246
343
  return 1;
247
344
  }
248
-
249
- module.exports = { jsonschema2md, main };
package/lib/keywords.js CHANGED
@@ -11,13 +11,11 @@
11
11
  */
12
12
  const used = new Set();
13
13
 
14
- function keyword(str) {
14
+ export function keyword(str) {
15
15
  used.add(str[0]);
16
16
  return str.join('');
17
17
  }
18
18
 
19
- function report() {
19
+ export function report() {
20
20
  return used;
21
21
  }
22
-
23
- module.exports = { keyword, report };
@@ -10,8 +10,8 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  // eslint-disable-next-line import/no-extraneous-dependencies
13
- const { exportTranslationKeys } = require('i18n-tag-schema');
14
- const fs = require('fs-extra');
13
+ import { exportTranslationKeys } from 'i18n-tag-schema';
14
+ import fs from 'fs-extra';
15
15
 
16
16
  exportTranslationKeys({ rootPath: './lib' })
17
17
  .then((result) => {