-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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 JSON Schema to define and document MermaidConfig
#4112
Use JSON Schema to define and document MermaidConfig
#4112
Conversation
7425775
to
430830a
Compare
Git force push changesI've You can use the following command to view the changes (GitHub's UI isn't great for viewing the difference between two patch series): git range-diff fec193ebaf85403e3bc8031d79b4f593a5db1c31..74257756fc7e1fc773aca1c882a47c17c2b80cae 8b5cb75ef70ee1ccc66373cadffae7e5e7425213..430830ada64cc3d8e79fb5c15213f8ca964bbf7b Main changes:
Rely to #4112 (comment)
Perhaps it's a bit too wordy though :) Maybe I need to ask ChatGPT to summarize it for me, hahaha. Unfortunately, I couldn't really figure out a way to split this up into smaller PRs. The markdown that is generated creates it as a code-block: ```txt
https://mermaid-js.github.io/schemas/config.schema.json
``` To be honest, we could make it into a clickable URL, but I'm not sure we should, since @adobe/jsonschema2md might have a good reason to make it into a code block (feel free to view example I think it might be because you're never expected to click on it (it's just an ugly JSON file), it's mainly just used as a unique ID, or for programs to download the schema. See https://aloisklink.com/mermaid/schemas/config.schema.json for an example of what the file looks like (I've pretty-printed it to make it look nicer). Apparently, Vitepress wasn't bundling
Awesome, that will be something to discuss/fix in the next PR (it should be a separate discussion, since previous changes to |
Git force push changesI've You can use the following command to view the changes (GitHub's UI isn't great for viewing the difference between two patch series): git range-diff 8b5cb75ef70ee1ccc66373cadffae7e5e7425213..430830ada64cc3d8e79fb5c15213f8ca964bbf7b 7647ae317a7b2130e32777248d25a9c4d24b8f9f..049d1c13d3d91614490bac2d1c023998cc411227 Changes (found by running
Edit: Fixed broken links and wrong formatting that was making CI fail. |
4a69226
to
049d1c1
Compare
This looks great! Good job @aloisklink! |
I've fixed merge conflicts in the It looks like we have a Line 3 in e4d2118
However, renovate seems to ignore this setting, so it's constantly converting our Edit: I've made a PR to fix this, see #4249 Is it worth getting a review from @ashishjain0512 too (maybe not a full review, but at least making sure they're okay with using a new method to declare the default values, types, and documentation for MermaidConfig)? They seem to be the main other @mermaid-js member that has edited these files. |
What is the status on this? |
dbe5255
to
0477a9f
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## develop #4112 +/- ##
===========================================
+ Coverage 69.82% 77.26% +7.43%
===========================================
Files 143 143
Lines 16489 14455 -2034
Branches 518 516 -2
===========================================
- Hits 11513 11168 -345
+ Misses 4848 3182 -1666
+ Partials 128 105 -23
Flags with carried forward coverage won't be shown. Click here to find out more.
|
0477a9f
to
8542365
Compare
Sorry for the delay! Since this is a pretty big PR the changes how the MermaidConfig is defined, fixing merge conflicts is a bit of a pain. IMO, since this PR has been open for a while, I guess anybody who wanted to review it already has. Anybody mind if I go ahead and merge this after PR #4580 gets merged? I've git range-diff 7647ae317a7b2130e32777248d25a9c4d24b8f9f..049d1c13d3d91614490bac2d1c023998cc411227 9c011abbd424641172b696c038490a36ec99c518..85423656fe46edc1461893c62d9c01677be4688e Changes:
|
@nirname, feels like it should be true, any reason for setting false as the default? |
I just want to point out something: these changes would work fine with the current approach, but they're most likely to break or change when applying the stuff discussed in #4499, i.g., moving types from |
Currently, shiki doesn't support code-blocks that use the regexp language, which means vitepress throws an error on them: ```regexp ^([1-9][0-9]*)(minute|hour|day|week|month)$ ``` As a hack until shiki supports them, I've just modified them to get converted into JavaScript RegEx literal code-blocks, e.g.: ```javascript /^([1-9][0-9]*)(minute|hour|day|week|month)$/ ```
Add a JSON Schema file (in YAML) for the MermaidConfig. This JSON Schema file follows [JSON Schema 2019-09][1], with some slight modifications to work with: - [json-schema-to-typescript][2] The `tsType` keyword is used to override the generated TypeScript type, when it doesn't match the JSON Schema type. This is used in two cases: - when the current type cannot be represented in JSON Schema (e.g. `FontCalculator`, which is a function) - when the JSON Schema type is narrower than the TypeScript type. Currently, many enums types are listed as `string` in TypeScript, but json-schema-to-typescript converts them to `"val1" | "val2"`. I've manually set them to `string | "val1" | "val2"` to avoid causing a breaking change in the TypeScript types. We should remove these in a future major version of TypeScript. - [@adobe/jsonschema2md][3] The `meta:enum` keyword is used to add documentation for specific enum values. [1]: https://json-schema.org/draft/2019-09/release-notes.html [2]: https://www.npmjs.com/package/json-schema-to-typescript [3]: https://www.npmjs.com/package/@adobe/jsonschema2md
Adds a vitepress JsonSchema plugin that automatically loads the Mermaid Config JSON Schema from a .schema.yaml file and gets the default values from it.
Automatically build documentation for JSON Schema. This is only built when running with `--vitepress`, as it currently produces loads of markdown files, which I feel like we shouldn't be committing. This currently manually uses some internal `jsonschema2md` functions so that we can manually control the Markdown output.
Add script `packages/mermaid/scripts/create-types-from-json-schema.mts` to automatically generate the TypeScript definition for `MermaidConfig` from the `MermaidConfig` JSON Schema at `packages/mermaid/src/schemas/config.schema.yaml`. To do this, we are using this library [`json-schema-to-typescript`][1], which is also used by Webpack to generate their types from their JSON Schema. In order to make sure that this isn't a breaking change, the script makes all fields **optional**, as that is what the original typescript file has. Additionally, I've put in some custom logic into the script, so that the exact same order is used for the TypeScript file, to make the `git diff` easier to review. In the future, we can remove this custom logic, once we no longer need to worry about `git merge` conflicts. [1]: https://github.com/bcherny/json-schema-to-typescript
Runs `pnpm --filter mermaid run types:build-config` to automatically generate typescript types for `MermaidConfig` from the JSON Schema file.
Adds a temporary test to ensure that the new defaultConfig, generated by Vite automatically from the `MermaidConfig` JSON Schema, has the same values as the old defaultConfig (taken from https://github.com/mermaid-js/mermaid/blob/38013de7114966e8b1a83396703ef8158bb34466/packages/mermaid/src/defaultConfig.ts) The only minor difference seems to be that: - `gitGraph` now has a default `useMaxWidth: false` option (previously used to be `undefined`), - `class` now has a `htmlLabels` value of `false` instead of `undefined`.
Add a CI check that runs `pnpm run --filter mermaid types:verify-config` and checks whether the MermaidConfig TypeScript types are in sync with the MermaidConfig JSON Schema.
Fix the link in some Mermaid Config markdown documentation, which previously pointed to `src/schemas/config.schema.yaml`, which went nowhere. Now, these links point to: - config.schema.json (i.e. the generated JSON file, not YAML) - links are relative to the markdown documentation We also needed to store the `schema.json` file in the Vitepress `public/` folder, as Vitepress otherwise doesn't bundle `.json` files properly, when running `vitepress build src/vitepress`.
8542365
to
c29088a
Compare
I've git range-diff 9c011abbd424641172b696c038490a36ec99c518..0477a9f68a8d6f474dc792d430ca892d1aa41b66 c742ac71a4f59455ce3dc0b6ac56d5f9b2baa4d2..c29088af019a8180ac2f85d79b890cab4cd5fee5 Changes:
We could have a separate
Honestly, it would be even better to split things up. The current |
Sorry for accidentally closing this PR (it's my fault, not @sidharthv96!) I wrote |
Yeah, splitting might be the way to go. I'm not saying to drop I likes the idea of |
* develop: test: test partial QuadrantChartConfig options test: fix types in `config.spec.ts` style: fix lint issues in src/config.spec.ts test: rename src/config.spec.js to config.spec.ts fix lint update homepage community link docs(flowchart): add documentation on multiple nodes style Add docker-specific command, leave commonly used command intact Support docs:dev in docker Fix lint. Update docs add ChatGPT plugin blog post Fix flowchart tooltip typing
I love the split config idea. Let's do it in another PR. |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [mermaid](https://togithub.com/mermaid-js/mermaid) | [`10.2.4` -> `10.3.0`](https://renovatebot.com/diffs/npm/mermaid/10.2.4/10.3.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/mermaid/10.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/mermaid/10.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/mermaid/10.2.4/10.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/mermaid/10.2.4/10.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>mermaid-js/mermaid (mermaid)</summary> ### [`v10.3.0`](https://togithub.com/mermaid-js/mermaid/releases/tag/v10.3.0): 10.3.0 [Compare Source](https://togithub.com/mermaid-js/mermaid/compare/v10.2.4...v10.3.0) #### What's Changed ##### Features - Sankey diagrams by [@​nirname](https://togithub.com/nirname) in [https://github.com/mermaid-js/mermaid/pull/4502](https://togithub.com/mermaid-js/mermaid/pull/4502) - Feature/1838 actor creation destruction by [@​Valentine14th](https://togithub.com/Valentine14th) in [https://github.com/mermaid-js/mermaid/pull/4466](https://togithub.com/mermaid-js/mermaid/pull/4466) - Vertical branches in Git Diagram by [@​mastersibin](https://togithub.com/mastersibin) in [https://github.com/mermaid-js/mermaid/pull/4639](https://togithub.com/mermaid-js/mermaid/pull/4639) - Use JSON Schema to define and document `MermaidConfig` by [@​aloisklink](https://togithub.com/aloisklink) in [https://github.com/mermaid-js/mermaid/pull/4112](https://togithub.com/mermaid-js/mermaid/pull/4112) - Remove the test checking whether the JSON Schema default config matched the old default config by [@​aloisklink](https://togithub.com/aloisklink) in [https://github.com/mermaid-js/mermaid/pull/4610](https://togithub.com/mermaid-js/mermaid/pull/4610) - Fixes support of the macro `ContainerQueue_Ext` for C4 diagrams definition. by [@​kislerdm](https://togithub.com/kislerdm) in [https://github.com/mermaid-js/mermaid/pull/4577](https://togithub.com/mermaid-js/mermaid/pull/4577) ##### Bugfixes - Make quadrant chart options TypeScript types optional by [@​aloisklink](https://togithub.com/aloisklink) in [https://github.com/mermaid-js/mermaid/pull/4602](https://togithub.com/mermaid-js/mermaid/pull/4602) - Remove double parsing by [@​nirname](https://togithub.com/nirname) in [https://github.com/mermaid-js/mermaid/pull/4587](https://togithub.com/mermaid-js/mermaid/pull/4587) - Fix flowchart tooltip typing bug by [@​lishid](https://togithub.com/lishid) in [https://github.com/mermaid-js/mermaid/pull/4562](https://togithub.com/mermaid-js/mermaid/pull/4562) - Bug/4590 allow notes identical to keywords by [@​ibrahimWassouf](https://togithub.com/ibrahimWassouf) in [https://github.com/mermaid-js/mermaid/pull/4597](https://togithub.com/mermaid-js/mermaid/pull/4597) - feat: allow specifying on which weekday a tickInterval should start by [@​leinelissen](https://togithub.com/leinelissen) in [https://github.com/mermaid-js/mermaid/pull/4634](https://togithub.com/mermaid-js/mermaid/pull/4634) - Split formatted markdown strings with unicode support. by [@​sidharthv96](https://togithub.com/sidharthv96) in [https://github.com/mermaid-js/mermaid/pull/4470](https://togithub.com/mermaid-js/mermaid/pull/4470) - fix: Mind maps handles `-` signs in node ids/text by [@​knsv](https://togithub.com/knsv) ##### Chores - Remove all TypeScript enums and forbid them in ESLint by [@​aloisklink](https://togithub.com/aloisklink) in [https://github.com/mermaid-js/mermaid/pull/4580](https://togithub.com/mermaid-js/mermaid/pull/4580) - refactor accessibility by [@​Yokozuna59](https://togithub.com/Yokozuna59) in [https://github.com/mermaid-js/mermaid/pull/4551](https://togithub.com/mermaid-js/mermaid/pull/4551) - chore: Reduce codecov pushes by [@​sidharthv96](https://togithub.com/sidharthv96) in [https://github.com/mermaid-js/mermaid/pull/4604](https://togithub.com/mermaid-js/mermaid/pull/4604) - Run PR-labeler-config-validator only if config changes by [@​sidharthv96](https://togithub.com/sidharthv96) in [https://github.com/mermaid-js/mermaid/pull/4607](https://togithub.com/mermaid-js/mermaid/pull/4607) - chore(deps): update all minor dependencies (minor) by [@​renovate](https://togithub.com/renovate) in [https://github.com/mermaid-js/mermaid/pull/4624](https://togithub.com/mermaid-js/mermaid/pull/4624) - Update all patch dependencies (patch) by [@​renovate](https://togithub.com/renovate) in [https://github.com/mermaid-js/mermaid/pull/4566](https://togithub.com/mermaid-js/mermaid/pull/4566) - Update all patch dependencies (patch) by [@​renovate](https://togithub.com/renovate) in [https://github.com/mermaid-js/mermaid/pull/4581](https://togithub.com/mermaid-js/mermaid/pull/4581) - Rename workflow jobs by [@​sidharthv96](https://togithub.com/sidharthv96) in [https://github.com/mermaid-js/mermaid/pull/4574](https://togithub.com/mermaid-js/mermaid/pull/4574) - Removed unused code in state diagrams by [@​nirname](https://togithub.com/nirname) in [https://github.com/mermaid-js/mermaid/pull/4631](https://togithub.com/mermaid-js/mermaid/pull/4631) - chore(deps): update all patch dependencies (patch) by [@​renovate](https://togithub.com/renovate) in [https://github.com/mermaid-js/mermaid/pull/4623](https://togithub.com/mermaid-js/mermaid/pull/4623) - chore: remove unused `devDependency` on coveralls by [@​aloisklink](https://togithub.com/aloisklink) in [https://github.com/mermaid-js/mermaid/pull/4641](https://togithub.com/mermaid-js/mermaid/pull/4641) - Allow entity diagram attribute names to start with asterisk by [@​ibrahimWassouf](https://togithub.com/ibrahimWassouf) in [https://github.com/mermaid-js/mermaid/pull/4588](https://togithub.com/mermaid-js/mermaid/pull/4588) - Bug/4592 fix new line padding class diagram by [@​ibrahimWassouf](https://togithub.com/ibrahimWassouf) in [https://github.com/mermaid-js/mermaid/pull/4633](https://togithub.com/mermaid-js/mermaid/pull/4633) - Fix graph not loading when the img loads too fast or fail to load by [@​pierrickouw](https://togithub.com/pierrickouw) in [https://github.com/mermaid-js/mermaid/pull/4496](https://togithub.com/mermaid-js/mermaid/pull/4496) - convert `cypress/helpers/util.js` to ts by [@​Yokozuna59](https://togithub.com/Yokozuna59) in [https://github.com/mermaid-js/mermaid/pull/4552](https://togithub.com/mermaid-js/mermaid/pull/4552) - build(deps-dev): bump word-wrap from 1.2.3 to 1.2.4 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/mermaid-js/mermaid/pull/4652](https://togithub.com/mermaid-js/mermaid/pull/4652) - chore(deps): update all minor dependencies (minor) by [@​renovate](https://togithub.com/renovate) in [https://github.com/mermaid-js/mermaid/pull/4663](https://togithub.com/mermaid-js/mermaid/pull/4663) - chore(deps): update all patch dependencies (patch) by [@​renovate](https://togithub.com/renovate) in [https://github.com/mermaid-js/mermaid/pull/4662](https://togithub.com/mermaid-js/mermaid/pull/4662) ##### Documentation - Sankey: Remove duplicated examples by [@​nirname](https://togithub.com/nirname) in [https://github.com/mermaid-js/mermaid/pull/4595](https://togithub.com/mermaid-js/mermaid/pull/4595) - Release docs by [@​sidharthv96](https://togithub.com/sidharthv96) in [https://github.com/mermaid-js/mermaid/pull/4493](https://togithub.com/mermaid-js/mermaid/pull/4493) - Update latest news section by [@​huynhicode](https://togithub.com/huynhicode) in [https://github.com/mermaid-js/mermaid/pull/4495](https://togithub.com/mermaid-js/mermaid/pull/4495) - Fix Typo by [@​ryru](https://togithub.com/ryru) in [https://github.com/mermaid-js/mermaid/pull/4567](https://togithub.com/mermaid-js/mermaid/pull/4567) - Docs: add ChatGPT plugin blog post by [@​huynhicode](https://togithub.com/huynhicode) in [https://github.com/mermaid-js/mermaid/pull/4570](https://togithub.com/mermaid-js/mermaid/pull/4570) - Fix relative link to theme variables list by [@​ibrahimWassouf](https://togithub.com/ibrahimWassouf) in [https://github.com/mermaid-js/mermaid/pull/4573](https://togithub.com/mermaid-js/mermaid/pull/4573) - Fix docs:dev by [@​sidharthv96](https://togithub.com/sidharthv96) in [https://github.com/mermaid-js/mermaid/pull/4598](https://togithub.com/mermaid-js/mermaid/pull/4598) - Docs: update link - "Join the Community" by [@​huynhicode](https://togithub.com/huynhicode) in [https://github.com/mermaid-js/mermaid/pull/4601](https://togithub.com/mermaid-js/mermaid/pull/4601) - Support docs:dev in docker by [@​nirname](https://togithub.com/nirname) in [https://github.com/mermaid-js/mermaid/pull/4599](https://togithub.com/mermaid-js/mermaid/pull/4599) - docs(flowchart): add documentation on multiple nodes style by [@​tomperr](https://togithub.com/tomperr) in [https://github.com/mermaid-js/mermaid/pull/4600](https://togithub.com/mermaid-js/mermaid/pull/4600) - Avoid downloading avtars everytime on docs:dev by [@​sidharthv96](https://togithub.com/sidharthv96) in [https://github.com/mermaid-js/mermaid/pull/4603](https://togithub.com/mermaid-js/mermaid/pull/4603) - docs: Fix checkbox syntax by [@​guilhermgonzaga](https://togithub.com/guilhermgonzaga) in [https://github.com/mermaid-js/mermaid/pull/4646](https://togithub.com/mermaid-js/mermaid/pull/4646) - Fix the "Edit this page on GitHub" link in Vitepress documentation for the Mermaid Config pages by [@​aloisklink](https://togithub.com/aloisklink) in [https://github.com/mermaid-js/mermaid/pull/4640](https://togithub.com/mermaid-js/mermaid/pull/4640) - Support MERMAID_RELEASE_VERSION in docs. by [@​sidharthv96](https://togithub.com/sidharthv96) in [https://github.com/mermaid-js/mermaid/pull/4612](https://togithub.com/mermaid-js/mermaid/pull/4612) - Docs: update Latest News section by [@​huynhicode](https://togithub.com/huynhicode) in [https://github.com/mermaid-js/mermaid/pull/4655](https://togithub.com/mermaid-js/mermaid/pull/4655) - added Typora to integrations list by [@​kgilbert78](https://togithub.com/kgilbert78) in [https://github.com/mermaid-js/mermaid/pull/4666](https://togithub.com/mermaid-js/mermaid/pull/4666) - Docs: Corrects name of C4 link by [@​Incognito](https://togithub.com/Incognito) in [https://github.com/mermaid-js/mermaid/pull/4660](https://togithub.com/mermaid-js/mermaid/pull/4660) - Fix a typo by [@​gjtorikian](https://togithub.com/gjtorikian) in [https://github.com/mermaid-js/mermaid/pull/4396](https://togithub.com/mermaid-js/mermaid/pull/4396) #### New Contributors - [@​ryru](https://togithub.com/ryru) made their first contribution in [https://github.com/mermaid-js/mermaid/pull/4567](https://togithub.com/mermaid-js/mermaid/pull/4567) - [@​ibrahimWassouf](https://togithub.com/ibrahimWassouf) made their first contribution in [https://github.com/mermaid-js/mermaid/pull/4573](https://togithub.com/mermaid-js/mermaid/pull/4573) - [@​kislerdm](https://togithub.com/kislerdm) made their first contribution in [https://github.com/mermaid-js/mermaid/pull/4577](https://togithub.com/mermaid-js/mermaid/pull/4577) - [@​leinelissen](https://togithub.com/leinelissen) made their first contribution in [https://github.com/mermaid-js/mermaid/pull/4634](https://togithub.com/mermaid-js/mermaid/pull/4634) - [@​pierrickouw](https://togithub.com/pierrickouw) made their first contribution in [https://github.com/mermaid-js/mermaid/pull/4496](https://togithub.com/mermaid-js/mermaid/pull/4496) - [@​mastersibin](https://togithub.com/mastersibin) made their first contribution in [https://github.com/mermaid-js/mermaid/pull/4639](https://togithub.com/mermaid-js/mermaid/pull/4639) - [@​kgilbert78](https://togithub.com/kgilbert78) made their first contribution in [https://github.com/mermaid-js/mermaid/pull/4666](https://togithub.com/mermaid-js/mermaid/pull/4666) - [@​Incognito](https://togithub.com/Incognito) made their first contribution in [https://github.com/mermaid-js/mermaid/pull/4660](https://togithub.com/mermaid-js/mermaid/pull/4660) - [@​gjtorikian](https://togithub.com/gjtorikian) made their first contribution in [https://github.com/mermaid-js/mermaid/pull/4396](https://togithub.com/mermaid-js/mermaid/pull/4396) **Full Changelog**: mermaid-js/mermaid@v10.2.4...v10.3.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/levaintech/contented). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMS4wIiwidXBkYXRlZEluVmVyIjoiMzYuMTEuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
📑 Summary
Currently, the
MermaidConfig
definition is a bit broken.packages/mermaid/src/defaultConfig.ts
.packages/mermaid/src/defaultConfig.ts
.However, it uses documentationjs, which is broken with our current workflow, and has been removed from the Mermaid website since we migrated to Vitepress (see 9468bff).
packages/mermaid/src/config.type.ts
, but the types often conflict with the types described by the documentation.This PR proposes instead moving as much as possible into a JSON Schema definition.
From a JSON Schema file, we can:
This has been added in f9d3d53.
MermaidConfig
stricter, but that will be a breaking change, so it might need to wait for Mermaid v11.undefined
andfunction
are still located indefaultConfig.ts
.defaultConfig
is the same as the newdefaultConfig
. This test can begit revert
-ed once this PR is merged, and there is no risk of merge conflicts.(i.e. like what eslint uses for plugins)
(not in this PR, since it will be a breaking change).
Before (broken)
Two files to edit (
defaultConfig.ts
andconfig.types.ts
) with broken documentation.After
One file to edit (
schemas/config.schema.yaml
JSON Schema) that auto-generatesdefaultConfig.ts
,config.types.ts
, and documentation.📏 Design Decisions
packages/mermaid/src/docs.mts
script as the rest of the markdown documentation. However, I've decided to only put it in Vitepress, and not in thedocs/
folder, mainly because it creates 100s of files, which slows downgit
, and would make this PR massive.packages/mermaid/src/config.type.ts
definition is backwards compatible with the old one. This however, has some issues:securityLevel
are changed from astring
/number
to an enum. (e.g.securityLevel
type is"strict" | "loose" | "antiscript" | "sandbox"
). To ensure backwards compatibility, I've added a| string
to them, but in the future, they should probably just be anenum
.required
, should be a required type. In the future, we should mark these as required inMermaidConfig
, and change functions likesetConfig()
to only accept aPartial<MermaidConfig>
.git diff
simpler, the script that generatespackages/mermaid/src/defaultConfig.ts
has some custom code to make sure everything is output in the same order as it was before. We can delete this bit later, once we no longer need to worry aboutgit merge
conflicts.packages/mermaid/scripts/create-types-from-json-schema.mjs
script I wrote is a bit hacky.packages/mermaid/src/docs.mts
, so that both of these scripts can re-use the same code and functions.MermaidConfig
TypeScript file, but also uses theMermaidConfig
TypeScript file. We may want to fix this in the future.packages/mermaid/src/defaultConfig.ts
:pnpm run build
orpnpm run test
from thedefault:
keys in the JSON Schema, by the custom.vite/jsonSchemaPlugin.ts
file I made, that uses ajv to get the default values.{"key": "bar"}
instead of{key: "bar"}
). It's probably not worth changing.gitGraph.useMaxWidth
isundefined
. I've changed this tofalse
in my implementation.However, every other diagram uses
true
, so should we also setgitGraph.useMaxWidth
totrue
?undefined
, which isn't a valid JSON type,so we can't put their default values into the JSON Schema.
Can we instead make their default values
null
?Generated Documentation Preview
See https://aloisklink.com/mermaid/config/schema-docs/config.html if you want to explore the docs yourself.
📋 Tasks
Make sure you
develop
branchdevelop
andrelease/10.0.0
, so that this PR should also merge cleanly into therelease/10.0.0
branch.However, since this PR is pretty big, it can wait until after v10.0.0, especially since this PR doesn't yet have any breaking changes.
It's probably worth asking most of the core contributors if they'd be comfortable writing in JSON Schema, instead of modifying
defaultConfig.ts
/config.types.ts
.