Skip to content

Commit

Permalink
fix(api): Create workaround for null union with multiple types (#64834)
Browse files Browse the repository at this point in the history
See comment in code for detail
  • Loading branch information
schew2381 authored Feb 8, 2024
1 parent 8ec3015 commit 8fc6989
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/sentry/apidocs/spectacular_ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,18 @@ def resolve_type_hint(hint) -> Any:
else:
schema = resolve_type_hint(type_args[0])
if type(None) in args:
schema["nullable"] = True
# There's an issue where if 3 or more types are OR'd together and one of
# them is None, validating the schema will fail because "nullable: true"
# with "anyOf" raises an error because there is no "type" key on the
# schema. This works around it by including a proxy null object in
# the "anyOf".
# See:
# - https://github.com/tfranzel/drf-spectacular/issues/925
# - https://github.com/OAI/OpenAPI-Specification/issues/1368.
if len(args) > 2:
schema["oneOf"].append({"type": "object", "nullable": True})
else:
schema["nullable"] = True
return schema
elif origin is collections.abc.Iterable:
return build_array_type(resolve_type_hint(args[0]))
Expand Down

0 comments on commit 8fc6989

Please sign in to comment.