Skip to content

Commit

Permalink
fix(type-safe-api): deserialize python body with model_validate inste…
Browse files Browse the repository at this point in the history
…ad of from_json (#686)

A bug in OpenAPI Generator can cause some fields to be omitted when deserializing python models
which make use of `allOf` to compose schemas:

OpenAPITools/openapi-generator#12778

Instead of using the generated `from_json` method which may omit fields to deserialize, we use the
pydantic `model_validate` method directly.
  • Loading branch information
cogwirrel authored Jan 23, 2024
1 parent 43c0d6d commit 96cab35
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def parse_body(body, content_types, model):
"""
if len([c for c in content_types if c != 'application/json']) == 0:
if model != Any:
body = model.from_json(body)
body = model.model_validate(json.loads(body))
else:
body = json.loads(body or '{}')
return body
Expand Down

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

0 comments on commit 96cab35

Please sign in to comment.