feat: Expose drafts 2019-09 and 2020-12 to Python (#457)

Co-authored-by: Dmitry Dygalo <dmitry@dygalo.dev>
This commit is contained in:
Stephan Lanfermann 2024-03-03 01:24:07 +01:00 committed by GitHub
parent e15d4dd342
commit 6ae63dc564
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 0 deletions

View File

@ -4,6 +4,7 @@
### Changed ### Changed
- Expose drafts 2019-09 and 2020-12 to Python
- Update `pyo3` to `0.20`. - Update `pyo3` to `0.20`.
## [0.17.1] - 2023-07-05 ## [0.17.1] - 2023-07-05

View File

@ -67,3 +67,5 @@ class ValidationError(ValueError):
Draft4: int Draft4: int
Draft6: int Draft6: int
Draft7: int Draft7: int
Draft201909: int
Draft202012: int

View File

@ -34,6 +34,8 @@ mod types;
const DRAFT7: u8 = 7; const DRAFT7: u8 = 7;
const DRAFT6: u8 = 6; const DRAFT6: u8 = 6;
const DRAFT4: u8 = 4; const DRAFT4: u8 = 4;
const DRAFT201909: u8 = 19;
const DRAFT202012: u8 = 20;
/// An instance is invalid under a provided schema. /// An instance is invalid under a provided schema.
#[pyclass(extends=exceptions::PyValueError, module="jsonschema_rs")] #[pyclass(extends=exceptions::PyValueError, module="jsonschema_rs")]
@ -117,6 +119,8 @@ fn get_draft(draft: u8) -> PyResult<Draft> {
DRAFT4 => Ok(jsonschema::Draft::Draft4), DRAFT4 => Ok(jsonschema::Draft::Draft4),
DRAFT6 => Ok(jsonschema::Draft::Draft6), DRAFT6 => Ok(jsonschema::Draft::Draft6),
DRAFT7 => Ok(jsonschema::Draft::Draft7), DRAFT7 => Ok(jsonschema::Draft::Draft7),
DRAFT201909 => Ok(jsonschema::Draft::Draft201909),
DRAFT202012 => Ok(jsonschema::Draft::Draft202012),
_ => Err(exceptions::PyValueError::new_err(format!( _ => Err(exceptions::PyValueError::new_err(format!(
"Unknown draft: {}", "Unknown draft: {}",
draft draft
@ -462,6 +466,8 @@ fn jsonschema_rs(py: Python<'_>, module: &PyModule) -> PyResult<()> {
module.add("Draft4", DRAFT4)?; module.add("Draft4", DRAFT4)?;
module.add("Draft6", DRAFT6)?; module.add("Draft6", DRAFT6)?;
module.add("Draft7", DRAFT7)?; module.add("Draft7", DRAFT7)?;
module.add("Draft201909", DRAFT201909)?;
module.add("Draft202012", DRAFT202012)?;
// Add build metadata to ease triaging incoming issues // Add build metadata to ease triaging incoming issues
module.add("__build__", pyo3_built::pyo3_built!(py, build))?; module.add("__build__", pyo3_built::pyo3_built!(py, build))?;