add websockets lib, bump version (#116)

* add websockets lib, bump version

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

* use template

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

* 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>
This commit is contained in:
Jess Frazelle
2023-07-31 18:05:13 -07:00
committed by GitHub
parent 20b2a188dc
commit 1a978b79f0
77 changed files with 871 additions and 678 deletions

View File

@ -0,0 +1,113 @@
from typing import Any, Dict, Optional, Union, List
from websockets.sync.client import connect as ws_connect
from websockets.client import connect as ws_connect_async
from websockets.sync.client import ClientConnection
from websockets.client import WebSocketClientProtocol
from ...client import Client
from ...models.error import Error
from ...types import Response
{% for import in imports %}
{{import}}
{% endfor %}
def _get_kwargs(
{% for arg in args %}
{% if arg.is_optional == False %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
*,
client: Client,
{% for arg in args %}
{% if arg.is_optional %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
) -> Dict[str, Any]:
url = "{{url_template}}".format(client.base_url{% for arg in args %}{% if arg.in_url %}, {{arg.name}}={{arg.name}}{% endif %}{% endfor %}) # noqa: E501
{% for arg in args %}
{% if arg.in_query %}
if {{arg.name}} is not None:
if "?" in url:
url = url + "&{{arg.name}}=" + str({{arg.name}})
else:
url = url + "?{{arg.name}}=" + str({{arg.name}})
{% endif %}
{% endfor %}
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(),
{% if has_request_body %}"content": body,{% endif %}
}
def sync(
{% for arg in args %}
{% if arg.is_optional == False %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
*,
client: Client,
{% for arg in args %}
{% if arg.is_optional %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
) -> ClientConnection:
{%if docs%}"""{{docs}}""" # noqa: E501{% endif %}
kwargs = _get_kwargs(
{% for arg in args %}
{{arg.name}}={{arg.name}},
{% endfor %}
client=client,
)
with ws_connect(kwargs["url"].replace("https://", "wss://"), additional_headers=kwargs["headers"]) as websocket:
return websocket # type: ignore
# Return an error if we got here.
return Error(message="An error occurred while connecting to the websocket.")
async def asyncio(
{% for arg in args %}
{% if arg.is_optional == False %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
*,
client: Client,
{% for arg in args %}
{% if arg.is_optional %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
) -> WebSocketClientProtocol:
{%if docs%}"""{{docs}}""" # noqa: E501{% endif %}
kwargs = _get_kwargs(
{% for arg in args %}
{{arg.name}}={{arg.name}},
{% endfor %}
client=client,
)
async with ws_connect_async(kwargs["url"].replace("https://", "wss://"), extra_headers=kwargs["headers"]) as websocket:
return websocket
# Return an error if we got here.
return Error(message="An error occurred while connecting to the websocket.")

View File

@ -0,0 +1,169 @@
from typing import Any, Dict, Optional, Union, List
import httpx
from ...client import Client
from ...models.error import Error
from ...types import Response
{% for import in imports %}
{{import}}
{% endfor %}
def _get_kwargs(
{% for arg in args %}
{% if arg.is_optional == False %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
*,
client: Client,
{% for arg in args %}
{% if arg.is_optional %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
) -> Dict[str, Any]:
url = "{{url_template}}".format(client.base_url, {% for arg in args %}{% if arg.in_url %}{{arg.name}}={{arg.name}},{% endif %}{% endfor %}) # noqa: E501
{% for arg in args %}
{% if arg.in_query %}
if {{arg.name}} is not None:
if "?" in url:
url = url + "&{{arg.name}}=" + str({{arg.name}})
else:
url = url + "?{{arg.name}}=" + str({{arg.name}})
{% endif %}
{% endfor %}
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(),
{% if has_request_body %}"content": body,{% endif %}
}
def _parse_response(*, response: httpx.Response){% if response_type != "" %} -> {{response_type}} {% endif %}:
{{parse_response}}
def _build_response(
*, response: httpx.Response
) -> Response[{% if response_type != "" %}{{response_type}}{% else %}Any{% endif %}]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)
def sync_detailed(
{% for arg in args %}
{% if arg.is_optional == False %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
*,
client: Client,
{% for arg in args %}
{% if arg.is_optional %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
) -> Response[{% if response_type != "" %}{{response_type}}{% else %}Any{% endif %}]:
kwargs = _get_kwargs(
{% for arg in args %}
{{arg.name}}={{arg.name}},
{% endfor %}
client=client,
)
response = httpx.{{method}}(
verify=client.verify_ssl,
**kwargs,
)
return _build_response(response=response)
def sync(
{% for arg in args %}
{% if arg.is_optional == False %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
*,
client: Client,
{% for arg in args %}
{% if arg.is_optional %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
) {% if response_type != "" %} -> {{response_type}} {% endif %}:
{%if docs%}"""{{docs}}""" # noqa: E501{% endif %}
return sync_detailed(
{% for arg in args %}
{{arg.name}}={{arg.name}},
{% endfor %}
client=client,
).parsed
async def asyncio_detailed(
{% for arg in args %}
{% if arg.is_optional == False %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
*,
client: Client,
{% for arg in args %}
{% if arg.is_optional %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
) -> Response[{% if response_type != "" %}{{response_type}}{% else %}Any{% endif %}]:
kwargs = _get_kwargs(
{% for arg in args %}
{{arg.name}}={{arg.name}},
{% endfor %}
client=client,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.{{method}}(**kwargs)
return _build_response(response=response)
async def asyncio(
{% for arg in args %}
{% if arg.is_optional == False %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
*,
client: Client,
{% for arg in args %}
{% if arg.is_optional %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endfor %}
) {% if response_type != "" %} -> {{response_type}} {% endif %}:
{%if docs%}"""{{docs}}""" # noqa: E501{% endif %}
return (
await asyncio_detailed(
{% for arg in args %}
{{arg.name}}={{arg.name}},
{% endfor %}
client=client,
)
).parsed

View File

@ -5,10 +5,11 @@ import logging
import os
import random
import re
from typing import Any, Dict, List, Optional, Tuple
from typing import Any, Dict, List, Optional, Tuple, TypedDict
import black
import isort
import jinja2
import jsonpatch
from prance import BaseParser
@ -344,10 +345,7 @@ def generatePath(path: str, name: str, method: str, endpoint: dict, data: dict)
tag_name = endpoint["tags"][0].replace("-", "_")
path = os.path.join(path, tag_name)
file_path = os.path.join(path, file_name)
logging.info("generating type: ", name, " at: ", file_path)
f = open(file_path, "w")
f.write("from typing import List\n\n")
logging.info("generating path functions: ", name, " at: ", file_path)
endpoint_refs = getEndpointRefs(endpoint, data)
parameter_refs = getParameterRefs(endpoint)
@ -503,16 +501,8 @@ from kittycad.types import Response
"""
)
# This longer example we use for generating tests.
# We only show the short example in the docs since it is much more intuitive to MEs
example = (
example_imports
+ """
@pytest.mark.skip
"""
+ short_sync_example
+ """
long_example = (
"""
# OR if you need more info (e.g. status_code)
"""
@ -549,6 +539,72 @@ async def test_"""
+ """)"""
)
# Generate the websocket examples.
if "x-dropshot-websocket" in endpoint:
short_sync_example = (
"""def test_"""
+ fn_name
+ """():
# Create our client.
client = ClientFromEnv()
# Connect to the websocket.
websocket = """
+ fn_name
+ """.sync(client=client,"""
+ params_str
+ """)
# Send a message.
websocket.send("{}")
# Get the messages.
for message in websocket:
print(message)
"""
)
long_example = (
"""
# OR run async
@pytest.mark.asyncio
@pytest.mark.skip
async def test_"""
+ fn_name
+ """_async():
# Create our client.
client = ClientFromEnv()
# Connect to the websocket.
websocket = await """
+ fn_name
+ """.asyncio(client=client,"""
+ params_str
+ """)
# Send a message.
await websocket.send("{}")
# Get the messages.
async for message in websocket:
print(message)
"""
)
# This longer example we use for generating tests.
# We only show the short example in the docs since it is much more intuitive to MEs
example = (
example_imports
+ """
@pytest.mark.skip
"""
+ short_sync_example
+ long_example
)
# Make pretty.
line_length = 82
short_sync_example = example_imports + short_sync_example
@ -571,156 +627,78 @@ async def test_"""
+ ".html",
}
# Add our imports.
f.write("from typing import Any, Dict, Optional, Union, cast\n")
f.write("\n")
f.write("import httpx\n")
f.write("\n")
f.write("from ...client import Client\n")
# Start defining the template info.
ArgType = TypedDict(
"ArgType",
{
"name": str,
"type": str,
"in_url": bool,
"in_query": bool,
"is_optional": bool,
},
)
TemplateType = TypedDict(
"TemplateType",
{
"imports": List[str],
"response_type": str,
"args": List[ArgType],
"url_template": str,
"method": str,
"docs": str,
"parse_response": str,
"has_request_body": bool,
},
)
template_info: TemplateType = {
"imports": [],
"response_type": response_type,
"args": [],
"url_template": "{}" + name,
"method": method,
"docs": "",
"parse_response": "",
"has_request_body": False,
}
if len(endpoint_refs) == 0:
template_info["response_type"] = ""
if "description" in endpoint:
template_info["docs"] = endpoint["description"]
# Import our references for responses.
for ref in endpoint_refs:
if ref.startswith("List[") and ref.endswith("]"):
ref = ref.replace("List[", "").replace("]", "")
if ref != "str" and ref != "dict":
f.write("from ...models." + camel_to_snake(ref) + " import " + ref + "\n")
template_info["imports"].append(
"from ...models." + camel_to_snake(ref) + " import " + ref
)
for ref in parameter_refs:
f.write("from ...models." + camel_to_snake(ref) + " import " + ref + "\n")
template_info["imports"].append(
"from ...models." + camel_to_snake(ref) + " import " + ref
)
for ref in request_body_refs:
f.write("from ...models." + camel_to_snake(ref) + " import " + ref + "\n")
f.write("from ...types import Response\n")
f.write("\n")
# Define the method.
f.write("def _get_kwargs(\n")
# Iterate over the parameters.
optional_args = []
if "parameters" in endpoint:
parameters = endpoint["parameters"]
for parameter in parameters:
parameter_name = parameter["name"]
if "type" in parameter["schema"]:
parameter_type = (
parameter["schema"]["type"]
.replace("string", "str")
.replace("integer", "int")
.replace("number", "float")
template_info["imports"].append(
"from ...models." + camel_to_snake(ref) + " import " + ref
)
elif "$ref" in parameter["schema"]:
parameter_type = parameter["schema"]["$ref"].replace(
"#/components/schemas/", ""
)
else:
logging.error("parameter: ", parameter)
raise Exception("Unknown parameter type")
if "nullable" in parameter["schema"]:
if parameter["schema"]["nullable"]:
parameter_type = "Optional[" + parameter_type + "] = None"
optional_args.append(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
)
else:
f.write(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
)
else:
f.write(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
)
if request_body_type:
f.write("\tbody: " + request_body_type + ",\n")
f.write("\t*,\n")
f.write("\tclient: Client,\n")
for optional_arg in optional_args:
f.write(optional_arg)
f.write(") -> Dict[str, Any]:\n")
templateUrl = "{}" + name
formatTemplate = ".format(client.base_url"
query_params: List[str] = []
# Iterate over the parameters.
if "parameters" in endpoint:
parameters = endpoint["parameters"]
for parameter in parameters:
parameter_name = parameter["name"]
if "type" in parameter["schema"]:
parameter_type = parameter["schema"]["type"].replace("string", "str")
elif "$ref" in parameter["schema"]:
parameter_type = parameter["schema"]["$ref"].replace(
"#/components/schemas/", ""
)
else:
logging.error("parameter: ", parameter)
raise Exception("Unknown parameter type")
if parameter["in"] == "path":
formatTemplate = (
formatTemplate
+ ", "
+ clean_parameter_name(parameter_name)
+ "="
+ camel_to_snake(parameter_name)
)
elif parameter["in"] == "query":
query_params.append(parameter_name)
f.write('\turl = "' + templateUrl + '"' + formatTemplate + ") # noqa: E501\n")
for query_param in query_params:
f.write("\tif " + query_param + " is not None:\n")
f.write("\t\tif '?' in url:\n")
f.write("\t\t\turl = url + '&" + query_param + "='+str(" + query_param + ")\n")
f.write("\t\telse:\n")
f.write("\t\t\turl = url + '?" + query_param + "='+str(" + query_param + ")\n")
f.write("\n")
f.write("\theaders: Dict[str, Any] = client.get_headers()\n")
f.write("\tcookies: Dict[str, Any] = client.get_cookies()\n")
f.write("\n")
f.write("\treturn {\n")
f.write('\t\t"url": url,\n')
f.write('\t\t"headers": headers,\n')
f.write('\t\t"cookies": cookies,\n')
f.write('\t\t"timeout": client.get_timeout(),\n')
if request_body_type:
f.write('\t\t"content": body,\n')
f.write("\t}\n")
# Define the parse reponse.
f.write("\n")
f.write("\n")
if len(endpoint_refs) > 0:
f.write(
"def _parse_response(*, response: httpx.Response) -> "
+ response_type
+ ":\n"
)
else:
f.write("def _parse_response(*, response: httpx.Response):\n")
# Iterate over the responses.
parse_response = io.StringIO()
if len(endpoint_refs) > 0:
responses = endpoint["responses"]
for response_code in responses:
response = responses[response_code]
if response_code == "default":
# This is no content.
f.write("\treturn None\n")
parse_response.write("\treturn None\n")
elif response_code == "204" or response_code == "302":
# This is no content.
f.write("\treturn None\n")
parse_response.write("\treturn None\n")
else:
f.write(
parse_response.write(
"\tif response.status_code == "
+ response_code.replace("XX", "00")
+ ":\n"
@ -734,41 +712,45 @@ async def test_"""
if "$ref" in json:
ref = json["$ref"].replace("#/components/schemas/", "")
schema = data["components"]["schemas"][ref]
# Let's check if it is a oneOf.
# Let's check if it is a oneOparse_response.
if "oneOf" in schema:
is_one_of = True
# We want to parse each of the possible types.
f.write("\t\tdata = response.json()\n")
parse_response.write("\t\tdata = response.json()\n")
for index, one_of in enumerate(schema["oneOf"]):
ref = getOneOfRefType(one_of)
f.write("\t\ttry:\n")
f.write(
parse_response.write("\t\ttry:\n")
parse_response.write(
"\t\t\tif not isinstance(data, dict):\n"
)
f.write("\t\t\t\traise TypeError()\n")
parse_response.write(
"\t\t\t\traise TypeError()\n"
)
option_name = "option_" + camel_to_snake(ref)
f.write(
parse_response.write(
"\t\t\t"
+ option_name
+ " = "
+ ref
+ ".from_dict(data)\n"
)
f.write("\t\t\treturn " + option_name + "\n")
f.write("\t\texcept ValueError:\n")
parse_response.write(
"\t\t\treturn " + option_name + "\n"
)
parse_response.write("\t\texcept ValueError:\n")
if index == len(schema["oneOf"]) - 1:
# On the last one raise the error.
f.write("\t\t\traise\n")
parse_response.write("\t\t\traise\n")
else:
f.write("\t\t\tpass\n")
f.write("\t\texcept TypeError:\n")
parse_response.write("\t\t\tpass\n")
parse_response.write("\t\texcept TypeError:\n")
if index == len(schema["oneOf"]) - 1:
# On the last one raise the error.
f.write("\t\t\traise\n")
parse_response.write("\t\t\traise\n")
else:
f.write("\t\t\tpass\n")
parse_response.write("\t\t\tpass\n")
else:
f.write(
parse_response.write(
"\t\tresponse_"
+ response_code
+ " = "
@ -782,16 +764,20 @@ async def test_"""
ref = items["$ref"].replace(
"#/components/schemas/", ""
)
f.write(
parse_response.write(
"\t\tresponse_" + response_code + " = [\n"
)
f.write("\t\t\t" + ref + ".from_dict(item)\n")
f.write("\t\t\tfor item in response.json()\n")
f.write("\t\t]\n")
parse_response.write(
"\t\t\t" + ref + ".from_dict(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")
elif json["type"] == "string":
f.write(
parse_response.write(
"\t\tresponse_"
+ response_code
+ " = response.text\n"
@ -799,7 +785,7 @@ async def test_"""
else:
raise Exception("Unknown type", json["type"])
else:
f.write(
parse_response.write(
"\t\tresponse_"
+ response_code
+ " = response.json()\n"
@ -819,7 +805,7 @@ async def test_"""
ref = json["$ref"].replace(
"#/components/schemas/", ""
)
f.write(
parse_response.write(
"\t\tresponse_"
+ response_code
+ " = "
@ -831,38 +817,17 @@ async def test_"""
raise Exception("response not supported")
if not is_one_of:
f.write("\t\treturn response_" + response_code + "\n")
parse_response.write("\t\treturn response_" + response_code + "\n")
# End the method.
f.write("\treturn Error.from_dict(response.json())\n")
parse_response.write("\treturn Error.from_dict(response.json())\n")
else:
f.write("\treturn\n")
parse_response.write("\treturn\n")
# Define the build response method.
f.write("\n")
f.write("\n")
if len(endpoint_refs) > 0:
f.write(
"def _build_response(*, response: httpx.Response) -> "
+ detailed_response_type
+ ":\n"
)
else:
f.write("def _build_response(*, response: httpx.Response) -> Response[Any]:\n")
template_info["parse_response"] = parse_response.getvalue()
f.write("\treturn Response(\n")
f.write("\t\tstatus_code=response.status_code,\n")
f.write("\t\tcontent=response.content,\n")
f.write("\t\theaders=response.headers,\n")
f.write("\t\tparsed=_parse_response(response=response),\n")
f.write("\t)\n")
# Define the sync_detailed method.
f.write("\n")
f.write("\n")
f.write("def sync_detailed(\n")
optional_args = []
# Iterate over the parameters.
optional_args = []
if "parameters" in endpoint:
parameters = endpoint["parameters"]
for parameter in parameters:
@ -884,277 +849,60 @@ async def test_"""
if "nullable" in parameter["schema"]:
if parameter["schema"]["nullable"]:
parameter_type = "Optional[" + parameter_type + "] = None"
optional_args.append(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
template_info["args"].append(
{
"name": camel_to_snake(parameter_name),
"type": parameter_type,
"in_url": "in" in parameter and (parameter["in"] == "path"),
"in_query": "in" in parameter
and (parameter["in"] == "query"),
"is_optional": True,
}
)
else:
f.write(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
template_info["args"].append(
{
"name": camel_to_snake(parameter_name),
"type": parameter_type,
"in_url": "in" in parameter and (parameter["in"] == "path"),
"in_query": "in" in parameter
and (parameter["in"] == "query"),
"is_optional": False,
}
)
else:
f.write(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
template_info["args"].append(
{
"name": camel_to_snake(parameter_name),
"type": parameter_type,
"in_url": "in" in parameter and (parameter["in"] == "path"),
"in_query": "in" in parameter and (parameter["in"] == "query"),
"is_optional": False,
}
)
if request_body_type:
f.write("\tbody: " + request_body_type + ",\n")
f.write("\t*,\n")
f.write("\tclient: Client,\n")
for optional_arg in optional_args:
f.write(optional_arg)
template_info["args"].append(
{
"name": "body",
"type": request_body_type,
"in_url": False,
"in_query": False,
"is_optional": False,
}
)
template_info["has_request_body"] = True
if len(endpoint_refs) > 0:
f.write(") -> " + detailed_response_type + ":\n")
else:
f.write(") -> Response[Any]:\n")
f.write("\tkwargs = _get_kwargs(\n")
params = get_function_parameters(endpoint, request_body_type)
for param in params:
f.write("\t\t" + clean_parameter_name(param) + "=" + param + ",\n")
f.write("\t\tclient=client,\n")
f.write("\t)\n")
f.write("\n")
f.write("\tresponse = httpx." + method + "(\n")
f.write("\t\tverify=client.verify_ssl,\n")
f.write("\t\t**kwargs,\n")
f.write("\t)\n")
f.write("\n")
f.write("\treturn _build_response(response=response)\n")
# Define the sync method.
f.write("\n")
f.write("\n")
f.write("def sync(\n")
optional_args = []
# Iterate over the parameters.
if "parameters" in endpoint:
parameters = endpoint["parameters"]
for parameter in parameters:
parameter_name = parameter["name"]
if "type" in parameter["schema"]:
parameter_type = (
parameter["schema"]["type"]
.replace("string", "str")
.replace("integer", "int")
.replace("number", "float")
)
elif "$ref" in parameter["schema"]:
parameter_type = parameter["schema"]["$ref"].replace(
"#/components/schemas/", ""
)
else:
logging.error("parameter: ", parameter)
raise Exception("Unknown parameter type")
if "nullable" in parameter["schema"]:
if parameter["schema"]["nullable"]:
parameter_type = "Optional[" + parameter_type + "] = None"
optional_args.append(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
)
else:
f.write(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
)
else:
f.write(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
)
if request_body_type:
f.write("\tbody: " + request_body_type + ",\n")
f.write("\t*,\n")
f.write("\tclient: Client,\n")
for optional_arg in optional_args:
f.write(optional_arg)
if len(endpoint_refs) > 0:
f.write(") -> " + response_type + ":\n")
else:
f.write("):\n")
if "description" in endpoint:
f.write('\t""" ' + endpoint["description"] + ' """ # noqa: E501\n')
f.write("\n")
f.write("\treturn sync_detailed(\n")
params = get_function_parameters(endpoint, request_body_type)
for param in params:
f.write("\t\t" + clean_parameter_name(param) + "=" + param + ",\n")
f.write("\t\tclient=client,\n")
f.write("\t).parsed\n")
# Define the asyncio_detailed method.
f.write("\n")
f.write("\n")
f.write("async def asyncio_detailed(\n")
optional_args = []
# Iterate over the parameters.
if "parameters" in endpoint:
parameters = endpoint["parameters"]
for parameter in parameters:
parameter_name = parameter["name"]
if "type" in parameter["schema"]:
parameter_type = (
parameter["schema"]["type"]
.replace("string", "str")
.replace("integer", "int")
.replace("number", "float")
)
elif "$ref" in parameter["schema"]:
parameter_type = parameter["schema"]["$ref"].replace(
"#/components/schemas/", ""
)
else:
logging.error("parameter: ", parameter)
raise Exception("Unknown parameter type")
if "nullable" in parameter["schema"]:
if parameter["schema"]["nullable"]:
parameter_type = "Optional[" + parameter_type + "] = None"
optional_args.append(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
)
else:
f.write(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
)
else:
f.write(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
)
if request_body_type is not None:
f.write("\tbody: " + request_body_type + ",\n")
f.write("\t*,\n")
f.write("\tclient: Client,\n")
for optional_arg in optional_args:
f.write(optional_arg)
if len(endpoint_refs) > 0:
f.write(") -> " + detailed_response_type + ":\n")
else:
f.write(") -> Response[Any]:\n")
f.write("\tkwargs = _get_kwargs(\n")
params = get_function_parameters(endpoint, request_body_type)
for param in params:
f.write("\t\t" + clean_parameter_name(param) + "=" + param + ",\n")
f.write("\t\tclient=client,\n")
f.write("\t)\n")
f.write("\n")
f.write("\tasync with httpx.AsyncClient(verify=client.verify_ssl) as _client:\n")
f.write("\t\tresponse = await _client." + method + "(**kwargs)\n")
f.write("\n")
f.write("\treturn _build_response(response=response)\n")
# Define the asyncio method.
f.write("\n")
f.write("\n")
f.write("async def asyncio(\n")
optional_args = []
# Iterate over the parameters.
if "parameters" in endpoint:
parameters = endpoint["parameters"]
for parameter in parameters:
parameter_name = parameter["name"]
if "type" in parameter["schema"]:
parameter_type = (
parameter["schema"]["type"]
.replace("string", "str")
.replace("integer", "int")
.replace("number", "float")
)
elif "$ref" in parameter["schema"]:
parameter_type = parameter["schema"]["$ref"].replace(
"#/components/schemas/", ""
)
else:
logging.error("parameter: ", parameter)
raise Exception("Unknown parameter type")
if "nullable" in parameter["schema"]:
if parameter["schema"]["nullable"]:
parameter_type = "Optional[" + parameter_type + "] = None"
optional_args.append(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
)
else:
f.write(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
)
else:
f.write(
"\t"
+ camel_to_snake(parameter_name)
+ ": "
+ parameter_type
+ ",\n"
)
if request_body_type:
f.write("\tbody: " + request_body_type + ",\n")
f.write("\t*,\n")
f.write("\tclient: Client,\n")
for optional_arg in optional_args:
f.write(optional_arg)
if len(endpoint_refs) > 0:
f.write(") -> " + response_type + ":\n")
else:
f.write("):\n")
if "description" in endpoint:
f.write('\t""" ' + endpoint["description"] + ' """ # noqa: E501\n')
f.write("\n")
f.write("\treturn (\n")
f.write("\t\tawait asyncio_detailed(\n")
params = get_function_parameters(endpoint, request_body_type)
for param in params:
f.write("\t\t" + clean_parameter_name(param) + "=" + param + ",\n")
f.write("\t\t\tclient=client,\n")
f.write("\t\t)\n")
f.write("\t).parsed\n")
# Close the file.
f.close()
# Generate the template for the functions.
environment = jinja2.Environment(loader=jinja2.FileSystemLoader("generate/"))
template_file = "functions.py.jinja2"
if "x-dropshot-websocket" in endpoint:
template_file = "functions-ws.py.jinja2"
template = environment.get_template(template_file)
content = template.render(**template_info)
with open(file_path, mode="w", encoding="utf-8") as message:
message.write(content)
logging.info(f"... wrote {file_path}")
return data
@ -1444,7 +1192,9 @@ def generateObjectTypeCode(name: str, schema: dict, type_name: str, data: dict)
has_date_time = hasDateTime(schema)
if has_date_time:
f.write("import datetime\n")
f.write("from typing import Any, Dict, List, Type, TypeVar, Union, cast\n")
f.write(
"from typing import Any, Dict, List, Type, TypeVar, Union, cast, deprecated\n"
)
f.write("\n")
f.write("import attr\n")
if has_date_time:
@ -1755,6 +1505,9 @@ def renderTypeToDict(f, property_name: str, property_schema: dict, data: dict):
def renderTypeInit(f, property_name: str, property_schema: dict, data: dict):
property_name = clean_parameter_name(property_name)
# if "deprecated" in property_schema and property_schema["deprecated"]:
# TODO some properties are deprecated, but we still need to support them
# we should show some kind of warning here
if "type" in property_schema:
property_type = property_schema["type"]

File diff suppressed because one or more lines are too long

View File

@ -18,7 +18,9 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/ai/image-to-3d/{input_format}/{output_format}".format(
client.base_url, input_format=input_format, output_format=output_format
client.base_url,
input_format=input_format,
output_format=output_format,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()

View File

@ -16,8 +16,10 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/ai/text-to-3d/{output_format}".format(
client.base_url, output_format=output_format
client.base_url,
output_format=output_format,
) # noqa: E501
if prompt is not None:
if "?" in url:
url = url + "&prompt=" + str(prompt)

View File

@ -13,7 +13,10 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/api-calls/{id}".format(client.base_url, id=id) # noqa: E501
url = "{}/api-calls/{id}".format(
client.base_url,
id=id,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -13,7 +13,10 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/api-calls/{id}".format(client.base_url, id=id) # noqa: E501
url = "{}/user/api-calls/{id}".format(
client.base_url,
id=id,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -14,7 +14,10 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/api-call-metrics".format(client.base_url) # noqa: E501
url = "{}/api-call-metrics".format(
client.base_url,
) # noqa: E501
if group_by is not None:
if "?" in url:
url = url + "&group_by=" + str(group_by)

View File

@ -18,7 +18,10 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/async/operations/{id}".format(client.base_url, id=id) # noqa: E501
url = "{}/async/operations/{id}".format(
client.base_url,
id=id,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -16,17 +16,22 @@ def _get_kwargs(
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Dict[str, Any]:
url = "{}/api-calls".format(client.base_url) # noqa: E501
url = "{}/api-calls".format(
client.base_url,
) # noqa: E501
if limit is not None:
if "?" in url:
url = url + "&limit=" + str(limit)
else:
url = url + "?limit=" + str(limit)
if page_token is not None:
if "?" in url:
url = url + "&page_token=" + str(page_token)
else:
url = url + "?page_token=" + str(page_token)
if sort_by is not None:
if "?" in url:
url = url + "&sort_by=" + str(sort_by)

View File

@ -17,17 +17,23 @@ def _get_kwargs(
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Dict[str, Any]:
url = "{}/users/{id}/api-calls".format(client.base_url, id=id) # noqa: E501
url = "{}/users/{id}/api-calls".format(
client.base_url,
id=id,
) # noqa: E501
if limit is not None:
if "?" in url:
url = url + "&limit=" + str(limit)
else:
url = url + "?limit=" + str(limit)
if page_token is not None:
if "?" in url:
url = url + "&page_token=" + str(page_token)
else:
url = url + "?page_token=" + str(page_token)
if sort_by is not None:
if "?" in url:
url = url + "&sort_by=" + str(sort_by)

View File

@ -18,22 +18,28 @@ def _get_kwargs(
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Dict[str, Any]:
url = "{}/async/operations".format(client.base_url) # noqa: E501
url = "{}/async/operations".format(
client.base_url,
) # noqa: E501
if limit is not None:
if "?" in url:
url = url + "&limit=" + str(limit)
else:
url = url + "?limit=" + str(limit)
if page_token is not None:
if "?" in url:
url = url + "&page_token=" + str(page_token)
else:
url = url + "?page_token=" + str(page_token)
if sort_by is not None:
if "?" in url:
url = url + "&sort_by=" + str(sort_by)
else:
url = url + "?sort_by=" + str(sort_by)
if status is not None:
if "?" in url:
url = url + "&status=" + str(status)

View File

@ -16,17 +16,22 @@ def _get_kwargs(
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Dict[str, Any]:
url = "{}/user/api-calls".format(client.base_url) # noqa: E501
url = "{}/user/api-calls".format(
client.base_url,
) # noqa: E501
if limit is not None:
if "?" in url:
url = url + "&limit=" + str(limit)
else:
url = url + "?limit=" + str(limit)
if page_token is not None:
if "?" in url:
url = url + "&page_token=" + str(page_token)
else:
url = url + "?page_token=" + str(page_token)
if sort_by is not None:
if "?" in url:
url = url + "&sort_by=" + str(sort_by)

View File

@ -12,7 +12,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/api-tokens".format(client.base_url) # noqa: E501
url = "{}/user/api-tokens".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -13,7 +13,8 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/user/api-tokens/{token}".format(
client.base_url, token=token
client.base_url,
token=token,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()

View File

@ -14,7 +14,8 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/user/api-tokens/{token}".format(
client.base_url, token=token
client.base_url,
token=token,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()

View File

@ -16,17 +16,22 @@ def _get_kwargs(
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Dict[str, Any]:
url = "{}/user/api-tokens".format(client.base_url) # noqa: E501
url = "{}/user/api-tokens".format(
client.base_url,
) # noqa: E501
if limit is not None:
if "?" in url:
url = url + "&limit=" + str(limit)
else:
url = url + "?limit=" + str(limit)
if page_token is not None:
if "?" in url:
url = url + "&page_token=" + str(page_token)
else:
url = url + "?page_token=" + str(page_token)
if sort_by is not None:
if "?" in url:
url = url + "&sort_by=" + str(sort_by)

View File

@ -11,7 +11,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/apps/github/callback".format(client.base_url) # noqa: E501
url = "{}/apps/github/callback".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -12,7 +12,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/apps/github/consent".format(client.base_url) # noqa: E501
url = "{}/apps/github/consent".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -12,7 +12,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/apps/github/webhook".format(client.base_url) # noqa: E501
url = "{}/apps/github/webhook".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -15,7 +15,8 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/constant/physics/{constant}".format(
client.base_url, constant=constant
client.base_url,
constant=constant,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()

View File

@ -1,9 +1,10 @@
from typing import Any, Dict
import httpx
from websockets.client import WebSocketClientProtocol, connect as ws_connect_async
from websockets.sync.client import ClientConnection, connect as ws_connect
from ...client import Client
from ...types import Response
from ...models.error import Error
def _get_kwargs(
@ -23,68 +24,40 @@ def _get_kwargs(
}
def _parse_response(*, response: httpx.Response):
return
def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)
def sync_detailed(
*,
client: Client,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
)
response = httpx.get(
verify=client.verify_ssl,
**kwargs,
)
return _build_response(response=response)
def sync(
*,
client: Client,
):
) -> ClientConnection:
"""Attach to a docker container to create an interactive terminal.""" # noqa: E501
return sync_detailed(
client=client,
).parsed
async def asyncio_detailed(
*,
client: Client,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.get(**kwargs)
with ws_connect(
kwargs["url"].replace("https://", "wss://"),
additional_headers=kwargs["headers"],
) as websocket:
return websocket # type: ignore
return _build_response(response=response)
# Return an error if we got here.
return Error(message="An error occurred while connecting to the websocket.")
async def asyncio(
*,
client: Client,
):
) -> WebSocketClientProtocol:
"""Attach to a docker container to create an interactive terminal.""" # noqa: E501
return (
await asyncio_detailed(
kwargs = _get_kwargs(
client=client,
)
).parsed
async with ws_connect_async(
kwargs["url"].replace("https://", "wss://"), extra_headers=kwargs["headers"]
) as websocket:
return websocket
# Return an error if we got here.
return Error(message="An error occurred while connecting to the websocket.")

View File

@ -16,7 +16,11 @@ def _get_kwargs(
client: Client,
output: Optional[str] = None,
) -> Dict[str, Any]:
url = "{}/file/execute/{lang}".format(client.base_url, lang=lang) # noqa: E501
url = "{}/file/execute/{lang}".format(
client.base_url,
lang=lang,
) # noqa: E501
if output is not None:
if "?" in url:
url = url + "&output=" + str(output)

View File

@ -17,12 +17,16 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/file/center-of-mass".format(client.base_url) # noqa: E501
url = "{}/file/center-of-mass".format(
client.base_url,
) # noqa: E501
if output_unit is not None:
if "?" in url:
url = url + "&output_unit=" + str(output_unit)
else:
url = url + "?output_unit=" + str(output_unit)
if src_format is not None:
if "?" in url:
url = url + "&src_format=" + str(src_format)

View File

@ -18,7 +18,9 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/file/conversion/{src_format}/{output_format}".format(
client.base_url, output_format=output_format, src_format=src_format
client.base_url,
output_format=output_format,
src_format=src_format,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()

View File

@ -20,22 +20,28 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/file/density".format(client.base_url) # noqa: E501
url = "{}/file/density".format(
client.base_url,
) # noqa: E501
if material_mass is not None:
if "?" in url:
url = url + "&material_mass=" + str(material_mass)
else:
url = url + "?material_mass=" + str(material_mass)
if material_mass_unit is not None:
if "?" in url:
url = url + "&material_mass_unit=" + str(material_mass_unit)
else:
url = url + "?material_mass_unit=" + str(material_mass_unit)
if output_unit is not None:
if "?" in url:
url = url + "&output_unit=" + str(output_unit)
else:
url = url + "?output_unit=" + str(output_unit)
if src_format is not None:
if "?" in url:
url = url + "&src_format=" + str(src_format)

View File

@ -20,22 +20,28 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/file/mass".format(client.base_url) # noqa: E501
url = "{}/file/mass".format(
client.base_url,
) # noqa: E501
if material_density is not None:
if "?" in url:
url = url + "&material_density=" + str(material_density)
else:
url = url + "?material_density=" + str(material_density)
if material_density_unit is not None:
if "?" in url:
url = url + "&material_density_unit=" + str(material_density_unit)
else:
url = url + "?material_density_unit=" + str(material_density_unit)
if output_unit is not None:
if "?" in url:
url = url + "&output_unit=" + str(output_unit)
else:
url = url + "?output_unit=" + str(output_unit)
if src_format is not None:
if "?" in url:
url = url + "&src_format=" + str(src_format)

View File

@ -17,12 +17,16 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/file/surface-area".format(client.base_url) # noqa: E501
url = "{}/file/surface-area".format(
client.base_url,
) # noqa: E501
if output_unit is not None:
if "?" in url:
url = url + "&output_unit=" + str(output_unit)
else:
url = url + "?output_unit=" + str(output_unit)
if src_format is not None:
if "?" in url:
url = url + "&src_format=" + str(src_format)

View File

@ -17,12 +17,16 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/file/volume".format(client.base_url) # noqa: E501
url = "{}/file/volume".format(
client.base_url,
) # noqa: E501
if output_unit is not None:
if "?" in url:
url = url + "&output_unit=" + str(output_unit)
else:
url = url + "?output_unit=" + str(output_unit)
if src_format is not None:
if "?" in url:
url = url + "&src_format=" + str(src_format)

View File

@ -14,7 +14,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/auth/email".format(client.base_url) # noqa: E501
url = "{}/auth/email".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -14,17 +14,22 @@ def _get_kwargs(
client: Client,
callback_url: Optional[str] = None,
) -> Dict[str, Any]:
url = "{}/auth/email/callback".format(client.base_url) # noqa: E501
url = "{}/auth/email/callback".format(
client.base_url,
) # noqa: E501
if callback_url is not None:
if "?" in url:
url = url + "&callback_url=" + str(callback_url)
else:
url = url + "?callback_url=" + str(callback_url)
if email is not None:
if "?" in url:
url = url + "&email=" + str(email)
else:
url = url + "?email=" + str(email)
if token is not None:
if "?" in url:
url = url + "&token=" + str(token)

View File

@ -11,7 +11,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/logout".format(client.base_url) # noqa: E501
url = "{}/logout".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -12,7 +12,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/.well-known/ai-plugin.json".format(client.base_url) # noqa: E501
url = "{}/.well-known/ai-plugin.json".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -12,7 +12,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/_meta/info".format(client.base_url) # noqa: E501
url = "{}/_meta/info".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -11,7 +11,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/openai/openapi.json".format(client.base_url) # noqa: E501
url = "{}/openai/openapi.json".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -11,7 +11,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/".format(client.base_url) # noqa: E501
url = "{}/".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -12,7 +12,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/ping".format(client.base_url) # noqa: E501
url = "{}/ping".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -13,7 +13,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/modeling/cmd".format(client.base_url) # noqa: E501
url = "{}/modeling/cmd".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -14,7 +14,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/modeling/cmd_batch".format(client.base_url) # noqa: E501
url = "{}/modeling/cmd_batch".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -1,9 +1,10 @@
from typing import Any, Dict
import httpx
from websockets.client import WebSocketClientProtocol, connect as ws_connect_async
from websockets.sync.client import ClientConnection, connect as ws_connect
from ...client import Client
from ...types import Response
from ...models.error import Error
def _get_kwargs(
@ -23,68 +24,40 @@ def _get_kwargs(
}
def _parse_response(*, response: httpx.Response):
return
def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)
def sync_detailed(
*,
client: Client,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
)
response = httpx.get(
verify=client.verify_ssl,
**kwargs,
)
return _build_response(response=response)
def sync(
*,
client: Client,
):
) -> ClientConnection:
"""Pass those commands to the engine via websocket, and pass responses back to the client. Basically, this is a websocket proxy between the frontend/client and the engine.""" # noqa: E501
return sync_detailed(
client=client,
).parsed
async def asyncio_detailed(
*,
client: Client,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.get(**kwargs)
with ws_connect(
kwargs["url"].replace("https://", "wss://"),
additional_headers=kwargs["headers"],
) as websocket:
return websocket # type: ignore
return _build_response(response=response)
# Return an error if we got here.
return Error(message="An error occurred while connecting to the websocket.")
async def asyncio(
*,
client: Client,
):
) -> WebSocketClientProtocol:
"""Pass those commands to the engine via websocket, and pass responses back to the client. Basically, this is a websocket proxy between the frontend/client and the engine.""" # noqa: E501
return (
await asyncio_detailed(
kwargs = _get_kwargs(
client=client,
)
).parsed
async with ws_connect_async(
kwargs["url"].replace("https://", "wss://"), extra_headers=kwargs["headers"]
) as websocket:
return websocket
# Return an error if we got here.
return Error(message="An error occurred while connecting to the websocket.")

View File

@ -14,7 +14,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/payment".format(client.base_url) # noqa: E501
url = "{}/user/payment".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -12,7 +12,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/payment/intent".format(client.base_url) # noqa: E501
url = "{}/user/payment/intent".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -11,7 +11,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/payment".format(client.base_url) # noqa: E501
url = "{}/user/payment".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -12,7 +12,10 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/payment/methods/{id}".format(client.base_url, id=id) # noqa: E501
url = "{}/user/payment/methods/{id}".format(
client.base_url,
id=id,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -12,7 +12,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/payment/balance".format(client.base_url) # noqa: E501
url = "{}/user/payment/balance".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -12,7 +12,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/payment".format(client.base_url) # noqa: E501
url = "{}/user/payment".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -12,7 +12,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/payment/invoices".format(client.base_url) # noqa: E501
url = "{}/user/payment/invoices".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -12,7 +12,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/payment/methods".format(client.base_url) # noqa: E501
url = "{}/user/payment/methods".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -14,7 +14,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/payment".format(client.base_url) # noqa: E501
url = "{}/user/payment".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -11,7 +11,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/payment/tax".format(client.base_url) # noqa: E501
url = "{}/user/payment/tax".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -17,8 +17,11 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/unit/conversion/angle/{input_unit}/{output_unit}".format(
client.base_url, input_unit=input_unit, output_unit=output_unit
client.base_url,
input_unit=input_unit,
output_unit=output_unit,
) # noqa: E501
if value is not None:
if "?" in url:
url = url + "&value=" + str(value)

View File

@ -17,8 +17,11 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/unit/conversion/area/{input_unit}/{output_unit}".format(
client.base_url, input_unit=input_unit, output_unit=output_unit
client.base_url,
input_unit=input_unit,
output_unit=output_unit,
) # noqa: E501
if value is not None:
if "?" in url:
url = url + "&value=" + str(value)

View File

@ -17,8 +17,11 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/unit/conversion/current/{input_unit}/{output_unit}".format(
client.base_url, input_unit=input_unit, output_unit=output_unit
client.base_url,
input_unit=input_unit,
output_unit=output_unit,
) # noqa: E501
if value is not None:
if "?" in url:
url = url + "&value=" + str(value)

View File

@ -17,8 +17,11 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/unit/conversion/energy/{input_unit}/{output_unit}".format(
client.base_url, input_unit=input_unit, output_unit=output_unit
client.base_url,
input_unit=input_unit,
output_unit=output_unit,
) # noqa: E501
if value is not None:
if "?" in url:
url = url + "&value=" + str(value)

View File

@ -17,8 +17,11 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/unit/conversion/force/{input_unit}/{output_unit}".format(
client.base_url, input_unit=input_unit, output_unit=output_unit
client.base_url,
input_unit=input_unit,
output_unit=output_unit,
) # noqa: E501
if value is not None:
if "?" in url:
url = url + "&value=" + str(value)

View File

@ -17,8 +17,11 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/unit/conversion/frequency/{input_unit}/{output_unit}".format(
client.base_url, input_unit=input_unit, output_unit=output_unit
client.base_url,
input_unit=input_unit,
output_unit=output_unit,
) # noqa: E501
if value is not None:
if "?" in url:
url = url + "&value=" + str(value)

View File

@ -17,8 +17,11 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/unit/conversion/length/{input_unit}/{output_unit}".format(
client.base_url, input_unit=input_unit, output_unit=output_unit
client.base_url,
input_unit=input_unit,
output_unit=output_unit,
) # noqa: E501
if value is not None:
if "?" in url:
url = url + "&value=" + str(value)

View File

@ -17,8 +17,11 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/unit/conversion/mass/{input_unit}/{output_unit}".format(
client.base_url, input_unit=input_unit, output_unit=output_unit
client.base_url,
input_unit=input_unit,
output_unit=output_unit,
) # noqa: E501
if value is not None:
if "?" in url:
url = url + "&value=" + str(value)

View File

@ -17,8 +17,11 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/unit/conversion/power/{input_unit}/{output_unit}".format(
client.base_url, input_unit=input_unit, output_unit=output_unit
client.base_url,
input_unit=input_unit,
output_unit=output_unit,
) # noqa: E501
if value is not None:
if "?" in url:
url = url + "&value=" + str(value)

View File

@ -17,8 +17,11 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/unit/conversion/pressure/{input_unit}/{output_unit}".format(
client.base_url, input_unit=input_unit, output_unit=output_unit
client.base_url,
input_unit=input_unit,
output_unit=output_unit,
) # noqa: E501
if value is not None:
if "?" in url:
url = url + "&value=" + str(value)

View File

@ -17,8 +17,11 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/unit/conversion/temperature/{input_unit}/{output_unit}".format(
client.base_url, input_unit=input_unit, output_unit=output_unit
client.base_url,
input_unit=input_unit,
output_unit=output_unit,
) # noqa: E501
if value is not None:
if "?" in url:
url = url + "&value=" + str(value)

View File

@ -17,8 +17,11 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/unit/conversion/torque/{input_unit}/{output_unit}".format(
client.base_url, input_unit=input_unit, output_unit=output_unit
client.base_url,
input_unit=input_unit,
output_unit=output_unit,
) # noqa: E501
if value is not None:
if "?" in url:
url = url + "&value=" + str(value)

View File

@ -17,8 +17,11 @@ def _get_kwargs(
client: Client,
) -> Dict[str, Any]:
url = "{}/unit/conversion/volume/{input_unit}/{output_unit}".format(
client.base_url, input_unit=input_unit, output_unit=output_unit
client.base_url,
input_unit=input_unit,
output_unit=output_unit,
) # noqa: E501
if value is not None:
if "?" in url:
url = url + "&value=" + str(value)

View File

@ -11,7 +11,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user".format(client.base_url) # noqa: E501
url = "{}/user".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -13,7 +13,10 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/session/{token}".format(client.base_url, token=token) # noqa: E501
url = "{}/user/session/{token}".format(
client.base_url,
token=token,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -13,7 +13,10 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/users/{id}".format(client.base_url, id=id) # noqa: E501
url = "{}/users/{id}".format(
client.base_url,
id=id,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -13,7 +13,10 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/users-extended/{id}".format(client.base_url, id=id) # noqa: E501
url = "{}/users-extended/{id}".format(
client.base_url,
id=id,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -11,7 +11,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/front-hash".format(client.base_url) # noqa: E501
url = "{}/user/front-hash".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -12,7 +12,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/onboarding".format(client.base_url) # noqa: E501
url = "{}/user/onboarding".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -12,7 +12,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user".format(client.base_url) # noqa: E501
url = "{}/user".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -12,7 +12,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/extended".format(client.base_url) # noqa: E501
url = "{}/user/extended".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -16,17 +16,22 @@ def _get_kwargs(
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Dict[str, Any]:
url = "{}/users".format(client.base_url) # noqa: E501
url = "{}/users".format(
client.base_url,
) # noqa: E501
if limit is not None:
if "?" in url:
url = url + "&limit=" + str(limit)
else:
url = url + "?limit=" + str(limit)
if page_token is not None:
if "?" in url:
url = url + "&page_token=" + str(page_token)
else:
url = url + "?page_token=" + str(page_token)
if sort_by is not None:
if "?" in url:
url = url + "&sort_by=" + str(sort_by)

View File

@ -16,17 +16,22 @@ def _get_kwargs(
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Dict[str, Any]:
url = "{}/users-extended".format(client.base_url) # noqa: E501
url = "{}/users-extended".format(
client.base_url,
) # noqa: E501
if limit is not None:
if "?" in url:
url = url + "&limit=" + str(limit)
else:
url = url + "?limit=" + str(limit)
if page_token is not None:
if "?" in url:
url = url + "&page_token=" + str(page_token)
else:
url = url + "?page_token=" + str(page_token)
if sort_by is not None:
if "?" in url:
url = url + "&sort_by=" + str(sort_by)

View File

@ -14,7 +14,9 @@ def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user".format(client.base_url) # noqa: E501
url = "{}/user".format(
client.base_url,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

View File

@ -3817,14 +3817,17 @@ def test_create_executor_term():
# Create our client.
client = ClientFromEnv()
create_executor_term.sync(
# Connect to the websocket.
websocket = create_executor_term.sync(
client=client,
)
# OR if you need more info (e.g. status_code)
create_executor_term.sync_detailed(
client=client,
)
# Send a message.
websocket.send("{}")
# Get the messages.
for message in websocket:
print(message)
# OR run async
@ -3834,14 +3837,17 @@ async def test_create_executor_term_async():
# Create our client.
client = ClientFromEnv()
await create_executor_term.asyncio(
# Connect to the websocket.
websocket = await create_executor_term.asyncio(
client=client,
)
# OR run async with more info
await create_executor_term.asyncio_detailed(
client=client,
)
# Send a message.
await websocket.send("{}")
# Get the messages.
async for message in websocket:
print(message)
@pytest.mark.skip
@ -3849,14 +3855,17 @@ def test_modeling_commands_ws():
# Create our client.
client = ClientFromEnv()
modeling_commands_ws.sync(
# Connect to the websocket.
websocket = modeling_commands_ws.sync(
client=client,
)
# OR if you need more info (e.g. status_code)
modeling_commands_ws.sync_detailed(
client=client,
)
# Send a message.
websocket.send("{}")
# Get the messages.
for message in websocket:
print(message)
# OR run async
@ -3866,11 +3875,14 @@ async def test_modeling_commands_ws_async():
# Create our client.
client = ClientFromEnv()
await modeling_commands_ws.asyncio(
# Connect to the websocket.
websocket = await modeling_commands_ws.asyncio(
client=client,
)
# OR run async with more info
await modeling_commands_ws.asyncio_detailed(
client=client,
)
# Send a message.
await websocket.send("{}")
# Get the messages.
async for message in websocket:
print(message)

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "kittycad"
version = "0.4.4"
version = "0.4.5"
description = "A client library for accessing KittyCAD"
authors = []
@ -16,11 +16,13 @@ attrs = ">=20.1.0,<24.0.0"
httpx = ">=0.15.4,<0.25.0"
python = "^3.8"
python-dateutil = "^2.8.0"
websockets = "^11.0.3"
[tool.poetry.dev-dependencies]
autoclasstoc = "^1.6.0"
black = "^23.7.0"
isort = "^5.12.0"
jinja2 = "^3.1.2"
jsonpatch = "^1.32"
mypy = "^1.2.0"
openapi-parser = "^0.2.6"