local-inference-service / tests /test_openapi_docs.py
fashxp's picture lukmzig's picture
BPT adjustments: batched embedding API, normalized vectors, resource limits, lint/type/test gate (#3)
ed962ac
Raw History Blame Contribute Delete
1.99 kB
# -------------------------------------------------------------------
# This source file is available under the terms of the
# Pimcore Open Core License (POCL)
# Full copyright and license information is available in
# LICENSE.md which is distributed with this source code.
# -------------------------------------------------------------------
"""OpenAPI-contract tests: a POST endpoint that documents no request body is undiscoverable from
the generated docs — Swagger UI renders no input widget and a caller has nothing to go on. Needs
no model weights."""
from src import main
SCHEMA = main.app.openapi()
IMAGE_TO_TEXT_BODY = "/image-to-text/{model_name}"
def test_image_to_text_documents_its_multipart_body():
"""`image_to_text` takes a raw ``Request`` rather than a typed model, so FastAPI cannot infer
the body — the multipart schema has to be declared explicitly via ``openapi_extra`` or the
endpoint appears to take no input at all.
"""
schema = SCHEMA["paths"][IMAGE_TO_TEXT_BODY]["post"]["requestBody"]["content"]["multipart/form-data"]["schema"]
assert schema["properties"]["image"]["format"] == "binary"
assert schema["required"] == ["image"]
def test_image_to_text_documents_its_raw_image_body():
"""``get_encoded_image`` accepts a raw ``image/*`` body as well as the multipart form, so both
accepted content types belong in the docs — see ``TextToImageTaskService.get_encoded_image``.
"""
content = SCHEMA["paths"][IMAGE_TO_TEXT_BODY]["post"]["requestBody"]["content"]
assert content["image/*"]["schema"]["format"] == "binary"
def test_every_post_endpoint_documents_a_request_body():
"""Guards the general case, so the next endpoint taking a raw ``Request`` cannot silently ship
without a documented body.
"""
missing = [
path
for path, operations in SCHEMA["paths"].items()
if "post" in operations and "requestBody" not in operations["post"]
]
assert missing == []