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: support schema content with pathy fileName #522

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aloisklink
Copy link
Contributor

Prevent an ENOENT error when running jsonschema2md on a JSON Schema that doesn't exist on disk, yet has a pathy fileName.

Using a fileName that is a path is required to get working links to the schema.json file in the output Markdown.

Current behavior

The Public API with non-existent schema path works test (added in this PR) currently fails with the following error.

  1) Testing Public API
       Public API with non-existent schema path works:
     Error: /my-custom-path-to-schema/abstract.schema.json: ENOENT: no such file or directory, open '/my-custom-path-to-schema/abstract.schema.json'
      at Object.openSync (node:fs:601:3)
      at Object.readFileSync (node:fs:469:35)
      at Object.readFileSync (node_modules/jsonfile/index.js:50:22)
      at file:///home/alois/Documents/jsonschema2md/lib/writeSchema.js:42:22
      at Array.map (<anonymous>)
      at file:///home/alois/Documents/jsonschema2md/lib/writeSchema.js:36:24
      at jsonschema2md (file:///home/alois/Documents/jsonschema2md/lib/index.js:153:5)
      at Context.<anonymous> (file:///home/alois/Documents/jsonschema2md/test/api.test.js:103:20)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Background

I'm trying to simplify some code in https://github.com/mermaid-js/mermaid/blob/b87f1f209843ed794d83bfece5669adf595bdabd/packages/mermaid/scripts/docs.mts#L393-L420 to use the official import {jsonschema2md} from ... API, since it currently uses a bunch of internals.

Prevent an `ENOENT` error when running `jsonschema2md` on a JSON
Schema that doesn't exist on disk, yet has a pathy `fileName`.

Using a `fileName` that is a path is required to get working links
to the `schema.json` file in the output Markdown.
@codecov
Copy link

codecov bot commented Aug 2, 2023

Codecov Report

Merging #522 (7018c70) into main (119f517) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #522   +/-   ##
=======================================
  Coverage   99.75%   99.75%           
=======================================
  Files          11       11           
  Lines        2039     2039           
=======================================
  Hits         2034     2034           
  Misses          5        5           
Files Changed Coverage Δ
lib/writeSchema.js 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

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

Successfully merging this pull request may close these issues.

1 participant