(GH-538) Enable retrieving keywords as Schema objects
#1226
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Summary
This change:
Adds two helper methods to retrieve a keyword as a
schemars::Schemainstance (borrowed and mutably borrowed) to make working with subschemas more ergonomic.Updates the following functions to return instances of
schemars::Schemainstead ofMap<String, Value>, since the returned data is always a subschema, if it exists:get_defs_subschema_from_id()get_defs_subschema_from_id_mut()get_defs_subschema_from_reference()get_defs_subschema_from_reference_mut()get_property_subschema()get_property_subschema_mut()Removes the type aliases
Object(forMap<String, Value>) andArray(forVec<Value>), as these conveniences weren't saving much typing and Rust Analyzer wasn't always plumbing them through for IntelliSense. The uses of these aliases now revert to calling the underlying types.Updates documentation and tests for the modified functions.
This change also refactors the
dsc-lib-jsonschemalibrary for consistency and ease of navigation:transformsmodule out into submodules and re-exports them fromtransforms- this keeps referencing the functions the way it was before but makes it easier to navigate the files, given their length.schema_utility_extensionsmirror the structure from the source code.transformmirror the structure from the source code.PR Context
Prior to this change, the
dsc-lib-jsonschemacrate defined extension methods for schemas to retrieve keywords as various underlying data types when the caller knows the data type they need. However, the extension methods didn't include a way to retrieve values as schemas, so any use of those values requires the caller to reimplement the extension methods logic or to manually convert the value to a schema.