diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 000c662..3b28e6a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,9 +32,16 @@ jobs: run: uv run pytest - name: Validate test server run: uv run scripts/validate-stapi-fastapi + continue-on-error: true + - name: Upload Validation Report + uses: actions/upload-artifact@v4 + with: + name: validation-report-py${{ matrix.python-version }} + path: validation-report.html - name: Docs run: uv run mkdocs build --strict - - uses: actions/upload-pages-artifact@v3 + - name: Upload Docs + uses: actions/upload-pages-artifact@v3 if: ${{ matrix.python-version == '3.12' }} with: path: site/ diff --git a/pyproject.toml b/pyproject.toml index 6035214..18bc76d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -81,7 +81,8 @@ filterwarnings = [ "error", "ignore:The 'app' shortcut is now deprecated.:DeprecationWarning", "ignore:Pydantic serializer warnings:UserWarning", - "ignore:jsonschema.exceptions.RefResolutionError is deprecated:DeprecationWarning", + "default:jsonschema.exceptions.RefResolutionError is deprecated:DeprecationWarning", + "default:jsonschema.RefResolver is deprecated as of v4.18.0:DeprecationWarning", ] markers = [ "mock_products", diff --git a/pystapi-validator/pyproject.toml b/pystapi-validator/pyproject.toml index 07436e7..dabaa7d 100644 --- a/pystapi-validator/pyproject.toml +++ b/pystapi-validator/pyproject.toml @@ -9,7 +9,7 @@ license = "MIT" readme = "README.md" requires-python = ">=3.10" dependencies = [ - "schemathesis>=3.37.0", + "schemathesis>=3.39.14", "pytest>=8.3.3", "requests>=2.32.3", "pyyaml>=6.0.2", diff --git a/pystapi-validator/tests/validate_api.py b/pystapi-validator/tests/validate_api.py index 6a31d20..74c19a1 100644 --- a/pystapi-validator/tests/validate_api.py +++ b/pystapi-validator/tests/validate_api.py @@ -2,14 +2,6 @@ import pytest import schemathesis -from schemathesis.checks import ( - content_type_conformance, - negative_data_rejection, - not_a_server_error, - response_headers_conformance, - response_schema_conformance, - status_code_conformance, -) schemathesis.experimental.OPEN_API_3_1.enable() @@ -21,19 +13,11 @@ @schema.parametrize() def test_api(case): - response = case.call_and_validate(base_url=BASE_URL) - case.validate_response(response) - - not_a_server_error(response, case) - status_code_conformance(response, case) - content_type_conformance(response, case) - response_schema_conformance(response, case) - response_headers_conformance(response, case) - negative_data_rejection(response, case) + case.call_and_validate(base_url=BASE_URL) def test_openapi_specification(): - assert schema.validate() + schema.validate() @pytest.hookimpl(tryfirst=True, hookwrapper=True) diff --git a/scripts/validate-stapi-fastapi b/scripts/validate-stapi-fastapi index 8852fcb..819cacc 100755 --- a/scripts/validate-stapi-fastapi +++ b/scripts/validate-stapi-fastapi @@ -5,17 +5,33 @@ set -e scripts="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" root=$(dirname "$scripts") +echo "Starting test server" uv run fastapi dev "$root/stapi-fastapi/tests/application.py" >/dev/null 2>&1 & server_pid=$! set +e -"$scripts"/wait-for-it.sh localhost:8000 -- test 0 # TODO update to validate -result=$? +"$scripts"/wait-for-it.sh localhost:8000 -- test 0 +wait_result=$? set -e +if [ $wait_result -ne 0 ]; then + echo "Failed to start test server" + kill $(pgrep -P $server_pid) + exit 1 +fi + +set +e +echo "Validating API" +uv run pytest "$root/pystapi-validator/tests/validate_api.py" --html=validation-report.html --self-contained-html +validation_result=$? +set -e + +echo "Stopping test server" kill $(pgrep -P $server_pid) -if [ $result ]; then + +if [ $validation_result -eq 0 ]; then echo "Validated OK!" else - exit $result + echo "Validation failed!" + exit 1 fi diff --git a/uv.lock b/uv.lock index 42e2766..b38f092 100644 --- a/uv.lock +++ b/uv.lock @@ -1316,7 +1316,7 @@ requires-dist = [ { name = "pytest-metadata", specifier = ">=3.1.1" }, { name = "pyyaml", specifier = ">=6.0.2" }, { name = "requests", specifier = ">=2.32.3" }, - { name = "schemathesis", specifier = ">=3.37.0" }, + { name = "schemathesis", specifier = ">=3.39.14" }, ] [[package]]