-
Notifications
You must be signed in to change notification settings - Fork 54
Add JSON schema #1426
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
Add JSON schema #1426
Changes from 19 commits
245e19d
a860269
4c957b4
a510957
facfa15
3749056
ba3f5b1
a719bb6
3a5fc19
334f2d5
90ce201
779cf12
f6b1f24
f18a88b
5e4a870
252c0d4
65aa12d
83ed23a
579e7b0
81533b0
985d505
3a2929f
d578167
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -685,11 +685,12 @@ set(openPMD_TEST_NAMES | |
| # command line tools | ||
| set(openPMD_CLI_TOOL_NAMES | ||
| ls | ||
| convert-json-toml | ||
|
||
| ) | ||
| set(openPMD_PYTHON_CLI_TOOL_NAMES | ||
| pipe | ||
| ) | ||
| set(openPMD_PYTHON_CLI_MODULE_NAMES ${openPMD_CLI_TOOL_NAMES}) | ||
| set(openPMD_PYTHON_CLI_MODULE_NAMES ls) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line change looks like a hack?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really. Until now, both |
||
| # examples | ||
| set(openPMD_EXAMPLE_NAMES | ||
| 1_structure | ||
|
|
@@ -894,6 +895,9 @@ if(openPMD_BUILD_CLI_TOOLS) | |
| endif() | ||
|
|
||
| target_link_libraries(openpmd-${toolname} PRIVATE openPMD) | ||
| target_include_directories(openpmd-${toolname} SYSTEM PRIVATE | ||
| $<TARGET_PROPERTY:openPMD::thirdparty::nlohmann_json,INTERFACE_INCLUDE_DIRECTORIES> | ||
| $<TARGET_PROPERTY:openPMD::thirdparty::toml11,INTERFACE_INCLUDE_DIRECTORIES>) | ||
| endforeach() | ||
| endif() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| convert := openpmd-convert-json-toml | ||
|
||
|
|
||
| json_files = attribute_defs.json attributes.json dataset_defs.json iteration.json mesh.json mesh_record_component.json particle_patches.json particle_species.json patch_record.json record.json record_component.json series.json | ||
|
|
||
| .PHONY: all | ||
| all: $(json_files) | ||
|
|
||
| # The target file should only be created if the conversion succeeded | ||
| $(json_files): %.json: %.toml | ||
| $(convert) @$^ > $@.tmp | ||
| mv $@.tmp $@ | ||
|
|
||
| .PHONY: clean | ||
| clean: | ||
| for file in $(json_files); do rm -f "$$file" "$$file.tmp"; done | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,47 @@ | ||||||
| # JSON Validation | ||||||
|
|
||||||
| This folder contains a JSON schema for validation of openPMD files written as `.json` files. | ||||||
|
|
||||||
| ## Usage | ||||||
|
|
||||||
| ### Generating the JSON schema | ||||||
|
|
||||||
| For improved readability, maintainability and documentation purposes, the JSON schema is written in `.toml` format and needs to be "compiled" to `.json` files first before usage. | ||||||
| To do this, the openPMD-api installs a tool named `openpmd-convert-json-toml` which can be used to convert between JSON and TOML files in both directions, e.g.: | ||||||
|
|
||||||
| ```bash | ||||||
| openpmd_convert-json-toml @series.toml > series.json | ||||||
| ``` | ||||||
|
|
||||||
| A `Makefile` is provided in this folder to simplify the application of this conversion tool. | ||||||
|
||||||
| A `Makefile` is provided in this folder to simplify the application of this conversion tool. | |
| A `Makefile` is provided in this folder to simplify the application of this conversion tool to the `.toml` files in this folder. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a bit clearer: A Makefile is provided in this folder to automate generating the needed JSON files from the TOML files.
?
franzpoeschel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might clarify a bit:
| While a large part of the openPMD standard can indeed be verified by checking against a JSON schema, the standard is generally large enough to make this approach come to its limits. Verification of a JSON schema is similar to the use of a naive recursive-descent parser. Error messages will often be unexpectedly verbose and not very informative. | |
| While a large part of the openPMD standard can indeed be verified by checking against a static JSON schema, the standard is generally large enough to make this approach come to its limits. Verification of a JSON schema is similar to the use of a naive recursive-descent parser. Error messages will often be unexpectedly verbose and not very informative. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this section, you might want to advertise & link openPMD-validator again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. We might additionally advertise the JSON schema in the validator. Adding the JSON validation to our CI brought up a number of bugs after all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we able to patch this in
check.py?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very easily. The JSON schema is on the file system and the single .json files refer to each other by their file names. Changing this would require (1) traversing the entire JSON schema and overriding the meshes path, the particles path and the references and (2) somehow setting up python-jsonschema to cross-reference in-memory schemas which I don't even know if it supports that, both at runtime of
check.py.