CesiumGS / wetzel

Generate Markdown documentation from JSON Schema
Apache License 2.0
133 stars 54 forks source link

`WETZEL_WARNING: title not defined` - is this required for every definition? #61

Closed pengolod closed 2 years ago

pengolod commented 2 years ago

In http://json-schema.org/draft-07/schema# and co., it seems that the title key isn't required for creating a json schema, but I get title not defined as an error for wetzel trying to parse my schema..

Any help would be great! The files in question are at https://github.com/comp500/packwiz-spec/blob/master/schemas

pengolod commented 2 years ago

Would it be possible to use the key of the object as a fallback when no title is provided?

Eg:

"UpdateImplementation": {
      "description": "This interface defines no properties - it exists solely to restrict the possible update values to those that are intended as update implementations.",
      "type": "object"
    }

would render title as "UpdateImplementation"?

pengolod commented 2 years ago

Example error message:

3:04:24 PM: Error: Command failed: npm x -n wetzel ./packwiz-spec/schemas/pack.json > docs/reference/pack-format/pack-toml.md -n
3:04:24 PM: /opt/build/repo/node_modules/wetzel/lib/generateMarkdown.js:135
3:04:24 PM:             const item = style.getTOCLink(currentTitle.replace(parentTitle + " ", ""), typeName);
3:04:24 PM:                                                        ^
3:04:24 PM: TypeError: Cannot read properties of undefined (reading 'replace')
3:04:24 PM:     at getRecursiveTOC (/opt/build/repo/node_modules/wetzel/lib/generateMarkdown.js:135:56)
3:04:24 PM:     at getTableOfContentsMarkdown (/opt/build/repo/node_modules/wetzel/lib/generateMarkdown.js:109:23)
3:04:24 PM:     at generateMarkdown (/opt/build/repo/node_modules/wetzel/lib/generateMarkdown.js:65:15)
3:04:24 PM:     at Object.<anonymous> (/opt/build/repo/node_modules/wetzel/bin/wetzel.js:94:22)
3:04:24 PM:     at Module._compile (node:internal/modules/cjs/loader:1101:14)
3:04:24 PM:     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
3:04:24 PM:     at Module.load (node:internal/modules/cjs/loader:981:32)
3:04:24 PM:     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
3:04:24 PM:     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
3:04:24 PM:     at node:internal/main/run_main_module:17:47
3:04:24 PM:     at checkExecSyncError (node:child_process:826:11)
3:04:24 PM:     at execSync (node:child_process:900:15)
3:04:24 PM:     at /opt/build/repo/build.js:52:5 {
3:04:24 PM:   status: 1,
3:04:24 PM:   signal: null,
3:04:24 PM:   output: [
3:04:24 PM:     null,
3:04:24 PM:     Buffer(0) [Uint8Array] [],
3:04:24 PM:     Buffer(1074) [Uint8Array] [
3:04:24 PM:        47, 111, 112, 116,  47,  98, 117, 105, 108, 100,  47, 114,
3:04:24 PM:       101, 112, 111,  47, 110, 111, 100, 101,  95, 109, 111, 100,
3:04:24 PM:       117, 108, 101, 115,  47, 119, 101, 116, 122, 101, 108,  47,
3:04:24 PM:       108, 105,  98,  47, 103, 101, 110, 101, 114,  97, 116, 101,
3:04:24 PM:        77,  97, 114, 107, 100, 111, 119, 110,  46, 106, 115,  58,
3:04:24 PM:        49,  51,  53,  10,  32,  32,  32,  32,  32,  32,  32,  32,
3:04:24 PM:        32,  32,  32,  32,  99, 111, 110, 115, 116,  32, 105, 116,
3:04:24 PM:       101, 109,  32,  61,  32, 115, 116, 121, 108, 101,  46, 103,
3:04:24 PM:       101, 116,  84,  79,
3:04:24 PM:       ... 974 more items
3:04:24 PM:     ]
3:04:24 PM:   ],
3:04:24 PM:   pid: 1367,
3:04:24 PM:   stdout: Buffer(0) [Uint8Array] [],
3:04:24 PM:   stderr: Buffer(1074) [Uint8Array] [
3:04:24 PM:      47, 111, 112, 116,  47,  98, 117, 105, 108, 100,  47, 114,
3:04:24 PM:     101, 112, 111,  47, 110, 111, 100, 101,  95, 109, 111, 100,
3:04:24 PM:     117, 108, 101, 115,  47, 119, 101, 116, 122, 101, 108,  47,
3:04:24 PM:     108, 105,  98,  47, 103, 101, 110, 101, 114,  97, 116, 101,
3:04:24 PM:      77,  97, 114, 107, 100, 111, 119, 110,  46, 106, 115,  58,
3:04:24 PM:      49,  51,  53,  10,  32,  32,  32,  32,  32,  32,  32,  32,
3:04:24 PM:      32,  32,  32,  32,  99, 111, 110, 115, 116,  32, 105, 116,
3:04:24 PM:     101, 109,  32,  61,  32, 115, 116, 121, 108, 101,  46, 103,
3:04:24 PM:     101, 116,  84,  79,
3:04:24 PM:     ... 974 more items
3:04:24 PM:   ]
3:04:24 PM: }
3:04:24 PM: ​

LOC in question: https://github.com/CesiumGS/wetzel/blob/6871d36cc2249ae21776912f42c0e44edb7dc9a6/lib/generateMarkdown.js#L135-L135

emackey commented 2 years ago

I'm fairly sure this is happening because you don't have a top-level title. For example in pack.json, you could add a title on line 3:

    "title": "Pack",

Otherwise the title must be inferred from the filename, which might end in .json or in .schema.json or might be something else entirely.

I'd prefer not to guess the title from the filename, because these titles end up in important places in the TOC and as anchor link names. So I think titles should be added at the tops of the schema files.

pengolod commented 2 years ago

I've ended up using https://github.com/grafana/json-schema-markdown as an alternative, but all the best to you and your project!

emackey commented 2 years ago

Thanks!