typespec1-10 Exercise 2: A Python Client for the Member Service ==================================================================== Generated with: openapi-python-client generate --path members.yaml --meta none --output-path gen (0.29.1; it warned only that ruff was not installed) Files of interest: gen/api/default/members_list.py, members_read.py, members_create.py; gen/models/member.py, create_member.py the script (try_members.py): from gen import Client from gen.api.default import members_create, members_list, members_read from gen.models import CreateMember client = Client(base_url="http://127.0.0.1:4011") # the Prism mock from Exercise 1 ... four calls: list, read 'x', create valid, create invalid ... Results: list status=200 parsed=list read x (no override) status=200 parsed=Member create (valid) status=200 parsed=Member create (invalid) status=422 parsed=NoneType WHAT THE CLIENT DID WITH THE INVALID CREATE It sent it. CreateMember(code='ab1234', name='A', age=15) was built without any complaint, because the generated model has no pattern, length or range checks (I searched create_member.py for them: nothing). The mock replied 422, a status this contract does not declare, so the client had no model to parse it into and returned parsed=None (no exception). So the only thing that rejected the data was the mock server. 'read x' returned a Member with status 200 because I did not send 'Prefer: code=404'; the mock returns the first documented success by default. LIMITS I did not look at how the client behaves with a documented error that has a body (the Book Service client in the chapter did: it returned a typed NotFound). WHY THIS WORKS AS AN ANSWER --------------------------- It makes the chapter's point with a different contract: the checks in the contract live in the mock (and in whatever validator you add), not in the generated model classes.