Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
otto-ifak committed May 30, 2024
1 parent 6a43e15 commit 318fe9b
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,39 @@ You can install JSON Schema Tool via pip:
python -m pip install json_schema_tool
```

## Schema Coverage Measurement
## Features

### Additional Keywords

Json Schema Tool supports OpenAPI's `discriminator` keyword for improved modelling of polymorphism:

```python
schema = {
'$schema': 'https://json-schema.org/draft/2020-12/schema',
'oneOf': [
{'$ref': '#/$defs/Cat'},
{'$ref': '#/$defs/Dog'},
],
'$defs': {
'Cat': {
'properties': {'sound': {'const': 'meow'}}
},
'Dog': {
'properties': {'sound': {'const': 'woof'}}
}
},
'discriminator': {
'propertyName': 'type'
}
}
result = validator.validate({'type': 'Cat', 'sound': '?'})
# result.ok == False
```

Using the discriminator `type`, Json Schema Tool knows which reference to check and will only return an error for the `Cat` type (and will not check `Dog`).
For more information, see https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/.

### Schema Coverage Measurement
You can use coverage to assess the completeness of your test data.
Schema coverage works on the keyword level, i.e., JsonSchema Tool checks, how many constraints have been actually checked during instance validation:

Expand Down Expand Up @@ -72,7 +104,7 @@ with open("schema-coverage.html", "w") as f:
cov.render_coverage(f)
```

## Type Inference
### Type Inference
Given a validator, you can use it to query the types of the schema.
This even works for complex and composed schemas:
```python
Expand All @@ -89,7 +121,7 @@ print(validator.get_types())
# {'object', 'string'}
```

## Validation Performance
### Validation Performance
You can drastically increase validation performance by using short circuit evaluation (SCE).
By using SCE, evaluation terminates as soon as the first error in the JSON instance is found.
For example, an allOf does not visit all sub schemas, if the first sub-schema already fails.
Expand Down

0 comments on commit 318fe9b

Please sign in to comment.