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>
This commit is contained in:
zoo-github-actions-auth[bot]
2024-04-12 12:03:34 -07:00
committed by GitHub
parent 38801b52a7
commit 64e8aa2816
7 changed files with 895 additions and 702 deletions

View File

@ -1270,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") f.write("from ." + camel_to_snake(ref_name) + " import " + ref_name + "\n")
all_options.append(ref_name) all_options.append(ref_name)
if isNestedObjectOneOf(schema): if isNestedObjectAnyOf(schema):
# We want to write each of the nested objects. # We want to write each of the nested objects.
for any_of in schema["anyOf"]: for any_of in schema["anyOf"]:
# Get the nested object. # Get the nested object.
@ -1326,6 +1326,47 @@ def generateAnyOfType(path: str, name: str, schema: dict, data: dict):
f.write(object_code) f.write(object_code)
f.write("\n") f.write("\n")
all_options.append(object_name) 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. # Write the sum type.
description = getAnyOfDescription(schema) description = getAnyOfDescription(schema)
@ -1953,6 +1994,40 @@ def getOneOfRefType(schema: dict) -> str:
raise Exception("Cannot get oneOf ref type for schema: ", schema) 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: def isNestedObjectOneOf(schema: dict) -> bool:
if "oneOf" not in schema: if "oneOf" not in schema:
return False return False
@ -1961,7 +2036,8 @@ def isNestedObjectOneOf(schema: dict) -> bool:
for one_of in schema["oneOf"]: for one_of in schema["oneOf"]:
# Check if each are an object w 1 property in it. # Check if each are an object w 1 property in it.
if ( if (
one_of["type"] == "object" "type" in one_of
and one_of["type"] == "object"
and "properties" in one_of and "properties" in one_of
and len(one_of["properties"]) == 1 and len(one_of["properties"]) == 1
): ):
@ -1973,7 +2049,10 @@ def isNestedObjectOneOf(schema: dict) -> bool:
is_nested_object = False is_nested_object = False
break break
elif ( 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 is_nested_object = True
else: else:

File diff suppressed because it is too large Load Diff

View File

@ -31,6 +31,7 @@ from .async_api_call_type import AsyncApiCallType
from .auth_callback import AuthCallback from .auth_callback import AuthCallback
from .axis import Axis from .axis import Axis
from .axis_direction_pair import AxisDirectionPair from .axis_direction_pair import AxisDirectionPair
from .batch_response import BatchResponse
from .billing_info import BillingInfo from .billing_info import BillingInfo
from .block_reason import BlockReason from .block_reason import BlockReason
from .cache_metadata import CacheMetadata 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 pydantic import BaseModel, ConfigDict, Field, RootModel
from typing_extensions import Annotated from typing_extensions import Annotated
from ..models.batch_response import BatchResponse
from ..models.ice_server import IceServer from ..models.ice_server import IceServer
from ..models.ok_modeling_cmd_response import OkModelingCmdResponse from ..models.ok_modeling_cmd_response import OkModelingCmdResponse
from ..models.raw_file import RawFile from ..models.raw_file import RawFile
@ -82,6 +83,24 @@ class modeling(BaseModel):
model_config = ConfigDict(protected_namespaces=()) 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): class ExportData(BaseModel):
"""""" """"""
@ -139,6 +158,7 @@ OkWebSocketResponseData = RootModel[
trickle_ice, trickle_ice,
sdp_answer, sdp_answer,
modeling, modeling,
modeling_batch,
export, export,
metrics_request, metrics_request,
pong, pong,

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "kittycad" name = "kittycad"
version = "0.6.11" version = "0.6.12"
description = "A client library for accessing KittyCAD" description = "A client library for accessing KittyCAD"
authors = [] authors = []

View File

@ -14257,6 +14257,44 @@
"direction" "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": { "BillingInfo": {
"description": "The billing information for payments.", "description": "The billing information for payments.",
"type": "object", "type": "object",
@ -22467,6 +22505,37 @@
"type" "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.", "description": "The exported files.",
"type": "object", "type": "object",