Skip to main content

jj mocks validator for openapi specs

Project description

Usage

  1. 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)
  1. 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.

  2. 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.

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")
    ...
  1. is_raise_error key allows raising an error when a mismatch occurs. False by default.

  2. 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jj_spec_validator-0.1.12.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

jj_spec_validator-0.1.12-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file jj_spec_validator-0.1.12.tar.gz.

File metadata

  • Download URL: jj_spec_validator-0.1.12.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for jj_spec_validator-0.1.12.tar.gz
Algorithm Hash digest
SHA256 c5ac9c3f40e316dd9f67ebfc425aa512d869fef86bb1d8f77e7d239a5698653d
MD5 8c7fb6e633ca29caf006f2a6a7f94005
BLAKE2b-256 62f3e89acd12a94fd28294923803a6e7b4114c4e61843c41e2d0c657c76cbfd0

See more details on using hashes here.

File details

Details for the file jj_spec_validator-0.1.12-py3-none-any.whl.

File metadata

File hashes

Hashes for jj_spec_validator-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 d9858fc2dbe9d7c4c1baaddc00205546b0dee75b34e0b6f001f46a2046f69fa6
MD5 78ea1495698d09299ef78258f6209c01
BLAKE2b-256 a64cb023c07fa3c5e864181e2ee5dc232f24d6d1a168a61df2fabb326207e33c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page