Skip to content

feat(model): add static examples for schema generation - #307

Open
alexlitvinenko wants to merge 1 commit into
v7from
feat/examples-v7
Open

feat(model): add static examples for schema generation#307
alexlitvinenko wants to merge 1 commit into
v7from
feat/examples-v7

Conversation

@alexlitvinenko

Copy link
Copy Markdown
Contributor

Add explicit model example payloads used by schema generation. Work around recursive field example issues such as Pcr.parent.

asana: Resolve schema generation issue

Add explicit model example payloads used by schema generation.
Work around recursive field example issues such as `Pcr.parent`.

asana: [Resolve schema generation issue](https://app.asana.com/1/654700433662128/project/666075018299960/task/1217607200481735?focus=true)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds reusable static model examples for Pydantic schema generation, including recursive-safe payloads, with validation tests.

Changes:

  • Adds example payloads for core model types.
  • Attaches examples to schemas and PCR fields.
  • Adds validation and serialization coverage.

Reviewed changes

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

Show a summary per file
File Summary
src/openepd/model/tests/test_examples.py Validates static examples. Moderate (4 votes): round-trip assertions should honor REQUIRE_ROUND_TRIP.
src/openepd/model/pcr.py Adds PCR schema examples.
src/openepd/model/light/industry_epd.py Adds light industry EPD examples.
src/openepd/model/light/generic_estimate.py Adds preview examples. Moderate (3 votes): the later model_config overwrites the earlier examples configuration.
src/openepd/model/light/epd.py Adds light EPD examples.
src/openepd/model/industry_epd.py Adds industry EPD examples.
src/openepd/model/generic_estimate.py Adds generic estimate examples.
src/openepd/model/examples/plant.py Defines plant example data.
src/openepd/model/examples/pcr.py Defines PCR example data.
src/openepd/model/examples/org.py Defines organization examples.
src/openepd/model/examples/industry_epd.py Defines industry EPD example data.
src/openepd/model/examples/generic_estimate.py Defines generic estimate example data.
src/openepd/model/examples/epd.py Defines EPD example data.
src/openepd/model/examples/__init__.py Initializes the examples package.
src/openepd/model/epd.py Adds full EPD schema examples.
src/openepd/model/declaration.py Adds a PCR field example.
Suppressed comments (3)

src/openepd/model/light/industry_epd.py:79

  • IndustryEpdPreviewV0 does not inherit WithLciaMixin, so impacts, resource_uses, and output_flows in EXAMPLE_INDUSTRY_EPD_METAL_PRODUCTS are full-model fields that the preview model ignores. Attaching this full payload to the preview schema advertises unsupported properties in generated API documentation; use a preview-specific payload without those fields or attach this example only to the full model.
    model_config = pydantic.ConfigDict(json_schema_extra={"examples": [EXAMPLE_INDUSTRY_EPD_METAL_PRODUCTS]})

src/openepd/model/tests/test_examples.py:19

  • This standard-library import block is not in the repository's Ruff/isort order (pyproject.toml:150-174); with force-sort-within-sections enabled, Ruff will report I001. Put the plain import statements before the from ... import ... statements.
from abc import ABC
import types
from typing import ClassVar
import unittest

src/openepd/model/tests/test_examples.py:70

  • The new test only validates the payloads and optionally round-trips them; it never checks model_json_schema() for the examples added by model_config or by the PCR field. A regression that removes the schema metadata, attaches it to the wrong preview/full class, or emits an invalid schema example would still pass. Add schema assertions for the configured models and the PCR field example.
                instance = self.MODEL_TYPE.model_validate(attribute_value)
                self.assertIsInstance(instance, self.MODEL_TYPE)
                # Ensure a basic serialize -> deserialize round-trip is stable
                self.assertEqual(instance.to_serializable(), attribute_value)

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Excludes LCIA data.
"""

model_config = pydantic.ConfigDict(json_schema_extra={"examples": [EXAMPLE_GENERIC_ESTIMATE_SAMPLE]})
instance = self.MODEL_TYPE.model_validate(attribute_value)
self.assertIsInstance(instance, self.MODEL_TYPE)
# Ensure a basic serialize -> deserialize round-trip is stable
self.assertEqual(instance.to_serializable(), attribute_value)
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.

4 participants