Skip to content

Support request bodies components #664

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

Closed
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 @@ -16,6 +16,7 @@
octet_stream_tests_octet_stream_get,
post_form_data,
post_form_data_inline,
post_form_data_ref,
post_tests_json_body_string,
test_inline_objects,
token_with_cookie_auth_token_with_cookie_get,
Expand Down Expand Up @@ -68,6 +69,13 @@ def post_form_data(cls) -> types.ModuleType:
"""
return post_form_data

@classmethod
def post_form_data_ref(cls) -> types.ModuleType:
"""
Post form data (ref request body)
"""
return post_form_data_ref

@classmethod
def post_form_data_inline(cls) -> types.ModuleType:
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from http import HTTPStatus
from typing import Any, Dict

import httpx

from ...client import Client
from ...models.a_form_data import AFormData
from ...types import Response


def _get_kwargs(
*,
client: Client,
form_data: AFormData,
) -> Dict[str, Any]:
url = "{}/tests/post_form_data_ref_body".format(client.base_url)

headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

return {
"method": "post",
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"data": form_data.to_dict(),
}


def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=None,
)


def sync_detailed(
*,
client: Client,
form_data: AFormData,
) -> Response[Any]:
"""Post form data (ref request body)

Post form data (ref request body)

Returns:
Response[Any]
"""

kwargs = _get_kwargs(
client=client,
form_data=form_data,
)

response = httpx.request(
verify=client.verify_ssl,
**kwargs,
)

return _build_response(response=response)


async def asyncio_detailed(
*,
client: Client,
form_data: AFormData,
) -> Response[Any]:
"""Post form data (ref request body)

Post form data (ref request body)

Returns:
Response[Any]
"""

kwargs = _get_kwargs(
client=client,
form_data=form_data,
)

async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.request(**kwargs)

return _build_response(response=response)
127 changes: 97 additions & 30 deletions end_to_end_tests/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,29 @@
}
}
},
"/tests/post_form_data_ref_body": {
"post": {
"tags": [
"tests"
],
"summary": "Post form data (ref request body)",
"description": "Post form data (ref request body)",
"operationId": "post_form_data_ref",
"requestBody": {
"$ref": "#/components/requestBodies/AFormBody"
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
}
}
}
},
"/tests/post_form_data_inline": {
"post": {
"tags": [
Expand Down Expand Up @@ -756,7 +779,9 @@
},
"/responses/unions/simple_before_complex": {
"post": {
"tags": ["responses"],
"tags": [
"responses"
],
"description": "Regression test for #603",
"responses": {
"200": {
Expand All @@ -765,12 +790,18 @@
"application/json": {
"schema": {
"type": "object",
"required": ["a"],
"required": [
"a"
],
"properties": {
"a": {
"oneOf": [
{"type": "string"},
{"type": "object"}
{
"type": "string"
},
{
"type": "object"
}
]
}
}
Expand Down Expand Up @@ -877,20 +908,20 @@
},
"parameters": [
{
"name": "param",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "param",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
"name": "param",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "param",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
]
},
"/same-name-multiple-locations/{param}": {
Expand Down Expand Up @@ -939,7 +970,9 @@
},
"/tag_with_number": {
"get": {
"tags": ["1"],
"tags": [
"1"
],
"responses": {
"200": {
"description": "Success"
Expand Down Expand Up @@ -1163,9 +1196,15 @@
{
"$ref": "#/components/parameters/integer-param"
},
{"$ref": "#/components/parameters/header-param"},
{"$ref": "#/components/parameters/cookie-param"},
{"$ref": "#/components/parameters/path-param"}
{
"$ref": "#/components/parameters/header-param"
},
{
"$ref": "#/components/parameters/cookie-param"
},
{
"$ref": "#/components/parameters/path-param"
}
],
"responses": {
"200": {
Expand Down Expand Up @@ -1477,7 +1516,11 @@
},
"Body_upload_file_tests_upload_post": {
"title": "Body_upload_file_tests_upload_post",
"required": ["some_file", "some_object", "some_nullable_object"],
"required": [
"some_file",
"some_object",
"some_nullable_object"
],
"type": "object",
"properties": {
"some_file": {
Expand Down Expand Up @@ -1519,7 +1562,10 @@
"some_object": {
"title": "Some Object",
"type": "object",
"required": ["num", "text"],
"required": [
"num",
"text"
],
"properties": {
"num": {
"type": "number"
Expand All @@ -1532,7 +1578,9 @@
"some_optional_object": {
"title": "Some Optional Object",
"type": "object",
"required": ["foo"],
"required": [
"foo"
],
"properties": {
"foo": {
"type": "string"
Expand Down Expand Up @@ -1755,7 +1803,10 @@
},
"type_enum": {
"type": "integer",
"enum": [0, 1]
"enum": [
0,
1
]
}
}
},
Expand All @@ -1768,11 +1819,15 @@
},
"type": {
"type": "string",
"enum": ["submodel"]
"enum": [
"submodel"
]
},
"type_enum": {
"type": "integer",
"enum": [0]
"enum": [
0
]
}
}
},
Expand Down Expand Up @@ -1915,7 +1970,7 @@
}
}
},
"ModelWithDateTimeProperty" : {
"ModelWithDateTimeProperty": {
"type": "object",
"properties": {
"datetime": {
Expand Down Expand Up @@ -2093,10 +2148,10 @@
"type": "string",
"format": "byte"
},
"import": {
"import": {
"type": "object"
},
"None": {
"None": {
"type": "object"
},
"model.reference.with.Periods": {
Expand Down Expand Up @@ -2167,6 +2222,18 @@
"type": "string"
}
}
},
"requestBodies": {
"AFormBody": {
"required": true,
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"$ref": "#/components/schemas/AFormData"
}
}
}
}
}
}
}
Loading