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. Control discrepancy handling with validate_level key:

    • "warning" (default, logs a warning, continues execution)
    • "error" (raises exceptions, stops execution)
    • "skip" (skips validation)
  2. Control the output mode of warning messages with the output_mode key:

    • "std" (default, prints warnings to stdout)
    • "file" (writes warnings to a file)

Note: The output_mode parameter is only applicable when validate_level is set to "warning"

  1. is_strict key will allow choosing between strict and non-strict comparison. False 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")
    ...

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.4.tar.gz (6.5 kB view hashes)

Uploaded Source

Built Distribution

jj_spec_validator-0.1.4-py3-none-any.whl (7.3 kB view hashes)

Uploaded Python 3

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