Compare commits

...

3 Commits

Author SHA1 Message Date
493991edd1 updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-04-10 18:36:19 -07:00
29003eae80 Update api spec (#211)
YOYO NEW API SPEC!

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-04-10 18:00:02 -07:00
79b977a55a fix test
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-04-05 13:30:47 -07:00
9 changed files with 1193 additions and 870 deletions

View File

@ -154,10 +154,19 @@ class WebSocket:
self.ws = sync(
{% for arg in args %}
{% if arg.in_query %}
{% if arg.is_optional == False %}
{{arg.name}},
{% endif %}
{% endif %}
{% endfor %}
client=client,
{% for arg in args %}
{% if arg.in_query %}
{% if arg.is_optional %}
{{arg.name}}={{arg.name}},
{% endif %}
{% endif %}
{% endfor %}
)
def __enter__(self,

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", items)
else:
raise Exception("Unknown array type")
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

@ -161,13 +161,13 @@ class WebSocket:
):
self.ws = sync(
fps,
pool,
post_effect,
unlocked_framerate,
video_res_height,
video_res_width,
webrtc,
client=client,
pool=pool,
)
def __enter__(

View File

@ -39,6 +39,7 @@ from .models import (
ModelingCmd,
ModelingCmdId,
Pong,
PostEffectType,
System,
TextToCad,
TextToCadCreateBody,
@ -356,6 +357,7 @@ def test_ws_simple():
with modeling_commands_ws.WebSocket(
client=client,
fps=30,
post_effect=PostEffectType.NOEFFECT,
unlocked_framerate=False,
video_res_height=360,
video_res_width=480,
@ -383,6 +385,7 @@ def test_ws_import():
with modeling_commands_ws.WebSocket(
client=client,
fps=30,
post_effect=PostEffectType.NOEFFECT,
unlocked_framerate=False,
video_res_height=360,
video_res_width=480,

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.9"
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"

132
spec.json
View File

@ -1746,6 +1746,138 @@
}
}
},
"/debug/uploads": {
"post": {
"tags": [
"meta",
"hidden"
],
"summary": "Uploads files to public blob storage for debugging purposes.",
"description": "Do NOT send files here that you don't want to be public.",
"operationId": "create_debug_uploads",
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"type": "string",
"format": "binary"
}
}
},
"required": true
},
"responses": {
"201": {
"description": "successful creation",
"headers": {
"Access-Control-Allow-Credentials": {
"description": "Access-Control-Allow-Credentials header.",
"style": "simple",
"required": true,
"schema": {
"type": "string"
}
},
"Access-Control-Allow-Headers": {
"description": "Access-Control-Allow-Headers header. This is a comma-separated list of headers.",
"style": "simple",
"required": true,
"schema": {
"type": "string"
}
},
"Access-Control-Allow-Methods": {
"description": "Access-Control-Allow-Methods header.",
"style": "simple",
"required": true,
"schema": {
"type": "string"
}
},
"Access-Control-Allow-Origin": {
"description": "Access-Control-Allow-Origin header.",
"style": "simple",
"required": true,
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"title": "Array_of_Url",
"type": "array",
"items": {
"type": "string",
"format": "uri"
}
}
}
}
},
"4XX": {
"$ref": "#/components/responses/Error"
},
"5XX": {
"$ref": "#/components/responses/Error"
}
}
},
"options": {
"tags": [
"hidden"
],
"summary": "OPTIONS endpoint.",
"description": "This is necessary for some preflight requests, specifically POST, PUT, and DELETE.",
"operationId": "options_create_debug_uploads",
"responses": {
"204": {
"description": "successful operation, no content",
"headers": {
"Access-Control-Allow-Credentials": {
"description": "Access-Control-Allow-Credentials header.",
"style": "simple",
"required": true,
"schema": {
"type": "string"
}
},
"Access-Control-Allow-Headers": {
"description": "Access-Control-Allow-Headers header. This is a comma-separated list of headers.",
"style": "simple",
"required": true,
"schema": {
"type": "string"
}
},
"Access-Control-Allow-Methods": {
"description": "Access-Control-Allow-Methods header.",
"style": "simple",
"required": true,
"schema": {
"type": "string"
}
},
"Access-Control-Allow-Origin": {
"description": "Access-Control-Allow-Origin header.",
"style": "simple",
"required": true,
"schema": {
"type": "string"
}
}
}
},
"4XX": {
"$ref": "#/components/responses/Error"
},
"5XX": {
"$ref": "#/components/responses/Error"
}
}
}
},
"/events": {
"post": {
"tags": [