Compare commits

...

7 Commits

Author SHA1 Message Date
64e8aa2816 Update api spec (#212)
* YOYO NEW API SPEC!

* fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* I have generated the latest API!

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jess Frazelle <github@jessfraz.com>
2024-04-12 12:03:34 -07:00
38801b52a7 fix
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-04-11 11:23:34 -07:00
e73f39cfa9 reviewers
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-04-11 11:16:11 -07:00
7536ca8683 assignee
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-04-11 11:05:49 -07:00
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
13 changed files with 1241 additions and 722 deletions

View File

@ -67,6 +67,9 @@ jobs:
gh pr create --title "Update lang spec docs for python" \
--body "Updating the generated docs for python" \
--head "$NEW_BRANCH" \
--reviewer jessfraz \
--reviewer irev-dev \
--reviewer franknoirot \
--base main || true
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}

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":
@ -1256,7 +1270,7 @@ def generateAnyOfType(path: str, name: str, schema: dict, data: dict):
f.write("from ." + camel_to_snake(ref_name) + " import " + ref_name + "\n")
all_options.append(ref_name)
if isNestedObjectOneOf(schema):
if isNestedObjectAnyOf(schema):
# We want to write each of the nested objects.
for any_of in schema["anyOf"]:
# Get the nested object.
@ -1312,6 +1326,47 @@ def generateAnyOfType(path: str, name: str, schema: dict, data: dict):
f.write(object_code)
f.write("\n")
all_options.append(object_name)
else:
# We want to write each of the nested objects.
for any_of in schema["anyOf"]:
# Get the nested object.
if "properties" in any_of:
for prop_name in any_of["properties"]:
nested_object = any_of["properties"][prop_name]
if nested_object == {}:
f.write("from typing import Any\n")
f.write(prop_name + " = Any\n")
f.write("\n")
all_options.append(prop_name)
elif "$ref" in nested_object:
ref = nested_object["$ref"]
ref_name = ref[ref.rfind("/") + 1 :]
f.write(
"from ."
+ camel_to_snake(ref_name)
+ " import "
+ ref_name
+ "\n"
)
f.write("\n")
if prop_name != ref_name:
f.write(prop_name + " = " + ref_name + "\n")
f.write("\n")
all_options.append(prop_name)
else:
object_code = generateObjectTypeCode(
prop_name, nested_object, "object", data, None, None
)
f.write(object_code)
f.write("\n")
all_options.append(prop_name)
elif "type" in any_of and any_of["type"] == "string":
enum_code = generateEnumTypeCode(
any_of["enum"][0], any_of, "string", []
)
f.write(enum_code)
f.write("\n")
all_options.append(any_of["enum"][0])
# Write the sum type.
description = getAnyOfDescription(schema)
@ -1728,8 +1783,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 (
@ -1934,6 +1994,40 @@ def getOneOfRefType(schema: dict) -> str:
raise Exception("Cannot get oneOf ref type for schema: ", schema)
def isNestedObjectAnyOf(schema: dict) -> bool:
if "anyOf" not in schema:
return False
is_nested_object = False
for any_of in schema["anyOf"]:
# Check if each are an object w 1 property in it.
if (
"type" in any_of
and any_of["type"] == "object"
and "properties" in any_of
and len(any_of["properties"]) == 1
):
for prop_name in any_of["properties"]:
nested_object = any_of["properties"][prop_name]
if "type" in nested_object and nested_object["type"] == "object":
is_nested_object = True
else:
is_nested_object = False
break
elif (
"type" in any_of
and any_of["type"] == "string"
and "enum" in any_of
and len(any_of["enum"]) == 1
):
is_nested_object = True
else:
is_nested_object = False
break
return is_nested_object
def isNestedObjectOneOf(schema: dict) -> bool:
if "oneOf" not in schema:
return False
@ -1942,7 +2036,8 @@ def isNestedObjectOneOf(schema: dict) -> bool:
for one_of in schema["oneOf"]:
# Check if each are an object w 1 property in it.
if (
one_of["type"] == "object"
"type" in one_of
and one_of["type"] == "object"
and "properties" in one_of
and len(one_of["properties"]) == 1
):
@ -1954,7 +2049,10 @@ def isNestedObjectOneOf(schema: dict) -> bool:
is_nested_object = False
break
elif (
one_of["type"] == "string" and "enum" in one_of and len(one_of["enum"]) == 1
"type" in one_of
and one_of["type"] == "string"
and "enum" in one_of
and len(one_of["enum"]) == 1
):
is_nested_object = True
else:

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

@ -31,6 +31,7 @@ from .async_api_call_type import AsyncApiCallType
from .auth_callback import AuthCallback
from .axis import Axis
from .axis_direction_pair import AxisDirectionPair
from .batch_response import BatchResponse
from .billing_info import BillingInfo
from .block_reason import BlockReason
from .cache_metadata import CacheMetadata

View File

@ -0,0 +1,24 @@
from typing import Union
from pydantic import BaseModel, ConfigDict, RootModel
class response(BaseModel):
"""Response to the modeling command."""
model_config = ConfigDict(protected_namespaces=())
class errors(BaseModel):
"""Errors that occurred during the modeling command."""
model_config = ConfigDict(protected_namespaces=())
BatchResponse = RootModel[
Union[
response,
errors,
]
]

View File

@ -1,8 +1,9 @@
from typing import List, Literal, Union
from typing import Dict, List, Literal, Union
from pydantic import BaseModel, ConfigDict, Field, RootModel
from typing_extensions import Annotated
from ..models.batch_response import BatchResponse
from ..models.ice_server import IceServer
from ..models.ok_modeling_cmd_response import OkModelingCmdResponse
from ..models.raw_file import RawFile
@ -82,6 +83,24 @@ class modeling(BaseModel):
model_config = ConfigDict(protected_namespaces=())
class ModelingBatchData(BaseModel):
""""""
responses: Dict[str, BatchResponse]
model_config = ConfigDict(protected_namespaces=())
class modeling_batch(BaseModel):
"""Response to a ModelingBatch."""
data: ModelingBatchData
type: Literal["modeling_batch"] = "modeling_batch"
model_config = ConfigDict(protected_namespaces=())
class ExportData(BaseModel):
""""""
@ -139,6 +158,7 @@ OkWebSocketResponseData = RootModel[
trickle_ice,
sdp_answer,
modeling,
modeling_batch,
export,
metrics_request,
pong,

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "kittycad"
version = "0.6.9"
version = "0.6.12"
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"

201
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": [
@ -14125,6 +14257,44 @@
"direction"
]
},
"BatchResponse": {
"description": "Websocket responses can either be successful or unsuccessful. Slightly different schemas in either case.",
"anyOf": [
{
"description": "Response sent when a request succeeded.",
"type": "object",
"properties": {
"response": {
"description": "Response to the modeling command.",
"allOf": [
{
"$ref": "#/components/schemas/OkModelingCmdResponse"
}
]
}
},
"required": [
"response"
]
},
{
"description": "Response sent when a request did not succeed.",
"type": "object",
"properties": {
"errors": {
"description": "Errors that occurred during the modeling command.",
"type": "array",
"items": {
"$ref": "#/components/schemas/ApiError"
}
}
},
"required": [
"errors"
]
}
]
},
"BillingInfo": {
"description": "The billing information for payments.",
"type": "object",
@ -22335,6 +22505,37 @@
"type"
]
},
{
"description": "Response to a ModelingBatch.",
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"responses": {
"description": "For each request in the batch, maps its ID to the request's outcome.",
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/BatchResponse"
}
}
},
"required": [
"responses"
]
},
"type": {
"type": "string",
"enum": [
"modeling_batch"
]
}
},
"required": [
"data",
"type"
]
},
{
"description": "The exported files.",
"type": "object",