jj mocks validator for openapi specs
Project description
Version Compatibility Notice
- For versions of this package below 1.0.0, only version 1 of the
d42package is compatible. - For versions of this package 1.0.0 and later, only version 2 of the
d42package is compatible.
Usage
- Decorate your mocked function with
@validate_spec(), providing a link to a YAML or JSON OpenAPI spec.
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)
-
is_strictkey 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. -
Use the
prefixkey to specify a prefix that should be removed from the paths in the mock function before matching them against the OpenAPI spec.
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")
...
-
is_raise_errorkey allows raising an error when a mismatch occurs.Falseby default. -
force_strictkey allows enforcing strict validation against the downloaded spec. This is useful when the spec is occasionally have all dicts relaxed.Falseby default.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jj_spec_validator-1.0.0.tar.gz.
File metadata
- Download URL: jj_spec_validator-1.0.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17edc5bc114a73350123fb942d503264e10f5c5036681e0d6ec93c0939b46f99
|
|
| MD5 |
8f873415f71080725290cbfb29431570
|
|
| BLAKE2b-256 |
f40e16ae06894ffaa5ccb6935672715557e33ae74baabd16168771a569529781
|
File details
Details for the file jj_spec_validator-1.0.0-py3-none-any.whl.
File metadata
- Download URL: jj_spec_validator-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc838784f4be5dada0528397a4824d982d368c268f695b830ea87bd1b8f6b554
|
|
| MD5 |
1543bfa495ecaaaf81570331775e09d2
|
|
| BLAKE2b-256 |
f0fc382ca6438f016ea81b690d80703963d63cbd89521030023c6acb30f02109
|