-
Notifications
You must be signed in to change notification settings - Fork 56
(GH-538) Enable retrieving keywords as Schema objects
#1226
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
base: main
Are you sure you want to change the base?
(GH-538) Enable retrieving keywords as Schema objects
#1226
Conversation
61d4d90 to
e7f8cf9
Compare
|
@michaeltlombardi can you fix the merge conflict, I think it's due to a change I made to revert a workaround you put in since schemars was updated and fixed the issue |
e7f8cf9 to
f1f0ad3
Compare
|
@SteveL-MSFT - rebased and resolved, should be ready for review. |
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.
Pull Request Overview
This PR enhances the dsc-lib-jsonschema library by adding methods to retrieve keywords as Schema objects and refactoring return types for subschema-related functions. The changes improve ergonomics when working with subschemas by returning typed Schema instances instead of generic JSON objects.
Key changes:
- Added
get_keyword_as_subschema()andget_keyword_as_subschema_mut()helper methods - Updated return types from
Map<String, Value>toSchemafor subschema retrieval functions - Removed
ObjectandArraytype aliases in favor of explicitMap<String, Value>andVec<Value>
Reviewed Changes
Copilot reviewed 10 out of 12 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
lib/dsc-lib-jsonschema/src/schema_utility_extensions.rs |
Core implementation: added new subschema retrieval methods, updated return types for property and defs functions, removed type aliases |
lib/dsc-lib-jsonschema/src/transforms/mod.rs |
Refactored to re-export functions from new submodules |
lib/dsc-lib-jsonschema/src/transforms/idiomaticize_string_enum.rs |
Extracted string enum transform logic into dedicated module |
lib/dsc-lib-jsonschema/src/transforms/idiomaticize_externally_tagged_enum.rs |
Extracted externally tagged enum transform logic into dedicated module |
lib/dsc-lib-jsonschema/src/tests/schema_utility_extensions/mod.rs |
Updated tests to use json_schema! macro and new return types |
lib/dsc-lib-jsonschema/src/tests/transforms/mod.rs |
Removed unit test file (transforms are integration tested) |
lib/dsc-lib-jsonschema/src/tests/mod.rs |
Removed transforms unit test module reference |
lib/dsc-lib-jsonschema/tests/integration/transforms/mod.rs |
Restructured to reference new submodule names |
lib/dsc-lib-jsonschema/tests/integration/transforms/idiomaticizing/mod.rs |
Removed (restructured) |
lib/dsc-lib-jsonschema/tests/integration/transforms/idiomaticizing/enums/mod.rs |
Removed (restructured) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lib/dsc-lib-jsonschema/src/transforms/idiomaticize_string_enum.rs
Outdated
Show resolved
Hide resolved
Prior to this change, the `dsc-lib-jsonschema` crate 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. This change adds two helper methods to retrieve a keyword as a `schemars::Schema` instance (borrowed and mutably borrowed) to make working with subschemas more ergonomic.
This change: - Updates the following functions to return instances of `schemars::Schema` instead of `Map<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` (for `Map<String, Value>`) and `Array` (for `Vec<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.
f1f0ad3 to
afb01af
Compare
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.
Pull Request Overview
Copilot reviewed 10 out of 12 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This change refactors the `dsc-lib-jsonschema` library without modifying any behavior. This change: - Splits the functions in the `transforms` module out into submodules and re-exports them from `transforms` - this keeps referencing the functions the way it was before but makes it easier to navigate the files, given their length. - Makes the unit tests for `schema_utility_extensions` mirror the structure from the source code. - Makes the integration tests for `transform` mirror the structure from the source code.
afb01af to
6d46d54
Compare
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.