If you have questions about the library, found a bug or want to suggest a feature, please create an issue.
Documentation website is available here. Please note that its source code is not in the repo yet. Our docs are still coupled to Remote's internal Design System and integration tests. The effort to decouple it at the moment is too high. Please refer to this section for details about how the library works.
-
Clone the repository including submodules with the
--recursiveoptiongit clone https://github.com/remoteoss/json-schema-form.git --recursive
If you already cloned the repository without the submodules, you can initialize and update them with:
git submodule update --init
-
Install dependencies. You must use
pnpmpnpm install
This project requires Node.js LTS v22.13.1.
We recommend using the exact version specified in .nvmrc:
Navigate to the "next" folder and run:
Troubleshooting: If your node version doesn't match, use nvm or another version manager to use the correct version.
# Check your Node version
node -v
## Update the version to match `.nvmrc`. For example, using `nvm`
nvm use
# If needed, check where Node comes from. Might be different from your version manager (eg `nvm`).
which nodeWithout the correct Node.js version and ``�pnpm`, tests and other development tasks will likely fail.
Submit your branch pointing to main.
Please, always add tests to your bug fixes and new features.
To execute the library, run:
pnpm devTo run the test suite (including the ones from the Official JSON-schema suite), run:
pnpm testOr run the tests in watch mode:
pnpm test:watchYou can also run a single test file with:
pnpm test:file path/to/fileThe simplest way to test your local changes is to run the dev script — this re-generates a dist folder whenever a file is changed.
Once you have a dist folder being created, you can either:
- Option A: Point your local project import to the
distfolder.
- import { createHeadlessForm } from '@remoteoss/json-schema-form'
+ import { createHeadlessForm } from '../../path/to/repo/json-schema-form/dist'- Option B: Use the
linkcommand of your project package manager tool to symlink the package build to your project'snode_modules, e.g. npm link or yarn link. For example, withnpm:
# in json-schema-form repo:
$ npm link
# cd to your project
$ npm link @remoteoss/json-schema-form
# Run npm unlink --no-save @remoteoss/json-schema-form to remove the local symlinkIf you need a public release (for example, to run it on your project CI), you can publish a dev release.
Note that only core maintainers can publish public releases. If needed, ask us in the PR and we'll do it for you. Check PR #3 for the video walkthrough.
- Locally run the script
pnpm run release:dev patchorpnpm run release:dev minordepending on your changes.- You'll be shown what's the new version and prompt you if it's correct. Eg
Creating a new dev... :: Current version: 1.0.0 :::::: New version: 1.0.1-dev.20230516175718 Ready to commit and publish it? (y/n) - Then it will ask for the
@remoteossOTP for the NPM access to publish it. - Done! 🎉
- You'll be shown what's the new version and prompt you if it's correct. Eg
Every dev release is tagged as dev, which means it won't be automatically installed in your project by default.
You must specify the exact version, for example:
pnpm i -S @remoteoss/json-schema-form@1.0.1-dev.20230516-175718You can create as many dev releases as you need during the PRs, by running the same command.
A PR needs all CI checks to pass.
By default, prefer to "Squash and Merge" giving it a message that follows the Conventional Commits.
- <type>[optional scope]: <description>
- feat(parser): add ability to parse arraysThe final release is done after merge.
-
Checkout
mainand pull the latest commit -
Depending if you want a
patchorminor, run the commandpnpm run release patchorpnpm run release minor.-
You'll be shown what's the new version and prompt you if it's correct. Eg
Creating a new version... :: Current version: 1.0.0-beta.0 :::::: New version: 1.1.0-beta.0 Ready to commit and publish it? (y/n) -
Then it will update the CHANGELOG using generate-changelog. You may change it if needed, before going to the next step.
-
Finally, it will ask for the
@remoteossOTP for the NPM access to publish it. -
Done! A new release is published on NPM! 🎉
-
-
Create a new Github Release.
- Choose the tag matching the newest version.
- Leave the title empty
- Copy the new part of the CHANGELOG to the description.
This is a high level overview of how the library works and what its main components are.
The code is organized into clear, focused modules to provide a clear separation of concerns and allow us to unit test each individual part of the library.
src/index.tsre-exportscreateHeadlessForm&modifySchemasrc/form.tsdefinescreateHeadlessFormthe main entry point to the library and orchestrates field generation and validation
src/field/schema.tsimplements generation of fields that can be used to build user interfaces frombuildFieldSchemais the main function that builds a field for any given schema, we assume that the root schema is always of typeobject- The rest of this modules implements helper functions for mapping the different schema types to corresponding fields
src/validation/schema.tsprovides thevalidateSchemafunction which can validate a JSON value against a given schema and returns validation errors in the form ofValidationError[]validateSchemacalls all type or keyword specific validation functions such asvalidateObject,validateArray,validateString,validateAnyOf,validateCondition, etc. and combine their returned validation errors- Those validation functions apply their validation logic when needed or simply return
[] - When those functions need to validate a nested schema or
subschemaas the spec calls it, they recursively callvalidateSchema
src/errors/index.tsdefines theValidationErrortype return from the validation functionssrc/errors/messages.tsdefinesgetErrorMessagewhich translates validation errors into human readable error messages which can be shown in a UI, these error messages are returned when callinghandleValidationon a form as part of theValidationResult
createHeadlessForm takes an options object with three properties: CreateHeadlessFormOptions
initialValuesvalues to be used when initially rendering a formstrictInputTypewhen true, each['x-jsf-presentation'].inputTypemust be present for each schema propertyvalidationOptionsan object that specifies options specific to validation, these options are here mainly for dragon and are disabled by defaulttreatNullAsUndefined- when true, a
nullvalue will be considered absent when validated against a schema - per the json-schema spec
nullis a perfectly valid value that can be validated, for example with a schema like{ "type": "null" }that only allows anullvalue - providing a
nullvalue to a schema like{ "type": "string" }should result in a validation error as the value’s type does not match - json-schema-form v0 does not return this error and all our forms rely on this, form fields that have not been filled, even hidden ones, will cause
nullvalues to be passed which would result in validation errors in nearly every form - dragon’s
useCreateHeadlessFormhook enables this option by default
- when true, a
allowForbiddenValues- when true, validating a value against a
falseschema will not result in a validation error - when validating any value against a schema that is
falsethe json-schema spec says that this is a validation error, asfalsemeans “you must not provide a value to this schema” - we frequently use
falseschemas when we conditionally hide properties by setting them tofalse - as mentioned above, dragon passes
nullvalues for hidden fields tohandleValidate - dragon’s
useCreateHeadlessFormhook enables this option by default
- when true, validating a value against a
This project uses zizmor to audit GitHub Actions workflows for security issues. The audit runs automatically in CI when workflow files are modified.
To run the audit locally, you'll need to install zizmor:
macOS/Linux (via Homebrew):
brew install zizmorVia Cargo:
cargo install zizmorOnce installed, you can run the audit commands:
# Audit workflows
pnpm run lint:workflows
# Audit and auto-fix issues
pnpm run lint:workflows:fixNote: Installing zizmor is optional for development unless you're modifying GitHub Actions workflow files.