Skip to content

Conversation

@michaeltlombardi
Copy link
Collaborator

PR Summary

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.

  • 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.

This change also refactors the dsc-lib-jsonschema library for consistency and ease of navigation:

  • 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.

PR Context

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.

@michaeltlombardi michaeltlombardi force-pushed the gh-538/main/get_keyword_as_subschema branch from 61d4d90 to e7f8cf9 Compare November 4, 2025 14:35
@SteveL-MSFT
Copy link
Member

@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

@michaeltlombardi michaeltlombardi force-pushed the gh-538/main/get_keyword_as_subschema branch from e7f8cf9 to f1f0ad3 Compare November 18, 2025 14:45
@michaeltlombardi
Copy link
Collaborator Author

@SteveL-MSFT - rebased and resolved, should be ready for review.

@SteveL-MSFT SteveL-MSFT requested a review from Copilot November 18, 2025 20:32
Copy link
Contributor

Copilot AI left a 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() and get_keyword_as_subschema_mut() helper methods
  • Updated return types from Map<String, Value> to Schema for subschema retrieval functions
  • Removed Object and Array type aliases in favor of explicit Map<String, Value> and Vec<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.

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.
@michaeltlombardi michaeltlombardi force-pushed the gh-538/main/get_keyword_as_subschema branch from f1f0ad3 to afb01af Compare November 19, 2025 14:36
Copilot finished reviewing on behalf of michaeltlombardi November 19, 2025 22:54
Copy link
Contributor

Copilot AI left a 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.
@michaeltlombardi michaeltlombardi force-pushed the gh-538/main/get_keyword_as_subschema branch from afb01af to 6d46d54 Compare November 19, 2025 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants