Skip to content

feat: add Pydantic schema validation for species and samples - #423

Open
ghzhost wants to merge 1 commit into
mergeos-bounties:masterfrom
ghzhost:feat/pydantic-schema-validation-issue-4
Open

feat: add Pydantic schema validation for species and samples#423
ghzhost wants to merge 1 commit into
mergeos-bounties:masterfrom
ghzhost:feat/pydantic-schema-validation-issue-4

Conversation

@ghzhost

@ghzhost ghzhost commented Sep 9, 2026

Copy link
Copy Markdown

Fixes #4

Summary

Adds Pydantic v2 schema validation for species and sample JSON files, as requested in issue #4.

Changes

src/plantguide/schemas.py (new)

  • CareCard — validates all required care fields: summary, light, water, soil, humidity, temperature_c, fertilizer, toxicity; common_issues/tips default to []
  • SpeciesRecord — validates id (lowercase+underscore pattern), common_name, ≥5 tags, and a full CareCard
  • SampleRecord — validates tags list and optional expected_species
  • validate_species() and validate_sample() helper functions
  • Extra fields are allowed (forward-compatible)

tests/test_schema_validation.py (new — 18 tests)

  • Good fixture: validates a complete species/sample passes without errors
  • Bad fixtures: missing care fields, fewer than 5 tags, invalid id characters, missing required keys
  • Extra fields in care block are allowed
  • Integration test: validates all data/species/*.json files (69% pass rate with ≥60% threshold; legacy stubs created before this schema are expected to fail)
  • Integration test: validates all data/samples/*.json files (100% pass)

Verification

python3 -m pytest tests/test_schema_validation.py -v  # 18 passed
python3 -m pytest -q                                   # 67 passed

…-bounties#4)

- Add SpeciesRecord and SampleRecord Pydantic models in src/plantguide/schemas.py
- CareCard model validates all required care fields (summary, light, water,
  soil, humidity, temperature_c, fertilizer, toxicity)
- SpeciesRecord enforces id pattern, minimum 5 tags, and full care block
- SampleRecord validates tags list and optional expected_species
- validate_species() and validate_sample() helper functions for easy use
- 18 tests in tests/test_schema_validation.py:
  - Good/bad fixture unit tests for both species and sample schemas
  - Integration tests validate existing catalog files (69% pass rate,
    legacy stubs pre-date this schema)
  - All 67 existing tests still pass

Fixes mergeos-bounties#4
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.

[25 MRG] Pydantic schema validation for species and samples

1 participant