Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,14 @@ def _convert_parameter_schema(
if "pattern" in param_data:
schema["pattern"] = param_data["pattern"]

# A repeated parameter takes a list of values, each matching the schema
# above. Its default moves to the array as a one-item list.
if param_data.get("repeated", False):
item_schema = schema
schema = {"type": "array", "items": item_schema}
if "default" in item_schema:
schema["default"] = [item_schema.pop("default")]

return schema

def save_openapi_spec(self, output_path: str) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ def calendar_api_spec():
"enum": ["startTime", "updated"],
"location": "query",
},
"eventTypes": {
"type": "string",
"description": "Event types to return",
"enum": [
"default",
"focusTime",
"outOfOffice",
],
"repeated": True,
"location": "query",
},
},
"response": {"$ref": "Events"},
"scopes": [
Expand Down Expand Up @@ -581,6 +592,32 @@ def test_extract_path_parameters(self, converter, path, expected_params):
{"type": "string", "enum": ["option1", "option2"]},
{"type": "string", "enum": ["option1", "option2"]},
),
# Repeated parameter
(
{"type": "string", "repeated": True},
{"type": "array", "items": {"type": "string"}},
),
# Repeated enum parameter
(
{
"type": "string",
"enum": ["option1", "option2"],
"repeated": True,
},
{
"type": "array",
"items": {"type": "string", "enum": ["option1", "option2"]},
},
),
# Repeated parameter with default
(
{"type": "string", "default": "LIVE", "repeated": True},
{
"type": "array",
"items": {"type": "string"},
"default": ["LIVE"],
},
),
],
)
def test_convert_parameter_schema(
Expand Down Expand Up @@ -739,6 +776,24 @@ def test_integration_calendar_api(self, converter_with_patched_build):
assert max_results["schema"]["type"] == "integer"
assert max_results["schema"]["default"] == "250"

def test_convert_repeated_query_parameter_to_array(
self, converter_with_patched_build
):
"""A query parameter marked repeated accepts a list of values."""
openapi_spec = converter_with_patched_build.convert()

get_events = openapi_spec["paths"]["/calendars/{calendarId}/events"]["get"]
param_dict = {p["name"]: p for p in get_events["parameters"]}
event_types = param_dict["eventTypes"]
assert event_types["in"] == "query"
assert event_types["schema"] == {
"type": "array",
"items": {
"type": "string",
"enum": ["default", "focusTime", "outOfOffice"],
},
}


@pytest.fixture
def conftest_content():
Expand Down
Loading