Agent guide for openapi-schema-validator.
Use this as the default operating playbook when making changes.
- Language: Python.
- Build backend and packaging: Poetry (
poetry-core). - Runtime package:
openapi_schema_validator/. - Tests:
pytestintests/unitandtests/integration. - Type checking:
mypywithstrict = true. - Formatting and imports:
blackandisort. - Extra static analysis:
deptry. - Supported Python versions: 3.10, 3.11, 3.12, 3.13, 3.14.
openapi_schema_validator/__init__.py: public exports + package metadata.openapi_schema_validator/validators.py: validator class setup for OAS 3.0/3.1/3.2.openapi_schema_validator/_keywords.py: custom keyword handlers and ValidationError generation.openapi_schema_validator/_format.py: format checker functions and registrations.openapi_schema_validator/_types.py: custom type checker setup.openapi_schema_validator/shortcuts.py: top-levelvalidatehelper.tests/unit/: focused unit tests.tests/integration/: validator behavior integration coverage.docs/: Sphinx source files.
- Install Poetry.
- Recommended one-time config:
poetry config virtualenvs.in-project true
- Install dependencies:
poetry install
- Include docs toolchain when needed:
poetry install --with docs
Run commands from repository root.
poetry installpoetry install --all-extras(matches CI tests job)
- Full suite:
poetry run pytest - Unit only:
poetry run pytest tests/unit - Integration only:
poetry run pytest tests/integration
- Single file:
poetry run pytest tests/unit/test_shortcut.py - Single test function:
poetry run pytest tests/unit/test_shortcut.py::test_validate_does_not_mutate_schema
- Single test class:
poetry run pytest tests/integration/test_validators.py::TestOAS31ValidatorValidate
- Pattern selection:
poetry run pytest -k nullable
poetry run mypy
- Full pre-commit run:
poetry run pre-commit run -a - Staged files pre-commit run:
poetry run pre-commit run - Format explicitly:
poetry run black . - Sort imports explicitly:
poetry run isort . - Convert to f-strings where safe:
poetry run flynt . - Dependency hygiene:
poetry run deptry .
- Build distributions:
poetry build - Build docs (CI-equivalent command):
poetry run python -m sphinx -T -b html -d docs/_build/doctrees -D language=en docs docs/_build/html -n -W
- Default
pytestoptions are defined inpyproject.toml. - Normal runs are verbose and include local variable display on failures.
- Reports are generated in
reports/junit.xmlandreports/coverage.xml. - Coverage is collected for
openapi_schema_validatorby default. - Test commands usually update files under
reports/.
- Black line length is 79; keep new code Black-compatible.
- Prefer clear, wrapped multi-line literals for schemas and parametrized test data.
- Follow existing wrapping style for function signatures and long calls.
- Isort is configured with
profile = "black",line_length = 79, andforce_single_line = true. - Import one symbol per line in
from ... import ...blocks. - Keep import grouping conventional: stdlib, third-party, local package.
- Prefer absolute imports from
openapi_schema_validator.
- Keep all new functions fully type-annotated (mypy strict mode).
- Use
Mapping[str, Any]for schema-like readonly mappings. - Use
Iterator[ValidationError]for keyword handler generators. - Use
Anyandcast(...)only when necessary for interop with jsonschema internals.
- Functions and variables:
snake_case. - Classes:
PascalCase. - Constants:
UPPER_SNAKE_CASE(e.g., validator maps). - Tests:
test_*functions; group withTest*classes when useful. - Preserve OpenAPI field spellings exactly (
readOnly,writeOnly,nullable, etc.).
- Validation failures should raise or yield
jsonschema.exceptions.ValidationError. - Prefer narrow exception handling (
FormatError, etc.) instead of broad catches. - If broad catches are required for ref-resolution boundaries, convert to explicit
ValidationErrormessages. - Keep error text stable and human-readable; tests assert message content.
- Preserve
Nonereturn behavior for successful.validate(...)paths.
- Do not mutate incoming schema objects in helper APIs.
- Maintain compatibility for OAS 3.0, OAS 3.1, and OAS 3.2 validators.
- Keep existing read/write behavior around
readOnlyandwriteOnly. - Keep format and type checker semantics aligned with current tests.
- For small edits, run the most targeted pytest selection first.
- Before handoff when feasible, run:
poetry run pytestpoetry run mypypoetry run pre-commit run -a
- If you changed dependencies/import graph, also run
poetry run deptry ..
- CI tests run on Python 3.10-3.14.
- CI static checks run via
pre-commit. - CI docs job builds Sphinx docs with warnings treated as errors.
- Keep local validation aligned with
.github/workflows/.
.cursor/rules/was not found..cursorruleswas not found..github/copilot-instructions.mdwas not found.- If any of these appear later, treat them as higher-priority instructions and update this guide.
- Read
pyproject.tomland the nearest related module/tests before editing. - Make minimal, focused changes that match existing patterns.
- Add or update tests in the closest relevant test module.
- Run a single-test command first, then broader checks.
- Keep
openapi_schema_validator/__init__.pyexports synchronized if public API changes.