-
Notifications
You must be signed in to change notification settings - Fork 4
BDMS-227-254: add schema validations to aquifer and geology schemas #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ksmuczynski
merged 5 commits into
bdms-227
from
kas-227-254-add-schema-validations-aquifer-geology
Dec 2, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8a78f67
feat(schemas): add enum, depth and geometry validations and associati…
ksmuczynski a8c4afc
refactor(schemas): centralize validations and enforce strict enums
ksmuczynski 33ea2e2
refactor(schemas): remove None check on validators.DepthIntervalMixin
ksmuczynski 02107c3
refactor(schemas): enforce non-negative depths in DepthIntervalMixin
ksmuczynski 3ed93b8
Merge remote-tracking branch 'origin/bdms-227' into kas-227-254-add-s…
ksmuczynski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """ | ||
| schemas/validators.py | ||
| Reusable Pydantic validators and mixins for aquifer and geology related schemas. | ||
| May consider expansion for other domain models in the future. | ||
| """ | ||
|
|
||
| from pydantic import model_validator, field_validator, BaseModel, ValueError, Field | ||
| from services.validation.geospatial import validate_wkt_geometry | ||
|
|
||
|
|
||
| class DepthIntervalMixin(BaseModel): | ||
| """ | ||
| Mixin to enforce: | ||
| 1. Depths are non-negative (via Field constraints). | ||
| 2. Bottom depth > top depth (via model_validator). | ||
| Assumes the model has 'top_depth' and 'bottom_depth' fields. | ||
| """ | ||
|
|
||
| top_depth: float = Field(ge=0) | ||
| bottom_depth: float = Field(ge=0) | ||
|
|
||
| @model_validator(mode="after") | ||
| def check_depth_logical_order(self) -> "DepthIntervalMixin": | ||
| if self.bottom_depth <= self.top_depth: | ||
| raise ValueError( | ||
| f"Bottom depth ({self.bottom_depth}) must be greater " | ||
| f"than top depth ({self.top_depth})" | ||
| ) | ||
| return self | ||
|
|
||
|
|
||
| class GeometryMixin(BaseModel): | ||
| """ | ||
| Mixin to validate WKT strings for boundary fields. | ||
| Delegates logic to the validate_wkt_geometry service function. | ||
| """ | ||
|
|
||
| boundary: str | None = None | ||
|
|
||
| @field_validator("boundary") | ||
| @classmethod | ||
| def validate_wkt(cls, v: str | None) -> str | None: | ||
| return validate_wkt_geometry(v) | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.