|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +Agent guide for `openapi-schema-validator`. |
| 4 | +Use this as the default operating playbook when making changes. |
| 5 | + |
| 6 | +## Project Snapshot |
| 7 | + |
| 8 | +- Language: Python. |
| 9 | +- Build backend and packaging: Poetry (`poetry-core`). |
| 10 | +- Runtime package: `openapi_schema_validator/`. |
| 11 | +- Tests: `pytest` in `tests/unit` and `tests/integration`. |
| 12 | +- Type checking: `mypy` with `strict = true`. |
| 13 | +- Formatting and imports: `black` and `isort`. |
| 14 | +- Extra static analysis: `deptry`. |
| 15 | +- Supported Python versions: 3.10, 3.11, 3.12, 3.13, 3.14. |
| 16 | + |
| 17 | +## Source Layout |
| 18 | + |
| 19 | +- `openapi_schema_validator/__init__.py`: public exports + package metadata. |
| 20 | +- `openapi_schema_validator/validators.py`: validator class setup for OAS 3.0/3.1. |
| 21 | +- `openapi_schema_validator/_keywords.py`: custom keyword handlers and ValidationError generation. |
| 22 | +- `openapi_schema_validator/_format.py`: format checker functions and registrations. |
| 23 | +- `openapi_schema_validator/_types.py`: custom type checker setup. |
| 24 | +- `openapi_schema_validator/shortcuts.py`: top-level `validate` helper. |
| 25 | +- `tests/unit/`: focused unit tests. |
| 26 | +- `tests/integration/`: validator behavior integration coverage. |
| 27 | +- `docs/`: Sphinx source files. |
| 28 | + |
| 29 | +## Environment Setup |
| 30 | + |
| 31 | +1. Install Poetry. |
| 32 | +2. Recommended one-time config: |
| 33 | + - `poetry config virtualenvs.in-project true` |
| 34 | +3. Install dependencies: |
| 35 | + - `poetry install` |
| 36 | +4. Include docs toolchain when needed: |
| 37 | + - `poetry install --with docs` |
| 38 | + |
| 39 | +## Build, Lint, and Test Commands |
| 40 | + |
| 41 | +Run commands from repository root. |
| 42 | + |
| 43 | +### Install / bootstrap |
| 44 | + |
| 45 | +- `poetry install` |
| 46 | +- `poetry install --all-extras` (matches CI tests job) |
| 47 | + |
| 48 | +### Test suite |
| 49 | + |
| 50 | +- Full suite: `poetry run pytest` |
| 51 | +- Unit only: `poetry run pytest tests/unit` |
| 52 | +- Integration only: `poetry run pytest tests/integration` |
| 53 | + |
| 54 | +### Running a single test (important) |
| 55 | + |
| 56 | +- Single file: `poetry run pytest tests/unit/test_shortcut.py` |
| 57 | +- Single test function: |
| 58 | + - `poetry run pytest tests/unit/test_shortcut.py::test_validate_does_not_mutate_schema` |
| 59 | +- Single test class: |
| 60 | + - `poetry run pytest tests/integration/test_validators.py::TestOAS31ValidatorValidate` |
| 61 | +- Pattern selection: `poetry run pytest -k nullable` |
| 62 | + |
| 63 | +### Type checks |
| 64 | + |
| 65 | +- `poetry run mypy` |
| 66 | + |
| 67 | +### Lint / formatting / static checks |
| 68 | + |
| 69 | +- Full pre-commit run: `poetry run pre-commit run -a` |
| 70 | +- Staged files pre-commit run: `poetry run pre-commit run` |
| 71 | +- Format explicitly: `poetry run black .` |
| 72 | +- Sort imports explicitly: `poetry run isort .` |
| 73 | +- Convert to f-strings where safe: `poetry run flynt .` |
| 74 | +- Dependency hygiene: `poetry run deptry .` |
| 75 | + |
| 76 | +### Build package / docs |
| 77 | + |
| 78 | +- Build distributions: `poetry build` |
| 79 | +- Build docs (CI-equivalent command): |
| 80 | + - `poetry run python -m sphinx -T -b html -d docs/_build/doctrees -D language=en docs docs/_build/html -n -W` |
| 81 | + |
| 82 | +## Pytest Behavior Notes |
| 83 | + |
| 84 | +- Default `pytest` options are defined in `pyproject.toml`. |
| 85 | +- Normal runs are verbose and include local variable display on failures. |
| 86 | +- Reports are generated in `reports/junit.xml` and `reports/coverage.xml`. |
| 87 | +- Coverage is collected for `openapi_schema_validator` by default. |
| 88 | +- Test commands usually update files under `reports/`. |
| 89 | + |
| 90 | +## Code Style Rules (Repository-Specific) |
| 91 | + |
| 92 | +### Formatting |
| 93 | + |
| 94 | +- Black line length is 79; keep new code Black-compatible. |
| 95 | +- Prefer clear, wrapped multi-line literals for schemas and parametrized test data. |
| 96 | +- Follow existing wrapping style for function signatures and long calls. |
| 97 | + |
| 98 | +### Imports |
| 99 | + |
| 100 | +- Isort is configured with `profile = "black"`, `line_length = 79`, and `force_single_line = true`. |
| 101 | +- Import one symbol per line in `from ... import ...` blocks. |
| 102 | +- Keep import grouping conventional: stdlib, third-party, local package. |
| 103 | +- Prefer absolute imports from `openapi_schema_validator`. |
| 104 | + |
| 105 | +### Types |
| 106 | + |
| 107 | +- Keep all new functions fully type-annotated (mypy strict mode). |
| 108 | +- Use `Mapping[str, Any]` for schema-like readonly mappings. |
| 109 | +- Use `Iterator[ValidationError]` for keyword handler generators. |
| 110 | +- Use `Any` and `cast(...)` only when necessary for interop with jsonschema internals. |
| 111 | + |
| 112 | +### Naming conventions |
| 113 | + |
| 114 | +- Functions and variables: `snake_case`. |
| 115 | +- Classes: `PascalCase`. |
| 116 | +- Constants: `UPPER_SNAKE_CASE` (e.g., validator maps). |
| 117 | +- Tests: `test_*` functions; group with `Test*` classes when useful. |
| 118 | +- Preserve OpenAPI field spellings exactly (`readOnly`, `writeOnly`, `nullable`, etc.). |
| 119 | + |
| 120 | +### Error handling and validation behavior |
| 121 | + |
| 122 | +- Validation failures should raise or yield `jsonschema.exceptions.ValidationError`. |
| 123 | +- Prefer narrow exception handling (`FormatError`, etc.) instead of broad catches. |
| 124 | +- If broad catches are required for ref-resolution boundaries, convert to explicit `ValidationError` messages. |
| 125 | +- Keep error text stable and human-readable; tests assert message content. |
| 126 | +- Preserve `None` return behavior for successful `.validate(...)` paths. |
| 127 | + |
| 128 | +### Behavioral constraints to preserve |
| 129 | + |
| 130 | +- Do not mutate incoming schema objects in helper APIs. |
| 131 | +- Maintain compatibility for both OAS 3.0 and OAS 3.1 validators. |
| 132 | +- Keep existing read/write behavior around `readOnly` and `writeOnly`. |
| 133 | +- Keep format and type checker semantics aligned with current tests. |
| 134 | + |
| 135 | +## Testing Expectations for Changes |
| 136 | + |
| 137 | +- For small edits, run the most targeted pytest selection first. |
| 138 | +- Before handoff when feasible, run: |
| 139 | + - `poetry run pytest` |
| 140 | + - `poetry run mypy` |
| 141 | + - `poetry run pre-commit run -a` |
| 142 | +- If you changed dependencies/import graph, also run `poetry run deptry .`. |
| 143 | + |
| 144 | +## CI Parity Checklist |
| 145 | + |
| 146 | +- CI tests run on Python 3.10-3.14. |
| 147 | +- CI static checks run via `pre-commit`. |
| 148 | +- CI docs job builds Sphinx docs with warnings treated as errors. |
| 149 | +- Keep local validation aligned with `.github/workflows/`. |
| 150 | + |
| 151 | +## Cursor / Copilot Instructions Status |
| 152 | + |
| 153 | +- `.cursor/rules/` was not found. |
| 154 | +- `.cursorrules` was not found. |
| 155 | +- `.github/copilot-instructions.md` was not found. |
| 156 | +- If any of these appear later, treat them as higher-priority instructions and update this guide. |
| 157 | + |
| 158 | +## Practical Workflow for Agents |
| 159 | + |
| 160 | +1. Read `pyproject.toml` and the nearest related module/tests before editing. |
| 161 | +2. Make minimal, focused changes that match existing patterns. |
| 162 | +3. Add or update tests in the closest relevant test module. |
| 163 | +4. Run a single-test command first, then broader checks. |
| 164 | +5. Keep `openapi_schema_validator/__init__.py` exports synchronized if public API changes. |
0 commit comments