Skip to content

Commit

Permalink
Handle type when it is a list
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiku committed Aug 7, 2024
1 parent f3ed700 commit f70f5b5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions flask_rebar/swagger_generation/generator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,17 @@ def flatten(schema: Dict[str, Any], base: str) -> Tuple[Dict[str, str], Dict[str
def _flatten(
schema: Dict[str, Any], definitions: Dict[str, Any], base: str
) -> Dict[str, str]:
schema_type = schema.get(sw.type_)
# With OpenAPI 3.1, this will be an array of allowed types that includes sw.null if allow_none=True.
schema_type: str | list[str] = schema.get(sw.type_)
schema_types = schema_type if type(schema_type) is list else [schema_type]
subschema_keyword = _get_subschema_keyword(schema)

if schema_type == sw.object_:
if sw.object_ in schema_types:
properties = schema.get(sw.properties, {})
for key, prop in properties.items():
properties[key] = _flatten(schema=prop, definitions=definitions, base=base)

elif schema_type == sw.array:
elif sw.array in schema_types:
schema[sw.items] = _flatten(
schema=schema[sw.items], definitions=definitions, base=base
)
Expand Down

0 comments on commit f70f5b5

Please sign in to comment.