Skip to content

Commit

Permalink
feat: Expose drafts 2019-09 and 2020-12 to Python (#457)
Browse files Browse the repository at this point in the history
Co-authored-by: Dmitry Dygalo <[email protected]>
  • Loading branch information
DerRidda and Stranger6667 authored Mar 3, 2024
1 parent e15d4dd commit 6ae63dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions bindings/python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Changed

- Expose drafts 2019-09 and 2020-12 to Python
- Update `pyo3` to `0.20`.

## [0.17.1] - 2023-07-05
Expand Down
2 changes: 2 additions & 0 deletions bindings/python/python/jsonschema_rs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ class ValidationError(ValueError):
Draft4: int
Draft6: int
Draft7: int
Draft201909: int
Draft202012: int
6 changes: 6 additions & 0 deletions bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ mod types;
const DRAFT7: u8 = 7;
const DRAFT6: u8 = 6;
const DRAFT4: u8 = 4;
const DRAFT201909: u8 = 19;
const DRAFT202012: u8 = 20;

/// An instance is invalid under a provided schema.
#[pyclass(extends=exceptions::PyValueError, module="jsonschema_rs")]
Expand Down Expand Up @@ -117,6 +119,8 @@ fn get_draft(draft: u8) -> PyResult<Draft> {
DRAFT4 => Ok(jsonschema::Draft::Draft4),
DRAFT6 => Ok(jsonschema::Draft::Draft6),
DRAFT7 => Ok(jsonschema::Draft::Draft7),
DRAFT201909 => Ok(jsonschema::Draft::Draft201909),
DRAFT202012 => Ok(jsonschema::Draft::Draft202012),
_ => Err(exceptions::PyValueError::new_err(format!(
"Unknown draft: {}",
draft
Expand Down Expand Up @@ -462,6 +466,8 @@ fn jsonschema_rs(py: Python<'_>, module: &PyModule) -> PyResult<()> {
module.add("Draft4", DRAFT4)?;
module.add("Draft6", DRAFT6)?;
module.add("Draft7", DRAFT7)?;
module.add("Draft201909", DRAFT201909)?;
module.add("Draft202012", DRAFT202012)?;

// Add build metadata to ease triaging incoming issues
module.add("__build__", pyo3_built::pyo3_built!(py, build))?;
Expand Down

0 comments on commit 6ae63dc

Please sign in to comment.