Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2024-04-10 18:36:19 -07:00
parent 29003eae80
commit 493991edd1
5 changed files with 970 additions and 791 deletions

View File

@ -482,7 +482,7 @@ from kittycad.types import Response
# it here. Obviously this is a hack and we should fix the root cause.
# When this happens again with another struct there might be a more obvious
# solution, but alas, I am lazy.
if endpoint_ref != "PrivacySettings":
if endpoint_ref != "PrivacySettings" and endpoint_ref != "List[str]":
example_imports = example_imports + (
"""from kittycad.models import """
+ endpoint_ref.replace("List[", "").replace("]", "")
@ -846,6 +846,20 @@ async def test_"""
"\t\t\tfor item in response.json()\n"
)
parse_response.write("\t\t]\n")
elif "type" in items:
if items["type"] == "string":
parse_response.write(
"\t\tresponse_"
+ response_code
+ " = [\n"
)
parse_response.write("\t\t\tstr(**item)\n")
parse_response.write(
"\t\t\tfor item in response.json()\n"
)
parse_response.write("\t\t]\n")
else:
raise Exception("Unknown array type", items)
else:
raise Exception("Unknown array type")
elif json["type"] == "string":
@ -1728,8 +1742,13 @@ def getEndpointRefs(endpoint: dict, data: dict) -> List[str]:
if "$ref" in items:
ref = items["$ref"].replace("#/components/schemas/", "")
refs.append("List[" + ref + "]")
elif "type" in items:
if items["type"] == "string":
refs.append("List[str]")
else:
raise Exception("Unknown array type")
raise Exception("Unknown array type", items)
else:
raise Exception("Unknown array type", items)
elif json["type"] == "string":
refs.append("str")
elif (

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,104 @@
from typing import Any, Dict, List, Optional, Union
import httpx
from ...client import Client
from ...models.error import Error
from ...types import Response
def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/debug/uploads".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()
return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[List[str], Error]]:
if response.status_code == 201:
response_201 = [str(**item) for item in response.json()]
return response_201
if response.status_code == 400:
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error(**response.json())
return response_5XX
return Error(**response.json())
def _build_response(
*, response: httpx.Response
) -> Response[Optional[Union[List[str], Error]]]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)
def sync_detailed(
*,
client: Client,
) -> Response[Optional[Union[List[str], Error]]]:
kwargs = _get_kwargs(
client=client,
)
response = httpx.post(
verify=client.verify_ssl,
**kwargs,
)
return _build_response(response=response)
def sync(
*,
client: Client,
) -> Optional[Union[List[str], Error]]:
"""Do NOT send files here that you don't want to be public.""" # noqa: E501
return sync_detailed(
client=client,
).parsed
async def asyncio_detailed(
*,
client: Client,
) -> Response[Optional[Union[List[str], Error]]]:
kwargs = _get_kwargs(
client=client,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.post(**kwargs)
return _build_response(response=response)
async def asyncio(
*,
client: Client,
) -> Optional[Union[List[str], Error]]:
"""Do NOT send files here that you don't want to be public.""" # noqa: E501
return (
await asyncio_detailed(
client=client,
)
).parsed

View File

@ -51,6 +51,7 @@ from kittycad.api.hidden import (
post_auth_saml,
)
from kittycad.api.meta import (
create_debug_uploads,
create_event,
get_ipinfo,
get_metadata,
@ -1275,6 +1276,49 @@ async def test_post_auth_saml_async():
)
@pytest.mark.skip
def test_create_debug_uploads():
# Create our client.
client = ClientFromEnv()
result: Optional[Union[List[str], Error]] = create_debug_uploads.sync(
client=client,
)
if isinstance(result, Error) or result is None:
print(result)
raise Exception("Error in response")
body: List[str] = result
print(body)
# OR if you need more info (e.g. status_code)
response: Response[Optional[Union[List[str], Error]]] = (
create_debug_uploads.sync_detailed(
client=client,
)
)
# OR run async
@pytest.mark.asyncio
@pytest.mark.skip
async def test_create_debug_uploads_async():
# Create our client.
client = ClientFromEnv()
result: Optional[Union[List[str], Error]] = await create_debug_uploads.asyncio(
client=client,
)
# OR run async with more info
response: Response[Optional[Union[List[str], Error]]] = (
await create_debug_uploads.asyncio_detailed(
client=client,
)
)
@pytest.mark.skip
def test_create_event():
# Create our client.

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "kittycad"
version = "0.6.10"
version = "0.6.11"
description = "A client library for accessing KittyCAD"
authors = []
@ -11,6 +11,10 @@ packages = [
]
include = ["CHANGELOG.md", "kittycad/py.typed"]
[[tool.poetry.source]]
name = "pypi-public"
url = "https://pypi.org/simple/"
[tool.poetry.dependencies]
attrs = ">=20.1.0,<24.0.0"
httpx = ">=0.15.4,<0.26.0"