Skip to content

Extend Property struct to support examples and handle complex additionalProperties#37

Merged
JR-1991 merged 6 commits intomainfrom
add-json-examples-add-props
Sep 24, 2025
Merged

Extend Property struct to support examples and handle complex additionalProperties#37
JR-1991 merged 6 commits intomainfrom
add-json-examples-add-props

Conversation

@JR-1991
Copy link
Copy Markdown
Collaborator

@JR-1991 JR-1991 commented Sep 23, 2025

This pull request introduces improvements to the handling of JSON Schema objects in the codebase, specifically around the additionalProperties field and the support for examples in properties. The changes enhance compatibility with schemas that use objects for additionalProperties and allow serialization of property examples.

Schema compatibility and serialization improvements:

  • Added custom deserialization logic in src/json/schema.rs to support both boolean and object forms of the additionalProperties field, ensuring that schemas with object values are correctly interpreted as allowing additional properties.
  • Updated the SchemaObject struct to use the new deserialization logic for additionalProperties, improving schema import robustness.
  • Added a unit test in src/json/import.rs to verify correct handling of object-valued additionalProperties, increasing test coverage for schema import scenarios.

Property serialization enhancements:

  • Added an examples field to the Property struct in src/json/schema.rs, allowing property examples to be serialized if present.
  • Ensured that the examples field is initialized to an empty vector when converting an Attribute to a Property in src/json/export.rs, maintaining consistency in property serialization.

Initializes the examples field as an empty vector when converting Attribute to schema::Property. This prepares the Property struct for future use of example values.
Added custom deserializer to support 'additionalProperties' as an object in SchemaObject. Updated tests to cover this case and added support for 'examples' in Property struct.
Introduces support for validating JSON schema files in the CLI by checking the input type and delegating to a new validate_from_json_schema function. Handles validation errors and logs results appropriately.
@JR-1991 JR-1991 requested a review from Copilot September 23, 2025 15:36
@JR-1991 JR-1991 self-assigned this Sep 23, 2025
@JR-1991 JR-1991 added bug Something isn't working enhancement New feature or request labels Sep 23, 2025
Copy link
Copy Markdown

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 JSON Schema handling by adding support for examples in properties and improving additionalProperties compatibility. The changes ensure schemas with object-valued additionalProperties are correctly interpreted and allow serialization of property examples.

  • Added custom deserialization for additionalProperties to handle both boolean and object forms
  • Extended Property struct with an examples field for serialization support
  • Added test coverage for object-valued additionalProperties scenarios

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/json/schema.rs Added custom deserializer for additionalProperties and examples field to Property struct
src/json/import.rs Added unit test to verify handling of object-valued additionalProperties
src/json/export.rs Initialize examples field when converting Attribute to Property

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/json/schema.rs
Comment thread src/json/schema.rs Outdated
Added a custom deserializer for the SchemaObject title field to strip all whitespace characters during deserialization. Includes tests to verify whitespace removal for various input cases.
@JR-1991 JR-1991 marked this pull request as ready for review September 24, 2025 10:12
Updated the Property struct so that the examples field is now a Vec<Value> instead of Vec<String>, allowing for more flexible example types in JSON schema properties.
Updated version numbers to 0.2.7 in Cargo.toml, Cargo.lock, and pyproject.toml for the mdmodels and mdmodels_core projects.
@JR-1991 JR-1991 merged commit e466bbf into main Sep 24, 2025
28 of 29 checks passed
@JR-1991 JR-1991 deleted the add-json-examples-add-props branch September 24, 2025 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants