Skip to content

fix: pystapi-validator #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion pystapi-validator/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 2 additions & 18 deletions pystapi-validator/tests/validate_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand Down
24 changes: 20 additions & 4 deletions scripts/validate-stapi-fastapi
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading