@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.
- package/{.eslintrc.js → .eslintrc.cjs} +3 -17
- package/{.releaserc.js → .releaserc.cjs} +0 -0
- package/CHANGELOG.md +47 -0
- package/cli.js +1 -1
- package/lib/formatInfo.js +17 -19
- package/lib/formattingTools.js +6 -8
- package/lib/index.js +176 -81
- package/lib/keywords.js +2 -4
- package/lib/locales/update.js +2 -2
- package/lib/markdownBuilder.js +62 -44
- package/lib/readmeBuilder.js +13 -12
- package/lib/schemaProxy.js +32 -26
- package/lib/symbols.js +14 -2
- package/lib/traverseSchema.js +5 -5
- package/lib/writeMarkdown.js +87 -41
- package/lib/writeSchema.js +46 -21
- package/package.json +40 -29
- package/types/api.d.ts +72 -0
- package/types/formatInfo.d.ts +19 -0
- package/types/formattingTools.d.ts +2 -0
- package/types/index.d.ts +75 -0
- package/types/keywords.d.ts +2 -0
- package/types/markdownBuilder.d.ts +8 -0
- package/types/readmeBuilder.d.ts +5 -0
- package/types/schemaProxy.d.ts +1 -0
- package/types/symbols.d.ts +11 -0
- package/types/traverseSchema.d.ts +6 -0
- package/types/writeMarkdown.d.ts +56 -0
- package/types/writeSchema.d.ts +19 -0
- package/.circleci/config.yml +0 -83
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -23
- package/.github/workflows/semantic-release.yaml +0 -55
- package/.github/workflows/semver-check.yaml +0 -16
- package/.renovaterc.json +0 -3
- package/.tidelift.yml +0 -32
- package/crowdin.yml +0 -4
- package/examples/abstract.md +0 -3
- package/examples/docs/README.md +0 -121
- package/examples/docs/abstract-definitions-first-properties-foo.md +0 -15
- package/examples/docs/abstract-definitions-first-properties-nonfoo.md +0 -23
- package/examples/docs/abstract-definitions-first.md +0 -66
- package/examples/docs/abstract-definitions-second-properties-bar.md +0 -15
- package/examples/docs/abstract-definitions-second.md +0 -39
- package/examples/docs/abstract-definitions.md +0 -15
- package/examples/docs/abstract.md +0 -104
- package/examples/docs/arrays-properties-boollist-items.md +0 -15
- package/examples/docs/arrays-properties-boollist.md +0 -19
- package/examples/docs/arrays-properties-coordinatelist-items-items.md +0 -21
- package/examples/docs/arrays-properties-coordinatelist-items.md +0 -21
- package/examples/docs/arrays-properties-coordinatelist.md +0 -19
- package/examples/docs/arrays-properties-intlist-items.md +0 -15
- package/examples/docs/arrays-properties-intlist.md +0 -21
- package/examples/docs/arrays-properties-jointypelist-items-oneof-0-properties-foo.md +0 -21
- package/examples/docs/arrays-properties-jointypelist-items-oneof-0.md +0 -45
- package/examples/docs/arrays-properties-jointypelist-items-oneof-1-properties-bar.md +0 -21
- package/examples/docs/arrays-properties-jointypelist-items-oneof-1.md +0 -45
- package/examples/docs/arrays-properties-jointypelist-items.md +0 -21
- package/examples/docs/arrays-properties-jointypelist.md +0 -15
- package/examples/docs/arrays-properties-list-items.md +0 -15
- package/examples/docs/arrays-properties-list.md +0 -15
- package/examples/docs/arrays-properties-listlist-items.md +0 -15
- package/examples/docs/arrays-properties-listlist.md +0 -15
- package/examples/docs/arrays-properties-numlist-items.md +0 -19
- package/examples/docs/arrays-properties-numlist.md +0 -19
- package/examples/docs/arrays-properties-objectlist-items-properties-a.md +0 -15
- package/examples/docs/arrays-properties-objectlist-items-properties-b.md +0 -15
- package/examples/docs/arrays-properties-objectlist-items.md +0 -58
- package/examples/docs/arrays-properties-objectlist.md +0 -15
- package/examples/docs/arrays-properties-stringlistlist-items-items.md +0 -15
- package/examples/docs/arrays-properties-stringlistlist-items.md +0 -15
- package/examples/docs/arrays-properties-stringlistlist.md +0 -15
- package/examples/docs/arrays-properties-tuple-items-negative-integer.md +0 -19
- package/examples/docs/arrays-properties-tuple-items-positive-integer.md +0 -19
- package/examples/docs/arrays-properties-tuple-zero.md +0 -23
- package/examples/docs/arrays-properties-tuple.md +0 -21
- package/examples/docs/arrays.md +0 -240
- package/examples/docs/complex-additionalproperties.md +0 -15
- package/examples/docs/complex-patternproperties-int.md +0 -15
- package/examples/docs/complex-patternproperties-str.md +0 -15
- package/examples/docs/complex-patternproperties.md +0 -15
- package/examples/docs/complex-properties-and-allof-0.md +0 -19
- package/examples/docs/complex-properties-and-allof-1.md +0 -19
- package/examples/docs/complex-properties-and.md +0 -21
- package/examples/docs/complex-properties-or-anyof-0.md +0 -15
- package/examples/docs/complex-properties-or-anyof-1.md +0 -19
- package/examples/docs/complex-properties-or.md +0 -21
- package/examples/docs/complex-properties-reflocalfiledef.md +0 -39
- package/examples/docs/complex-properties-refnestedobj-properties-refobj.md +0 -39
- package/examples/docs/complex-properties-refnestedobj.md +0 -39
- package/examples/docs/complex-properties-refobj.md +0 -39
- package/examples/docs/complex-properties-xor-oneof-0.md +0 -19
- package/examples/docs/complex-properties-xor-oneof-1.md +0 -19
- package/examples/docs/complex-properties-xor.md +0 -21
- package/examples/docs/complex.md +0 -285
- package/examples/docs/constants-properties-hello.md +0 -23
- package/examples/docs/constants.md +0 -47
- package/examples/docs/custom-allof-0.md +0 -15
- package/examples/docs/custom-allof-1.md +0 -39
- package/examples/docs/custom-allof-2.md +0 -39
- package/examples/docs/custom-definitions-first-properties-foo.md +0 -15
- package/examples/docs/custom-definitions-first-properties.md +0 -15
- package/examples/docs/custom-definitions-first.md +0 -39
- package/examples/docs/custom-definitions-second-properties-bar.md +0 -15
- package/examples/docs/custom-definitions-second-properties.md +0 -15
- package/examples/docs/custom-definitions-second.md +0 -39
- package/examples/docs/custom-definitions.md +0 -15
- package/examples/docs/custom.md +0 -85
- package/examples/docs/deepextending-allof-0.md +0 -49
- package/examples/docs/deepextending-allof-1.md +0 -89
- package/examples/docs/deepextending-allof-3.md +0 -39
- package/examples/docs/deepextending-definitions-fourth-properties-hey.md +0 -15
- package/examples/docs/deepextending-definitions-fourth-properties.md +0 -15
- package/examples/docs/deepextending-definitions-fourth.md +0 -39
- package/examples/docs/deepextending-definitions.md +0 -15
- package/examples/docs/deepextending.md +0 -57
- package/examples/docs/definitions-definitions-myid-properties-id-1.md +0 -19
- package/examples/docs/definitions-definitions-myid-properties-id.md +0 -19
- package/examples/docs/definitions-definitions-myid-properties-metaid.md +0 -19
- package/examples/docs/definitions-definitions-myid-properties.md +0 -15
- package/examples/docs/definitions-definitions-myid.md +0 -89
- package/examples/docs/definitions-definitions.md +0 -15
- package/examples/docs/definitions.md +0 -117
- package/examples/docs/enums-properties-enumerated-nested-properties-test.md +0 -25
- package/examples/docs/enums-properties-enumerated-nested.md +0 -49
- package/examples/docs/enums-properties-hello.md +0 -24
- package/examples/docs/enums.md +0 -67
- package/examples/docs/example-properties-bar.md +0 -25
- package/examples/docs/example-properties-foo.md +0 -21
- package/examples/docs/example.md +0 -83
- package/examples/docs/examples-properties-bar.md +0 -25
- package/examples/docs/examples-properties-foo.md +0 -21
- package/examples/docs/examples.md +0 -90
- package/examples/docs/extending-definitions-third-properties-baaaz.md +0 -21
- package/examples/docs/extending-definitions-third.md +0 -45
- package/examples/docs/extending-definitions.md +0 -15
- package/examples/docs/extending.md +0 -61
- package/examples/docs/extensible-definitions-first-properties-foo.md +0 -21
- package/examples/docs/extensible-definitions-first-properties.md +0 -15
- package/examples/docs/extensible-definitions-first.md +0 -45
- package/examples/docs/extensible-definitions-second-properties-bar.md +0 -25
- package/examples/docs/extensible-definitions-second-properties.md +0 -15
- package/examples/docs/extensible-definitions-second.md +0 -49
- package/examples/docs/extensible-definitions.md +0 -15
- package/examples/docs/extensible.md +0 -93
- package/examples/docs/identifiable-properties-id.md +0 -19
- package/examples/docs/identifiable.md +0 -43
- package/examples/docs/join-oneof-0-not-oneof-0-properties-foo.md +0 -21
- package/examples/docs/join-oneof-0-not-oneof-0.md +0 -45
- package/examples/docs/join-oneof-0-not-oneof-1-properties-bar.md +0 -21
- package/examples/docs/join-oneof-0-not-oneof-1.md +0 -45
- package/examples/docs/join-oneof-0-not.md +0 -21
- package/examples/docs/join-oneof-0.md +0 -23
- package/examples/docs/join-oneof-1-allof-0-properties-foo.md +0 -21
- package/examples/docs/join-oneof-1-allof-0.md +0 -45
- package/examples/docs/join-oneof-1.md +0 -19
- package/examples/docs/join-oneof-2-anyof-0-properties-bar.md +0 -21
- package/examples/docs/join-oneof-2-anyof-0.md +0 -45
- package/examples/docs/join-oneof-2.md +0 -19
- package/examples/docs/join.md +0 -33
- package/examples/docs/nestedobj-properties-settings-properties-collaborators-patternproperties-.md +0 -15
- package/examples/docs/nestedobj-properties-settings-properties-collaborators-patternproperties.md +0 -15
- package/examples/docs/nestedobj-properties-settings-properties-collaborators-properties-id.md +0 -15
- package/examples/docs/nestedobj-properties-settings-properties-collaborators.md +0 -58
- package/examples/docs/nestedobj-properties-settings.md +0 -39
- package/examples/docs/nestedobj.md +0 -39
- package/examples/docs/pattern-patternproperties-0-9.md +0 -21
- package/examples/docs/pattern-patternproperties.md +0 -15
- package/examples/docs/pattern.md +0 -45
- package/examples/docs/simple-properties-id.md +0 -19
- package/examples/docs/simple.md +0 -43
- package/examples/docs/simpletypes-properties-integer_threes.md +0 -23
- package/examples/docs/simpletypes-properties-interger_constrained.md +0 -19
- package/examples/docs/simpletypes-properties-interger_unconstrained.md +0 -15
- package/examples/docs/simpletypes-properties-number_constrained.md +0 -19
- package/examples/docs/simpletypes-properties-number_unconstrained.md +0 -15
- package/examples/docs/simpletypes-properties-string_date.md +0 -19
- package/examples/docs/simpletypes-properties-string_email.md +0 -19
- package/examples/docs/simpletypes-properties-string_hostname.md +0 -19
- package/examples/docs/simpletypes-properties-string_ipv4.md +0 -19
- package/examples/docs/simpletypes-properties-string_ipv6.md +0 -19
- package/examples/docs/simpletypes-properties-string_length.md +0 -31
- package/examples/docs/simpletypes-properties-string_pattern-metaenum.md +0 -15
- package/examples/docs/simpletypes-properties-string_pattern.md +0 -39
- package/examples/docs/simpletypes-properties-string_pattern_noexample.md +0 -25
- package/examples/docs/simpletypes-properties-string_pattern_singleexample.md +0 -31
- package/examples/docs/simpletypes-properties-string_unconstrained.md +0 -21
- package/examples/docs/simpletypes-properties-string_uri.md +0 -19
- package/examples/docs/simpletypes-properties-yesno.md +0 -15
- package/examples/docs/simpletypes.md +0 -455
- package/examples/docs/stabilizing-properties-id.md +0 -19
- package/examples/docs/stabilizing.md +0 -43
- package/examples/docs/subdir-allof-0.md +0 -43
- package/examples/docs/subdir-definitions-content-properties-id.md +0 -19
- package/examples/docs/subdir-definitions-content-properties.md +0 -15
- package/examples/docs/subdir-definitions-content.md +0 -43
- package/examples/docs/subdir-definitions.md +0 -15
- package/examples/docs/subdir.md +0 -55
- package/examples/docs/typearrays-properties-null.md +0 -15
- package/examples/docs/typearrays-properties-string-or-null.md +0 -15
- package/examples/docs/typearrays-properties-string-or-number-null.md +0 -15
- package/examples/docs/typearrays-properties-string-or-number.md +0 -15
- package/examples/docs/typearrays.md +0 -96
- package/examples/docsWithoutHeader/arrays.schema.md +0 -254
- package/examples/generated-schemas/abstract.schema.json +0 -1
- package/examples/generated-schemas/arrays.schema.json +0 -1
- package/examples/generated-schemas/complex.schema.json +0 -1
- package/examples/generated-schemas/constants.schema.json +0 -1
- package/examples/generated-schemas/custom.schema.json +0 -1
- package/examples/generated-schemas/deepextending.schema.json +0 -1
- package/examples/generated-schemas/definitions.schema.json +0 -1
- package/examples/generated-schemas/enums.schema.json +0 -1
- package/examples/generated-schemas/example.schema.json +0 -1
- package/examples/generated-schemas/examples.schema.json +0 -1
- package/examples/generated-schemas/extending.schema.json +0 -1
- package/examples/generated-schemas/extensible.schema.json +0 -1
- package/examples/generated-schemas/identifiable.schema.json +0 -1
- package/examples/generated-schemas/join.schema.json +0 -1
- package/examples/generated-schemas/nestedobj.schema.json +0 -1
- package/examples/generated-schemas/pattern.schema.json +0 -1
- package/examples/generated-schemas/simple.schema.json +0 -1
- package/examples/generated-schemas/simpletypes.schema.json +0 -1
- package/examples/generated-schemas/stabilizing.schema.json +0 -1
- package/examples/generated-schemas/subdir/subdir.schema.json +0 -1
- package/examples/generated-schemas/typearrays.schema.json +0 -1
- package/examples/schemas/abstract.schema.json +0 -44
- package/examples/schemas/arrays.schema.json +0 -185
- package/examples/schemas/complex.schema.json +0 -123
- package/examples/schemas/constants.schema.json +0 -25
- package/examples/schemas/custom.schema.json +0 -41
- package/examples/schemas/deepextending.schema.json +0 -37
- package/examples/schemas/definitions.description.md +0 -17
- package/examples/schemas/definitions.schema.json +0 -46
- package/examples/schemas/enums.schema.json +0 -42
- package/examples/schemas/example.example.1.json +0 -4
- package/examples/schemas/example.schema.json +0 -29
- package/examples/schemas/examples.example.1.json +0 -4
- package/examples/schemas/examples.example.2.json +0 -4
- package/examples/schemas/examples.schema.json +0 -32
- package/examples/schemas/extending.schema.json +0 -38
- package/examples/schemas/extensible.schema.json +0 -38
- package/examples/schemas/identifiable.schema.json +0 -22
- package/examples/schemas/join.schema.json +0 -88
- package/examples/schemas/nestedobj.schema.json +0 -35
- package/examples/schemas/pattern.schema.json +0 -21
- package/examples/schemas/simple.schema.json +0 -22
- package/examples/schemas/simpletypes.schema.json +0 -151
- package/examples/schemas/stabilizing.schema.json +0 -23
- package/examples/schemas/subdir/subdir.schema.json +0 -29
- package/examples/schemas/typearrays.schema.json +0 -39
- package/examples/status.md +0 -3
- package/test/api.test.js +0 -55
- package/test/cyclicSchemaIntegration.test.js +0 -87
- package/test/fixtures/additionalprops/additionalprops.schema.json +0 -6
- package/test/fixtures/additionalprops/arrays.schema.json +0 -9
- package/test/fixtures/arrays/arrays.schema.json +0 -201
- package/test/fixtures/arrays/tuple.schema.json +0 -35
- package/test/fixtures/content/html.schema.json +0 -5
- package/test/fixtures/content/jwt.schema.json +0 -26
- package/test/fixtures/content/png.schema.json +0 -6
- package/test/fixtures/cyclic/one.description.md +0 -1
- package/test/fixtures/cyclic/one.example.1.json +0 -1
- package/test/fixtures/cyclic/one.schema.json +0 -17
- package/test/fixtures/cyclic/three.schema.json +0 -17
- package/test/fixtures/cyclic/two.schema.json +0 -17
- package/test/fixtures/deadref/deadref.schema.json +0 -6
- package/test/fixtures/enums/arrayenums.schema.json +0 -29
- package/test/fixtures/enums/enums.schema.json +0 -29
- package/test/fixtures/example/example.schema.json +0 -52
- package/test/fixtures/format/format.schema.json +0 -25
- package/test/fixtures/identifiable/identifiable.schema.json +0 -22
- package/test/fixtures/not/not.schema.json +0 -7
- package/test/fixtures/null/null.schema.json +0 -14
- package/test/fixtures/nullable/array.schema.json +0 -17
- package/test/fixtures/readme-1/abstract.schema.json +0 -50
- package/test/fixtures/readme-1/complex.schema.json +0 -107
- package/test/fixtures/readme-1/simple.schema.json +0 -30
- package/test/fixtures/skipproperties/complete.schema.json +0 -29
- package/test/fixtures/stringformats/simpletypes.schema.json +0 -211
- package/test/fixtures/title/meta.schema.json +0 -53
- package/test/fixtures/type/button.schema.json +0 -28
- package/test/fixtures/type/type.schema.json +0 -20
- package/test/fixtures/types/merged.schema.json +0 -10
- package/test/fixtures/types/object.schema.json +0 -3
- package/test/fixtures/types/objectorarray.schema.json +0 -3
- package/test/fixtures/types/undefined.schema.json +0 -3
- package/test/fixtures/types/wrong.schema.json +0 -6
- package/test/formatting.test.js +0 -59
- package/test/markdownBuilder.test.js +0 -441
- package/test/readmeBuilder.test.js +0 -105
- package/test/schemaProxy.test.js +0 -187
- package/test/testUtils.js +0 -88
- package/test/testintegration.test.js +0 -65
- package/test/traverseSchema.test.js +0 -111
- package/test/zSchemaCoverage.test.js +0 -186
package/lib/markdownBuilder.js
CHANGED
|
@@ -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
|
-
|
|
13
|
-
map, list
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
root,
|
|
17
|
-
|
|
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
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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(
|
|
318
|
-
|
|
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(
|
|
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(
|
|
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 =
|
|
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;
|
package/lib/readmeBuilder.js
CHANGED
|
@@ -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
|
-
|
|
13
|
-
map, pipe, filter, list
|
|
14
|
-
}
|
|
15
|
-
|
|
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
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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;
|
package/lib/schemaProxy.js
CHANGED
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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.
|
|
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(
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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 =
|
|
193
|
+
const slugger = new GhSlugger();
|
|
192
194
|
|
|
193
|
-
return (
|
|
194
|
-
// console.log('loading',
|
|
195
|
-
const
|
|
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
|
|
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
|
-
|
|
35
|
+
export default symbols;
|
package/lib/traverseSchema.js
CHANGED
|
@@ -10,8 +10,10 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
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;
|
package/lib/writeMarkdown.js
CHANGED
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
|
58
|
+
const content = (!meta ? '' : '---\n')
|
|
35
59
|
+ (!meta ? '' : yaml.dump(meta))
|
|
36
60
|
+ (!meta ? '' : '---\n\n')
|
|
37
61
|
|
|
38
|
-
+ processor.stringify(
|
|
62
|
+
+ processor.stringify(markdownAst);
|
|
39
63
|
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
83
|
+
return output;
|
|
49
84
|
};
|
|
50
85
|
}
|
|
51
86
|
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
60
|
-
|
|
104
|
+
return (markdownAst) => {
|
|
105
|
+
// add YAML frontmatter
|
|
106
|
+
const content = (!meta ? '' : '---\n')
|
|
107
|
+
+ (!meta ? '' : yaml.dump(meta))
|
|
108
|
+
+ (!meta ? '' : '---\n\n')
|
|
61
109
|
|
|
62
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
124
|
+
return {
|
|
125
|
+
fileName,
|
|
126
|
+
fullPath,
|
|
127
|
+
markdownAst,
|
|
128
|
+
content,
|
|
79
129
|
};
|
|
80
|
-
}
|
|
81
|
-
return (args) => args;
|
|
82
|
-
}
|
|
130
|
+
};
|
|
83
131
|
}
|
|
84
|
-
|
|
85
|
-
module.exports = { writemarkdown, writereadme };
|
package/lib/writeSchema.js
CHANGED
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
import fs from 'fs-extra';
|
|
13
|
+
import path from 'path';
|
|
14
|
+
import s from './symbols.js';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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.
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
fileName,
|
|
63
|
+
fullPath,
|
|
64
|
+
content,
|
|
65
|
+
};
|
|
39
66
|
});
|
|
40
67
|
};
|
|
41
68
|
}
|
|
42
|
-
|
|
43
|
-
module.exports = { writeSchema };
|