feat(model): add static examples for schema generation - #307
Open
alexlitvinenko wants to merge 1 commit into
Open
feat(model): add static examples for schema generation#307alexlitvinenko wants to merge 1 commit into
alexlitvinenko wants to merge 1 commit into
Conversation
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)
alexlitvinenko
requested review from
bohdanzahoruikocchangelabs
and
a lite review from Copilot
August 21, 2026 14:57
corvis
approved these changes
Aug 21, 2026
There was a problem hiding this comment.
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
IndustryEpdPreviewV0does not inheritWithLciaMixin, soimpacts,resource_uses, andoutput_flowsinEXAMPLE_INDUSTRY_EPD_METAL_PRODUCTSare 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); withforce-sort-within-sectionsenabled, Ruff will report I001. Put the plainimportstatements before thefrom ... 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 theexamplesadded bymodel_configor 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) |
bohdanzahoruikocchangelabs
approved these changes
Aug 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add explicit model example payloads used by schema generation. Work around recursive field example issues such as
Pcr.parent.asana: Resolve schema generation issue