Skip to content

Undocumented response codes #114

@sobolevn

Description

@sobolevn

I runned schemathesis on django-ninja-jwt, it found several problems:

____________________________ test_api[POST /api/token/refresh] ____________________________
.venv/lib/python3.12/site-packages/schemathesis/_hypothesis.py:81: in test_api
    def test_function(*args: Any, **kwargs: Any) -> Any:
tests/test_schemathesis/test_schema.py:15: in test_api
    case.call_and_validate(base_url=str(live_server))
E   schemathesis.exceptions.CheckFailed: 
E   
E   1. Undocumented HTTP status code
E   
E       Received: 400
E       Documented: 200
E   
E   [400] Bad Request:
E   
E       `{"detail": "Invalid input.", "code": "invalid", "refresh": "token is required"}`
E   
E   Reproduce with: 
E   
E       curl -X POST -H 'Content-Type: application/json' -d '{"refresh": ""}' http://localhost/api/token/refresh
____________________________ test_api[POST /api/token/verify] _____________________________
.venv/lib/python3.12/site-packages/schemathesis/_hypothesis.py:81: in test_api
    def test_function(*args: Any, **kwargs: Any) -> Any:
tests/test_schemathesis/test_schema.py:15: in test_api
    case.call_and_validate(base_url=str(live_server))
E   schemathesis.exceptions.CheckFailed: 
E   
E   1. Undocumented HTTP status code
E   
E       Received: 400
E       Documented: 200
E   
E   [400] Bad Request:
E   
E       `{"detail": "Invalid input.", "code": "invalid", "token": "token is required"}`
E   
E   Reproduce with: 
E   
E       curl -X POST -H 'Content-Type: application/json' -d '{"token": ""}' http://localhost/api/token/verify
_____________________________ test_api[POST /api/token/pair] ______________________________
.venv/lib/python3.12/site-packages/schemathesis/_hypothesis.py:81: in test_api
    def test_function(*args: Any, **kwargs: Any) -> Any:
tests/test_schemathesis/test_schema.py:15: in test_api
    case.call_and_validate(base_url=str(live_server))
E   schemathesis.exceptions.CheckFailed: 
E   
E   1. Undocumented HTTP status code
E   
E       Received: 400
E       Documented: 200
E   
E   [400] Bad Request:
E   
E       `{"detail": "Invalid input.", "code": "invalid", "email": "email is required"}`
E   
E   Reproduce with: 
E   
E       curl -X POST -H 'Content-Type: application/json' -d '{"email": "", "password": ""}' http://localhost/api/token/pair

Reproducer:

from ninja_extra import NinjaExtraAPI
from ninja_jwt.controller import NinjaJWTDefaultController


api = NinjaExtraAPI()
api.register_controllers(NinjaJWTDefaultController)

and a test case:

import schemathesis
import pytest

from api import api

schema = api.get_openapi_schema()

schemathesis.experimental.OPEN_API_3_1.enable()
schema = schemathesis.from_dict(schema)


@schema.parametrize()
def test_api(case: schemathesis.Case, live_server):
    case.call_and_validate(base_url=str(live_server))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions