[Python] Validate specific value in JsonSchema with Python

Discussão em 'Python' iniciado por Stack, Abril 11, 2025.

  1. Stack

    Stack Membro Participativo

    Friends, given structure below how to validate if the "title" field must contain the value "delectus aut autem"

    I would also like to know if the gender field has the "male/female" value as I would validate too.

    def test_get():
    response = requests.get(ENDPOINT)
    assert response.status_code == 200
    data = response.json()
    print(data)
    print(data['title'])

    def test_body():
    schema = {
    "type": "object",
    "properties": {
    "id": {"type": "integer"},
    "title": {"type": "string"},

    },
    }

    validate(instance={"id": 1, "title": "delectus aut autem"}, schema=schema)
    # No error, the JSON is valid.

    Continue reading...

Compartilhe esta Página