Skip to content

Commit

Permalink
update generated client & use for dataset upload (#521)
Browse files Browse the repository at this point in the history
* update generated client & use for dataset upload
* undo enforce auth, ds download works without login
  • Loading branch information
jstriebel authored Dec 13, 2021
1 parent 4aa391e commit 21f3342
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 28 deletions.
11 changes: 11 additions & 0 deletions webknossos/__generate_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ def set_response_schema_by_example(
request_schema["responses"]["200"]["content"] = recorded_response_schema


def fix_request_body(openapi_schema: Dict) -> None:
assert_valid_schema(openapi_schema)
for path_val in openapi_schema["paths"].values():
for method_val in path_val.values():
if "requestBody" in method_val:
method_val["requestBody"]["content"] = {
"application/json": {"schema": {"type": "object"}}
}


def bootstrap_response_schemas(openapi_schema: Dict) -> None:
"""Inserts the response schemas into openapi_schema (in-place),
as recorded by example requests."""
Expand All @@ -188,5 +198,6 @@ def bootstrap_response_schemas(openapi_schema: Dict) -> None:
schema = json.loads(response.text)
add_api_prefix_for_non_data_paths(schema)
generate_client(schema)
fix_request_body(schema)
bootstrap_response_schemas(schema)
generate_client(schema)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def _get_kwargs(
data_layer_name: str,
*,
client: Client,
token: Union[Unset, None, str] = UNSET,
x: int,
y: int,
z: int,
Expand All @@ -32,6 +33,7 @@ def _get_kwargs(
cookies: Dict[str, Any] = client.get_cookies()

params: Dict[str, Any] = {
"token": token,
"x": x,
"y": y,
"z": z,
Expand Down Expand Up @@ -67,6 +69,7 @@ def sync_detailed(
data_layer_name: str,
*,
client: Client,
token: Union[Unset, None, str] = UNSET,
x: int,
y: int,
z: int,
Expand All @@ -81,6 +84,7 @@ def sync_detailed(
data_set_name=data_set_name,
data_layer_name=data_layer_name,
client=client,
token=token,
x=x,
y=y,
z=z,
Expand All @@ -104,6 +108,7 @@ async def asyncio_detailed(
data_layer_name: str,
*,
client: Client,
token: Union[Unset, None, str] = UNSET,
x: int,
y: int,
z: int,
Expand All @@ -118,6 +123,7 @@ async def asyncio_detailed(
data_set_name=data_set_name,
data_layer_name=data_layer_name,
client=client,
token=token,
x=x,
y=y,
z=z,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
from typing import Any, Dict
from typing import Any, Dict, Union

import httpx

from ...client import Client
from ...types import Response
from ...models.dataset_finish_upload_json_body import DatasetFinishUploadJsonBody
from ...types import UNSET, Response, Unset


def _get_kwargs(
*,
client: Client,
json_body: DatasetFinishUploadJsonBody,
token: Union[Unset, None, str] = UNSET,
) -> Dict[str, Any]:
url = "{}/data/datasets/finishUpload".format(client.base_url)

headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

params: Dict[str, Any] = {
"token": token,
}
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

json_json_body = json_body.to_dict()

return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"json": json_json_body,
"params": params,
}


Expand All @@ -35,9 +47,13 @@ def _build_response(*, response: httpx.Response) -> Response[Any]:
def sync_detailed(
*,
client: Client,
json_body: DatasetFinishUploadJsonBody,
token: Union[Unset, None, str] = UNSET,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
json_body=json_body,
token=token,
)

response = httpx.post(
Expand All @@ -50,9 +66,13 @@ def sync_detailed(
async def asyncio_detailed(
*,
client: Client,
json_body: DatasetFinishUploadJsonBody,
token: Union[Unset, None, str] = UNSET,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
json_body=json_body,
token=token,
)

async with httpx.AsyncClient() as _client:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
from typing import Any, Dict
from typing import Any, Dict, Union

import httpx

from ...client import Client
from ...types import Response
from ...models.dataset_reserve_upload_json_body import DatasetReserveUploadJsonBody
from ...types import UNSET, Response, Unset


def _get_kwargs(
*,
client: Client,
json_body: DatasetReserveUploadJsonBody,
token: Union[Unset, None, str] = UNSET,
) -> Dict[str, Any]:
url = "{}/data/datasets/reserveUpload".format(client.base_url)

headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

params: Dict[str, Any] = {
"token": token,
}
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

json_json_body = json_body.to_dict()

return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"json": json_json_body,
"params": params,
}


Expand All @@ -35,9 +47,13 @@ def _build_response(*, response: httpx.Response) -> Response[Any]:
def sync_detailed(
*,
client: Client,
json_body: DatasetReserveUploadJsonBody,
token: Union[Unset, None, str] = UNSET,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
json_body=json_body,
token=token,
)

response = httpx.post(
Expand All @@ -50,9 +66,13 @@ def sync_detailed(
async def asyncio_detailed(
*,
client: Client,
json_body: DatasetReserveUploadJsonBody,
token: Union[Unset, None, str] = UNSET,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
json_body=json_body,
token=token,
)

async with httpx.AsyncClient() as _client:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
from typing import Any, Dict
from typing import Any, Dict, Union

import httpx

from ...client import Client
from ...types import Response
from ...types import UNSET, Response, Unset


def _get_kwargs(
*,
client: Client,
token: Union[Unset, None, str] = UNSET,
) -> Dict[str, Any]:
url = "{}/data/datasets".format(client.base_url)

headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

params: Dict[str, Any] = {
"token": token,
}
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"params": params,
}


Expand All @@ -35,9 +42,11 @@ def _build_response(*, response: httpx.Response) -> Response[Any]:
def sync_detailed(
*,
client: Client,
token: Union[Unset, None, str] = UNSET,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
token=token,
)

response = httpx.post(
Expand All @@ -50,9 +59,11 @@ def sync_detailed(
async def asyncio_detailed(
*,
client: Client,
token: Union[Unset, None, str] = UNSET,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
token=token,
)

async with httpx.AsyncClient() as _client:
Expand Down
2 changes: 2 additions & 0 deletions webknossos/webknossos/client/_generated/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from .current_user_info_response_200_teams_item import (
CurrentUserInfoResponse200TeamsItem,
)
from .dataset_finish_upload_json_body import DatasetFinishUploadJsonBody
from .dataset_info_response_200 import DatasetInfoResponse200
from .dataset_info_response_200_data_source import DatasetInfoResponse200DataSource
from .dataset_info_response_200_data_source_data_layers_item import (
Expand All @@ -53,6 +54,7 @@
)
from .dataset_info_response_200_data_source_id import DatasetInfoResponse200DataSourceId
from .dataset_info_response_200_data_store import DatasetInfoResponse200DataStore
from .dataset_reserve_upload_json_body import DatasetReserveUploadJsonBody
from .datastore_list_response_200_item import DatastoreListResponse200Item
from .generate_token_for_data_store_response_200 import (
GenerateTokenForDataStoreResponse200,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from typing import Any, Dict, List, Type, TypeVar

import attr

T = TypeVar("T", bound="DatasetFinishUploadJsonBody")


@attr.s(auto_attribs=True)
class DatasetFinishUploadJsonBody:
""" """

additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update({})

return field_dict

@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
dataset_finish_upload_json_body = cls()

dataset_finish_upload_json_body.additional_properties = d
return dataset_finish_upload_json_body

@property
def additional_keys(self) -> List[str]:
return list(self.additional_properties.keys())

def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]

def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value

def __delitem__(self, key: str) -> None:
del self.additional_properties[key]

def __contains__(self, key: str) -> bool:
return key in self.additional_properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from typing import Any, Dict, List, Type, TypeVar

import attr

T = TypeVar("T", bound="DatasetReserveUploadJsonBody")


@attr.s(auto_attribs=True)
class DatasetReserveUploadJsonBody:
""" """

additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update({})

return field_dict

@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
dataset_reserve_upload_json_body = cls()

dataset_reserve_upload_json_body.additional_properties = d
return dataset_reserve_upload_json_body

@property
def additional_keys(self) -> List[str]:
return list(self.additional_properties.keys())

def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]

def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value

def __delitem__(self, key: str) -> None:
del self.additional_properties[key]

def __contains__(self, key: str) -> bool:
return key in self.additional_properties
Loading

0 comments on commit 21f3342

Please sign in to comment.