Skip to content

Conversation

@damaz91
Copy link
Contributor

@damaz91 damaz91 commented Feb 6, 2026

This pull request introduces major improvements to the model generation workflow, schema preprocessing, and project structure for the UCP Python SDK. The most significant changes include the addition of a schema preprocessing script to resolve compatibility issues, updates to the model generation script to use preprocessed schemas, a refactor of capability and discovery profile models for clarity and separation, and enhanced formatting and linting for generated code.

Schema Preprocessing and Model Generation:

  • Added a new preprocess_schemas.py script to preprocess JSON schemas, resolving internal references and removing problematic definitions to ensure compatibility with datamodel-code-generator. The generate_models.sh script is updated to invoke this preprocessing step and to format/lint generated models using Ruff. [1] [2] [3] [4]

Model and Schema Refactoring:

  • Refactored capability and discovery profile models for better separation and clarity. The new structure introduces clear distinctions between platform, business, and response schemas for both capabilities and payment handlers, and updates discovery profile models to use these new schema types. [1] [2] [3] [4]

Formatting and Linting Improvements:

  • Removed Ruff configuration from pyproject.toml and now generate a dedicated ruff.toml in the models directory for more lenient linting of auto-generated code. The model generation script now applies formatting and lint fixes automatically. [1] [2] [3] [4]

Documentation and Setup Updates:

  • Updated the README.md to clarify repository cloning instructions and document the need to clone the main UCP repository for schema regeneration. [1] [2]

Cleanup and Deprecation:

  • Removed the legacy _internal.py models file, as its functionality has been replaced by the new schema-based model structure.

@damaz91 damaz91 requested a review from a team February 6, 2026 10:18
The models are automatically generated from the JSON schemas in the UCP
Specification.

Clone the UCP main repository in the same folder:

Choose a reason for hiding this comment

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

Consider adding as a submodule instead.

[project]
name = "ucp-sdk"
version = "0.1.0"
version = "0.2.0"

Choose a reason for hiding this comment

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

Should this get in sync with the spec version? 2026.01.23 ?

# pylint: disable=all
# pyformat: disable
"""

Choose a reason for hiding this comment

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

Why move this to a temporarily generated file? These settings take effect across subdirectories too.

Choose a reason for hiding this comment

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

Is this tool specific to the Python repo, or is is needed for Javascript as well? Should it live in the main ucp repo instead?

# Run generation using uv
# We use --use-schema-description to use descriptions from JSON schema as docstrings
# We use --field-constraints to include validation constraints (regex, min/max, etc.)
# Note: Formatters removed as they can hang on large schemas

Choose a reason for hiding this comment

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

Might be better to comment that formatting is done as a post-processing step. We still want to reformat the code to minimize accidental whitespace changes.


echo "Generating Pydantic models from $SCHEMA_DIR..."
echo "Preprocessing schemas..."
python3 preprocess_schemas.py

Choose a reason for hiding this comment

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

uv run ... ?


echo "Formatting generated models..."
uv run ruff format "$OUTPUT_DIR"
uv run ruff check --fix --config "$OUTPUT_DIR/ruff.toml" "$OUTPUT_DIR" 2>&1 | grep -E "^(All checks passed|Fixed|Found)" || echo "Formatting complete"

Choose a reason for hiding this comment

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

If we remove --config "$OUTPUT_DIR/ruff.toml" , won't it use the settings from pyproject.toml at the top?


if __name__ == "__main__":
script_dir = Path(__file__).parent
input_schemas = script_dir / "ucp" / "source"

Choose a reason for hiding this comment

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

Consider taking command line arguments instead.

--allow-extra-fields

echo "Formatting generated models..."
uv run ruff format "$OUTPUT_DIR"

Choose a reason for hiding this comment

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

$OUTPUT_DIR can be omitted; the whole project will be reformatted.

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