Skip to content

Conversation

@ahouseholder
Copy link
Contributor

@ahouseholder ahouseholder commented Sep 16, 2025

The problem with the first attempt (tagged fix-834-attempt-1) is that it adds the undesirable AnyOf and null values in the json schema.

However, with fix-834-attempt-2 we have a working solution for the SelectionList object at least.

We may need to revisit this in the future if we need other objects to do the same "optional but no anyOf" fields, but this works for the current needs.

Copilot Summary

This pull request strengthens schema validation and refactors code related to schema handling and optional fields. The most important changes are the enforcement of non-empty strings for key schema fields, the introduction of a new utility module for schema operations, and the simplification of how optional fields are managed in selection-related models.

Schema validation improvements:

Codebase refactoring and modularization:

  • Moved schema ordering and manipulation utilities from ssvc.utils.misc to a new module ssvc.utils.schema, and updated all imports accordingly. [1] [2] [3] [4] [5] [6]
  • Introduced a new utility function strip_nullable_anyof in ssvc.utils.schema to clean up nullable string representations in generated JSON schemas. [1] [2]

Improvements to handling optional fields:

  • Refactored selection-related mixins and models to use Pydantic's type annotations for optional name and definition fields, removing custom validators and simplifying model logic. [1] [2] [3] [4]

These changes collectively improve schema robustness, code maintainability, and clarity around optional fields.

@ahouseholder ahouseholder self-assigned this Sep 16, 2025
@ahouseholder ahouseholder marked this pull request as draft September 16, 2025 16:17
@ahouseholder ahouseholder marked this pull request as ready for review September 16, 2025 18:49
@ahouseholder ahouseholder added tech/backend Back-end tools, code, infrastructure tech/data Data implementation (content of /data, data object instances, etc.) integration/blocker Something that is blocking integration with another framework or system integration Related to integration of SSVC into another framework or system labels Sep 16, 2025
@ahouseholder ahouseholder added this to the 2025-09 milestone Sep 16, 2025
@ahouseholder ahouseholder changed the title Attempting to resolve #834 Add minLength to name and definition in SelectionList $defs Sep 16, 2025
return ordered_schema


def strip_nullable_anyof(schema: dict) -> dict:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The meat of the whole PR lives in this one function that is used to post-process a schema.

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 refactors the handling of optional name and definition fields in SSVC models to ensure they cannot be empty strings while still allowing None values. The changes introduce new mixins with proper validation constraints and reorganize schema utilities into a dedicated module.

Key changes:

  • Introduce new _OptionalBase and _GenericOptionalSsvcObject mixins with minLength=1 constraints for optional string fields
  • Replace custom validators with Pydantic's built-in StringConstraints for cleaner validation
  • Move schema utility functions to a new ssvc.utils.schema module for better code organization

Reviewed Changes

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

Show a summary per file
File Description
src/ssvc/_mixins.py Adds new mixins with StringConstraints for optional fields and updates imports
src/ssvc/selection.py Refactors Selection and MinimalDecisionPointValue to use new mixins and schema utilities
src/ssvc/utils/schema.py New module containing moved schema utility functions including strip_nullable_anyof
src/ssvc/utils/misc.py Removes schema utility functions that were moved to dedicated module
src/test/test_selections.py Updates tests to verify empty strings raise ValueError while None is accepted
data/schema/v2/SelectionList_2_0_0.schema.json Updates JSON schema to enforce minLength=1 for name and definition fields
src/ssvc/registry_demo.py Updates import to use new schema utility module
src/ssvc/doctools.py Updates imports to use new schema utility module

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

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 8 out of 8 changed files in this pull request and generated no new comments.


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

@ahouseholder ahouseholder merged commit a220ed4 into main Sep 16, 2025
4 of 5 checks passed
@ahouseholder ahouseholder deleted the try-834 branch September 16, 2025 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration/blocker Something that is blocking integration with another framework or system integration Related to integration of SSVC into another framework or system tech/backend Back-end tools, code, infrastructure tech/data Data implementation (content of /data, data object instances, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add missing minLength in JSON schema "name" and "description" should have min_length=1

2 participants