Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): Create workaround for null union with multiple types #64834

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading