Skip to content

Support multiple content types for a single endpoint #453

Description

@dpursehouse

With an openapi yaml schema that has this content:

 requestBody:
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/REDACTED'
application/x-www-form-urlencoded:
schema:
type: array
items:
$ref: '#/components/schemas/REDACTED'
multipart/form-data:
schema:
type: array
items:
$ref: '#/components/schemas/REDACTED'
required: true

The generated client has this method:

def _get_kwargs(
*,
client: AuthenticatedClient,
multipart_data: List[REDACTED],
json_body: List[REDACTED],
) -> Dict[str, Any]:
url = "{}/api/redacted/".format(client.base_url)
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()
json_json_body = []
for json_body_item_data in json_body:
json_body_item = json_body_item_data.to_dict()
json_json_body.append(json_body_item)
multipart_multipart_data = []
for multipart_data_item_data in multipart_data:
multipart_data_item = multipart_data_item_data.to_dict()
multipart_multipart_data.append(multipart_data_item)
return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"files": multipart_multipart_data,
}

The diff from the client generated by version 0.9.2 is that it now takes a multipart_data parameter which is now used to populate the files field on the returned dict.

However the json field was removed and the json_body parameter is thus unused. This breaks clients that are passing the json_body field.

Adding it back fixes it, i.e.

 return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"json": json_json_body, # <--- HERE
"files": multipart_multipart_data,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions