openapi: Add hacky support for oneOf parameter types.

This is required for the upcoming type behavior of the "anchor"
parameter.

This change is the minimal work required to have our OpenAPI code not
fail when checking a union-type value of this form.  We'll likely want
to, in the future, do something nicer, but it'd require more extensive
infrastructure for parsing of OpenAPI data that it's worth with our
current approach (we may want to switch to using a library).
This commit is contained in:
Tim Abbott
2020-01-27 22:28:22 -08:00
parent 62500bcfae
commit c0712431df
2 changed files with 17 additions and 4 deletions

View File

@@ -377,9 +377,15 @@ do not match the types declared in the implementation of {}.\n""".format(functio
openapi_params = set() # type: Set[Tuple[str, Union[type, Tuple[type, object]]]]
for element in openapi_parameters:
name = element["name"] # type: str
_type = VARMAP[element["schema"]["type"]]
schema = element["schema"]
if 'oneOf' in schema:
# Hack: Just use the type of the first value
# Ideally, we'd turn this into a Union type.
_type = VARMAP[schema['oneOf'][0]['type']]
else:
_type = VARMAP[schema["type"]]
if _type == list:
items = element["schema"]["items"]
items = schema["items"]
if "anyOf" in items.keys():
subtypes = []
for st in items["anyOf"]: