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

Fix config schema #2393

Merged
merged 1 commit into from
Jan 16, 2025
Merged

Fix config schema #2393

merged 1 commit into from
Jan 16, 2025

Conversation

cristiklein
Copy link
Contributor

It seems like jsonschema2md ironically doesn't validate the schema of the input it receives. :)

It fails horribly with:

file:///home/cklein/elastisys/welkin/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:697
        ...schema[keyword`examples`].map((example) => paragraph(code('yaml', yaml.dump(example, undefined, 2)))),
                                     ^

TypeError: schema[keyword].map is not a function or its return value is not iterable
    at makeexamples (file:///home/cklein/elastisys/welkin/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:697:38)
    at file:///home/cklein/elastisys/welkin/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:762:14
    at Array.map (<anonymous>)
    at makeproplist (file:///home/cklein/elastisys/welkin/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:750:54)
    at file:///home/cklein/elastisys/welkin/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:831:16
    at Array.map (<anonymous>)
    at makedefinitions (file:///home/cklein/elastisys/welkin/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:818:10)
    at file:///home/cklein/elastisys/welkin/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:888:10
    at /home/cklein/elastisys/welkin/node_modules/ferrum/src/sequence.js:1234:12
    at /home/cklein/elastisys/welkin/node_modules/ferrum/src/sequence.js:807:5

I added console.log(schema[keywordexamples]); before the failing line and, long story short, it seems like jsonschema2md expects a list of examples and not a string.

Warning

This is a public repository, ensure not to disclose:

  • personal data beyond what is necessary for interacting with this pull request, nor
  • business confidential information, such as customer names.

What kind of PR is this?

See above

Required: Mark one of the following that is applicable:

  • kind/feature
  • kind/improvement
  • kind/deprecation
  • kind/documentation
  • kind/clean-up
  • kind/bug
  • kind/other

Optional: Mark one or more of the following that are applicable:

Important

Breaking changes should be marked kind/admin-change or kind/dev-change depending on type
Critical security fixes should be marked with kind/security

  • kind/admin-change
  • kind/dev-change
  • kind/security
  • [kind/adr](set-me)

What does this PR do / why do we need this PR?

...

  • Fixes #

Information to reviewers

I tested this PR as follows:

git clone --depth 1 [email protected]:elastisys/welkin
cd welkin
nodeenv .env
. .env/bin/activate
npm ci

# Next command generates schema documentation using this PR and does not fail
OVERRIDE_REF_NAME=ck/fix-schema ./scripts/jsonschema2md.sh 

# Next command generates schema documentation without this PR and fails
./scripts/jsonschema2md.sh

Checklist

  • Proper commit message prefix on all commits
  • Change checks:
    • The change is transparent
    • The change is disruptive
    • The change requires no migration steps
    • The change requires migration steps
    • The change updates CRDs
    • The change updates the config and the schema
  • Documentation checks:
  • Metrics checks:
    • The metrics are still exposed and present in Grafana after the change
    • The metrics names didn't change (Grafana dashboards and Prometheus alerts required no updates)
    • The metrics names did change (Grafana dashboards and Prometheus alerts required an update)
  • Logs checks:
    • The logs do not show any errors after the change
  • PodSecurityPolicy checks:
    • Any changed Pod is covered by Kubernetes Pod Security Standards
    • Any changed Pod is covered by Gatekeeper Pod Security Policies
    • The change does not cause any Pods to be blocked by Pod Security Standards or Policies
  • NetworkPolicy checks:
    • Any changed Pod is covered by Network Policies
    • The change does not cause any dropped packets in the NetworkPolicy Dashboard
  • Audit checks:
    • The change does not cause any unnecessary Kubernetes audit events
    • The change requires changes to Kubernetes audit policy
  • Falco checks:
    • The change does not cause any alerts to be generated by Falco
  • Bug checks:
    • The bug fix is covered by regression tests

It seems like jsonschema2md ironically doesn't validate the schema of the input
it receives. :)

It fails horribly with:

```
file:///home/cklein/elastisys/welkin/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:697
        ...schema[keyword`examples`].map((example) => paragraph(code('yaml', yaml.dump(example, undefined, 2)))),
                                     ^

TypeError: schema[keyword].map is not a function or its return value is not iterable
    at makeexamples (file:///home/cklein/elastisys/welkin/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:697:38)
    at file:///home/cklein/elastisys/welkin/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:762:14
    at Array.map (<anonymous>)
    at makeproplist (file:///home/cklein/elastisys/welkin/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:750:54)
    at file:///home/cklein/elastisys/welkin/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:831:16
    at Array.map (<anonymous>)
    at makedefinitions (file:///home/cklein/elastisys/welkin/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:818:10)
    at file:///home/cklein/elastisys/welkin/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:888:10
    at /home/cklein/elastisys/welkin/node_modules/ferrum/src/sequence.js:1234:12
    at /home/cklein/elastisys/welkin/node_modules/ferrum/src/sequence.js:807:5
```

I added `console.log(schema[keyword`examples`]);` before the failing line and,
long story short, it seems like jsonschema2md expects a list of examples and not
a string.
@cristiklein cristiklein added the kind/bug Something isn't working label Jan 14, 2025
@cristiklein cristiklein requested review from aarnq and a team January 14, 2025 16:14
@cristiklein cristiklein self-assigned this Jan 14, 2025
Copy link
Contributor

@aarnq aarnq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job finding it!
I'll take some time to containerise the generation and test it from here so we can avoid this in the future.

@cristiklein
Copy link
Contributor Author

Thanks @aarnq , both for the kind words and for thinking about how to avoid such issues in the future. 😄

@cristiklein cristiklein merged commit e3b815f into main Jan 16, 2025
12 checks passed
@cristiklein cristiklein deleted the ck/fix-schema branch January 16, 2025 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants