|
| 1 | +OpenAPI-Aided Help and Validation |
| 2 | +================================= |
| 3 | + |
| 4 | +Overview |
| 5 | +-------- |
| 6 | + |
| 7 | +Zyra can use an API's OpenAPI 3.0 specification to provide request hints and |
| 8 | +perform lightweight validation before issuing requests. |
| 9 | + |
| 10 | +CLI (``zyra acquire api``) |
| 11 | +-------------------------- |
| 12 | + |
| 13 | +- ``--openapi-help`` |
| 14 | + Fetches the service's OpenAPI spec and prints a summary for the resolved |
| 15 | + operation (required/optional query and header parameters, requestBody content types, |
| 16 | + and best-effort response content types). This does not send the request. |
| 17 | + |
| 18 | +- ``--openapi-validate`` |
| 19 | + Validates the provided ``--header``, ``--params``, and ``--data`` (when |
| 20 | + present) against the spec. Prints issues to stderr. |
| 21 | + |
| 22 | +- ``--openapi-strict`` |
| 23 | + With ``--openapi-validate``, exits non-zero when issues are found. |
| 24 | + |
| 25 | +API (``POST /v1/acquire/api``) |
| 26 | +------------------------------ |
| 27 | + |
| 28 | +- ``openapi_validate``: boolean. When true, validates the request before issuing it. |
| 29 | + Returns HTTP 400 with ``{"errors": [...]}`` on issues. |
| 30 | +- ``openapi_strict``: boolean. Defaults to true; controls whether issues are fatal. |
| 31 | + |
| 32 | +What is validated |
| 33 | +----------------- |
| 34 | + |
| 35 | +- Required query and header parameters. |
| 36 | +- Required ``requestBody`` presence. |
| 37 | +- ``requestBody`` Content-Type compatibility. |
| 38 | +- Simple parameter checks when values are present: |
| 39 | + - ``enum`` membership |
| 40 | + - Basic ``type`` checks (string/integer/number/boolean) |
| 41 | +- Optional JSON Schema validation for ``application/json`` requestBody when |
| 42 | + ``jsonschema`` is installed in the environment. |
| 43 | + |
| 44 | +Notes |
| 45 | +----- |
| 46 | + |
| 47 | +- Zyra uses a best-effort resolver for operations, matching the longest |
| 48 | + templated path (e.g., ``/v1/items/{id}``) with segment-aware scoring. |
| 49 | +- When the OpenAPI spec is unavailable, help and validation are skipped. |
| 50 | + |
| 51 | +Examples |
| 52 | +-------- |
| 53 | + |
| 54 | +Example OpenAPI snippet |
| 55 | +~~~~~~~~~~~~~~~~~~~~~~~ |
| 56 | + |
| 57 | +.. code-block:: json |
| 58 | +
|
| 59 | + { |
| 60 | + "openapi": "3.0.0", |
| 61 | + "paths": { |
| 62 | + "/v1/items": { |
| 63 | + "get": { |
| 64 | + "parameters": [ |
| 65 | + {"in": "query", "name": "q", "required": true, "schema": {"type": "string"}}, |
| 66 | + {"in": "query", "name": "limit", "schema": {"type": "integer"}} |
| 67 | + ], |
| 68 | + "responses": { |
| 69 | + "200": {"content": {"application/json": {}}} |
| 70 | + } |
| 71 | + } |
| 72 | + }, |
| 73 | + "/v1/items/{id}": { |
| 74 | + "get": { |
| 75 | + "parameters": [ |
| 76 | + {"in": "path", "name": "id", "required": true, "schema": {"type": "string"}} |
| 77 | + ], |
| 78 | + "responses": { |
| 79 | + "200": {"content": {"application/json": {}}} |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | +
|
| 86 | +CLI |
| 87 | +~~~ |
| 88 | + |
| 89 | +.. code-block:: bash |
| 90 | +
|
| 91 | + # Print required params for GET /v1/items |
| 92 | + zyra acquire api \ |
| 93 | + --url https://api.example/v1/items \ |
| 94 | + --openapi-help |
| 95 | +
|
| 96 | + # Validate current flags (warn-only) |
| 97 | + zyra acquire api \ |
| 98 | + --url https://api.example/v1/items \ |
| 99 | + --params q=wind \ |
| 100 | + --openapi-validate |
| 101 | +
|
| 102 | + # Validate strictly (exit non-zero on issues) |
| 103 | + zyra acquire api \ |
| 104 | + --url https://api.example/v1/items \ |
| 105 | + --openapi-validate --openapi-strict |
| 106 | +
|
| 107 | +HTTP |
| 108 | +~~~~ |
| 109 | + |
| 110 | +.. code-block:: bash |
| 111 | +
|
| 112 | + # Validate via API (400 on issues) |
| 113 | + curl -sS -X POST http://localhost:8000/v1/acquire/api \ |
| 114 | + -H 'Content-Type: application/json' \ |
| 115 | + -d '{"url": "https://api.example/v1/items", "openapi_validate": true}' |
| 116 | +
|
0 commit comments