Metadata-Version: 2.1
Name: jj-spec-validator
Version: 1.0.0
Summary: jj mocks validator for openapi specs
Home-page: https://github.com/Maestoz/jj-spec-validator
Author: Sam Roz
Author-email: rolez777@gmail.com
License: Apache-2.0
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: httpx<1.0.0,>=0.27.0
Requires-Dist: schemax-openapi<1.0.0,>=0.1.0
Requires-Dist: jj<3.0.0,>=2.10.3
Requires-Dist: d42<3.0.0,>=2.0.0

### Version Compatibility Notice

- For versions of this package **below 1.0.0**, only version 1 of the [`d42`](https://github.com/d42-schemas/d42) package is compatible.
- For versions of this package **1.0.0 and later**, only version 2 of the [`d42`](https://github.com/d42-schemas/d42) package is compatible.

## Usage

1. Decorate your [mocked](https://pypi.org/project/jj/) function with `@validate_spec()`, providing a link to a YAML or JSON OpenAPI spec.
```python
import jj
from jj.mock import mocked
from jj_spec_validator import validate_spec


@validate_spec(spec_link="http://example.com/api/users/spec.yml")
async def your_mocked_function():
    matcher = jj.match("GET", "/users")
    response = jj.Response(status=200, json=[])
    
    mock = await mocked(matcher, response)
```

2. `is_strict` key allows choosing between strict and non-strict comparison. Non-strict comparison allows you to mock only some fields from the spec. `False` (= non-strict) by default.

3. Use the `prefix` key to specify a prefix that should be removed from the paths in the mock function before matching them against the OpenAPI spec.
```python
from jj_spec_validator import validate_spec


@validate_spec(spec_link="http://example.com/api/users/spec.yml", prefix='/__mocked_api__')  # Goes to validate `/users` instead of `/__mocked_api__/users`
async def your_mocked_function():
    matcher = jj.match("GET", "/__mocked_api__/users")
    ...
```

4. `is_raise_error` key allows raising an error when a mismatch occurs. `False` by default.

5. `force_strict` key allows enforcing strict validation against the downloaded spec. This is useful when the spec is occasionally have all dicts relaxed. `False` by default.
