Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of meta:enum fails when one of the enum values is "enum" #458

Closed
schaze opened this issue Nov 13, 2022 · 3 comments · Fixed by #459
Closed

Use of meta:enum fails when one of the enum values is "enum" #458

schaze opened this issue Nov 13, 2022 · 3 comments · Fixed by #459

Comments

@schaze
Copy link

schaze commented Nov 13, 2022

Expected Behaviour

Using "meta:enum" to provide a map with descriptions of enum values should work for all possible values also the value "enum".

My guess is that the schema parser mistakes the "enum" map key for an actual "enum" JSON Schema keyword.

E.g. following example should work:

  "definitions": {
    "HomieDatatype": {
      "type": "string",
      "enum": [
        "integer",
        "float",
        "boolean",
        "string",
        "enum",
        "color",
        "datetime",
        "duration",
        "json"
      ],
      "title": "HomieDatatype",
      "description": "Specifies the datatype of the property value payload.",
      "meta:enum": {
        "integer": "TODO: describe",
        "float": "TODO: describe",
        "boolean": "TODO: describe.",
        "string": "TODO: describe",
        "enum": "TODO: describe",
        "color": "TODO: describe",
        "datetime": "TODO: describe",
        "duration": "TODO: describe",
        "json": "TODO: describe"
      }
    }
  }

Actual Behaviour

Generation fails with the following error:

...
...
generating markdown
file:///issue-example/utils/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:582
        ...schema[keyword`enum`].map((value) => tableRow([
                                 ^

TypeError: schema[keyword].map is not a function or its return value is not iterable
    at makeconstraintssection (file:///issue-example/utils/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:582:34)
    at file:///issue-example/utils/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:882:10
    at /issue-example/utils/node_modules/ferrum/src/sequence.js:1234:12
    at /issue-example/utils/node_modules/ferrum/src/sequence.js:807:5
    at each [CURRY] (/issue-example/utils/node_modules/ferrum/src/functional.js:240:12)
    at /issue-example/utils/node_modules/ferrum/src/sequence.js:1233:3
    at foldl [CURRY] (/issue-example/utils/node_modules/ferrum/src/functional.js:240:12)
    at file:///issue-example/utils/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:875:23
    at /issue-example/utils/node_modules/ferrum/src/functional.js:109:53
    at Array.reduce (<anonymous>)

Node.js v19.0.1
error Command failed with exit code 1.

Reproduce Scenario (including but not limited to)

Add a "meta:enum" description for an enum value with the actual value "enum".

Platform and Version

Node.js v19.0.1, "@adobe/jsonschema2md": "~7.1.2"

@trieloff trieloff added the bug label Nov 13, 2022
trieloff added a commit that referenced this issue Nov 14, 2022
trieloff pushed a commit that referenced this issue Nov 14, 2022
## [7.1.3](v7.1.2...v7.1.3) (2022-11-14)

### Bug Fixes

* **markdown-builder:** guard against `enum` being not an array ([aa46ac4](aa46ac4)), closes [#458](#458)
@trieloff
Copy link
Collaborator

🎉 This issue has been resolved in version 7.1.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@schaze
Copy link
Author

schaze commented Nov 16, 2022

Wow that was FAST! Thanks a lot. Works fine for me now (as already proven by your tests)!

@trieloff
Copy link
Collaborator

That one was easy, thanks to the test provided and the fact that there is an underlying systematic bug that causes jsonschema2md to trip up when JSON Schema keywords are used in unexpected places. I've fixed similar bugs before, so there wasn't much discovery involved.

Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants