Add a JSONSchemaWriter to Inlet#490
Conversation
…ng schemas for nested structures
…e more interesting syntax help
kennyweiss
left a comment
There was a problem hiding this comment.
This is great @joshessman-llnl !
There was a problem hiding this comment.
This seems brittle.
Is this typically available in unix? What about windows?
Is there a way we can add this via the build system, e.g. via axom's devtools and pass the path in through a #define in axom/config.hpp?
Perhaps as a follow-up PR?
There was a problem hiding this comment.
I have the path hardcoded here for security reasons (to avoid PATH injection attacks, though I'm not sure if this is a threat vector that Axom cares about).
I don't recall installing jsonschema (it just happened to be present), but I think it's available as a PyPI package that can be installed fairly easily. I think it could also be made available through spack.
| { | ||
| if(!hasSchemaUtility()) | ||
| { | ||
| GTEST_SKIP() << "jsonschema tool was not found"; |
|
|
||
| const bool jsonVerified = validateString(inlet, testString); | ||
|
|
||
| EXPECT_FALSE(jsonVerified); |
| inlet.writeDoc(); | ||
| std::unique_ptr<inlet::JSONSchemaWriter> schemaWriter( | ||
| new inlet::JSONSchemaWriter("nested_structs.json")); | ||
| inlet.registerWriter(std::move(schemaWriter)); |
There was a problem hiding this comment.
(It will be easy for me to check, but) is there only one writer at a time?
There was a problem hiding this comment.
Yes (I had to look it up myself) - I don't see any reason why we couldn't just store a vector of them, though.
There was a problem hiding this comment.
logged so we don't forget
There was a problem hiding this comment.
This needs to be fixed for the non-WSL windows build.
Possibly removing the path completely?
There was a problem hiding this comment.
This executable isn't there on OSX (at least mine)
| protected: | ||
| void SetUp() override | ||
| { | ||
| if(!hasSchemaUtility()) |
There was a problem hiding this comment.
👍 at least it just skips if its not there...
| This allows for integration with text editors like Visual Studio Code, which allows you to associate a JSON schema | ||
| with an input file and subsequently provides autocompletion, linting, tooltips, and more. | ||
|
|
||
| Using the same ``documentation_generation.cpp`` example, the automatically generated schema can be used to assist |
There was a problem hiding this comment.
Added an issue so I don't forget that we should have a dedicated page for Writer classes.
Summary
Inlethierarchy traversal logic to visit only one element of a container instead of all of them (since their schemas are guaranteed to be identical) - this was implemented at theWriterlevel in Document function callbacks in SphinxWriter #450 but after having implemented a secondWriterI think it's general enough to apply to allWriterscollectionIndicesandcollectionIndicesWithPathsfromContainermethods to nonmembers in thedetailnamespace, since they don't need access to private members (and so they can be used elsewhere)This PR also adds some tests that cover a small subset of what the new SchemaWriter produces - there's a lot of specialized logic associated with structs/collections of structs/primitive arrays that was tested manually. If the test approach makes sense, I can add more tests in this PR or a follow-up. I happened to have a tool called
jsonschemaon my machine that can check a JSON file against a JSON schema, so I've used this to verify that the schema verification agrees with Inlet's verification. These tests are skipped whenjsonschemais not available.I've also added a demo GIF showing what the VSCode integration looks like, though I've crunched it quite a bit to avoid cluttering the repo. If the resolution is too low I can increase it a bit.
New doc snippet: https://axom.readthedocs.io/en/feature-essman-json_schema_writer/axom/inlet/docs/sphinx/quick_start.html#generating-documentation