Metadata-Version: 2.1
Name: vedro-spec-validator
Version: 0.0.4
Summary: Vedro Spec Validator plugin
Home-page: https://github.com/Maestoz/vedro-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
License-File: LICENSE
Requires-Dist: jj-spec-validator<1.0.0,>=0.1.9
Requires-Dist: vedro<2.0,>=1.10

[vedro-spec-validator](https://pypi.org/project/vedro-spec-validator/) is a [Vedro](https://vedro.io) plugin that allow to validate mocks via OpenAPI spec/docs.

## Installation

<details open>
<summary>Quick</summary>
<p>

For a quick installation, you can use a plugin manager as follows:

```shell
$ vedro plugin install vedro-spec-validator
```

</p>
</details>

<details>
<summary>Manual</summary>
<p>

To install manually, follow these steps:

1. Install the package using pip:

```shell
$ pip3 install vedro-spec-validator
```

2. Next, activate the plugin in your `vedro.cfg.py` configuration file:

```python
# ./vedro.cfg.py
import vedro
import vedro_spec_validator

class Config(vedro.Config):

    class Plugins(vedro.Config.Plugins):

        class VedroSpecValidator(vedro_spec_validator.VedroSpecValidator):
            enabled = True
```

</p>
</details>

## 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 plugins.validate_spec 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 will allow choosing between strict and non-strict comparison. False 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 plugins.validate_spec 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")
    ...
```
