Skip to content

Commit

Permalink
Refactor SDK and OpenAPI specs
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlycoconuts committed Mar 11, 2022
1 parent d6cde02 commit ec080a3
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 19 deletions.
9 changes: 6 additions & 3 deletions api/api/openapi.bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/IdObject'
$ref: '#/components/schemas/JobId'
description: Accepted.
"400":
description: Invalid ensembling job
Expand Down Expand Up @@ -551,7 +551,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/IdObject_1'
$ref: '#/components/schemas/RouterId'
description: OK
"400":
description: Invalid project_id or router_id
Expand Down Expand Up @@ -1692,13 +1692,16 @@ components:
- failed_submission
- failed_building
type: string
JobId:
$ref: '#/components/schemas/IdObject'
IdObject:
example:
id: 0
properties:
id:
format: int32
type: integer
type: object
Id:
format: int32
type: integer
Expand Down Expand Up @@ -2518,7 +2521,7 @@ components:
- environment_name
- name
type: object
IdObject_1:
RouterId:
$ref: '#/components/schemas/IdObject'
RouterIdAndVersion:
example:
Expand Down
1 change: 1 addition & 0 deletions api/api/specs/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ components:
format: "int32"

IdObject:
type: "object"
properties:
id:
$ref: "#/components/schemas/Id"
Expand Down
4 changes: 2 additions & 2 deletions api/api/specs/jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/IdObject"
$ref: "#/components/schemas/JobId"
400:
description: "Invalid ensembling job"
404:
description: "Ensembling job not found"

components:
schemas:
IdObject:
JobId:
$ref: "common.yaml#/components/schemas/IdObject"
EnsemblingJob:
description: A JSON object that represents an ensembling job for batch experiment use cases
Expand Down
6 changes: 3 additions & 3 deletions api/api/specs/routers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/IdObject"
$ref: "#/components/schemas/RouterId"
400:
description: "Invalid project_id or router_id"
404:
Expand Down Expand Up @@ -388,8 +388,8 @@ paths:

components:
schemas:
IdObject:
$ref: "common.yaml#/components/schemas/IdObject"
RouterId:
$ref: "./common.yaml#/components/schemas/IdObject"

RouterIdObject:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)


class IdObject1(ModelSimple):
class JobId(ModelSimple):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Expand Down Expand Up @@ -91,7 +91,7 @@ def discriminator():

@convert_js_args_to_python_args
def __init__(self, *args, **kwargs):
"""IdObject1 - a model defined in OpenAPI
"""JobId - a model defined in OpenAPI
Note that value can be passed either in args or in kwargs, but not in both.
Expand Down
179 changes: 179 additions & 0 deletions sdk/turing/generated/model/router_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
"""
Turing Minimal Openapi Spec for SDK
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501
The version of the OpenAPI document: 0.0.1
Generated by: https://openapi-generator.tech
"""


import re # noqa: F401
import sys # noqa: F401

from turing.generated.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
ModelNormal,
ModelSimple,
cached_property,
change_keys_js_to_python,
convert_js_args_to_python_args,
date,
datetime,
file_type,
none_type,
validate_get_composed_info,
)


class RouterId(ModelSimple):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
Attributes:
allowed_values (dict): The key is the tuple path to the attribute
and the for var_name this is (var_name,). The value is a dict
with a capitalized key describing the allowed value and an allowed
value. These dicts store the allowed enum values.
validations (dict): The key is the tuple path to the attribute
and the for var_name this is (var_name,). The value is a dict
that stores validations for max_length, min_length, max_items,
min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum,
inclusive_minimum, and regex.
additional_properties_type (tuple): A tuple of classes accepted
as additional properties values.
"""

allowed_values = {
}

validations = {
}

additional_properties_type = None

_nullable = False

@cached_property
def openapi_types():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
Returns
openapi_types (dict): The key is attribute name
and the value is attribute type.
"""
return {
'value': (IdObject,),
}

@cached_property
def discriminator():
return None


attribute_map = {}

_composed_schemas = None

required_properties = set([
'_data_store',
'_check_type',
'_spec_property_naming',
'_path_to_item',
'_configuration',
'_visited_composed_classes',
])

@convert_js_args_to_python_args
def __init__(self, *args, **kwargs):
"""RouterId - a model defined in OpenAPI
Note that value can be passed either in args or in kwargs, but not in both.
Args:
args[0] (IdObject): # noqa: E501
Keyword Args:
value (IdObject): # noqa: E501
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
raised if the wrong type is input.
Defaults to True
_path_to_item (tuple/list): This is a list of keys or values to
drill down to the model in received_data
when deserializing a response
_spec_property_naming (bool): True if the variable names in the input data
are serialized names, as specified in the OpenAPI document.
False if the variable names in the input data
are pythonic names, e.g. snake case (default)
_configuration (Configuration): the instance to use when
deserializing a file_type parameter.
If passed, type conversion is attempted
If omitted no type conversion is done.
_visited_composed_classes (tuple): This stores a tuple of
classes that we have traveled through so that
if we see that class again we will not use its
discriminator again.
When traveling through a discriminator, the
composed schema that is
is traveled through is added to this set.
For example if Animal has a discriminator
petType and we pass in "Dog", and the class Dog
allOf includes Animal, we move through Animal
once using the discriminator, and pick Dog.
Then in Dog, we will make an instance of the
Animal class but this time we won't travel
through its discriminator because we passed in
_visited_composed_classes = (Animal,)
"""
# required up here when default value is not given
_path_to_item = kwargs.pop('_path_to_item', ())

if 'value' in kwargs:
value = kwargs.pop('value')
elif args:
args = list(args)
value = args.pop(0)
else:
raise ApiTypeError(
"value is required, but not passed in args or kwargs and doesn't have default",
path_to_item=_path_to_item,
valid_classes=(self.__class__,),
)

_check_type = kwargs.pop('_check_type', True)
_spec_property_naming = kwargs.pop('_spec_property_naming', False)
_configuration = kwargs.pop('_configuration', None)
_visited_composed_classes = kwargs.pop('_visited_composed_classes', ())

if args:
raise ApiTypeError(
"Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % (
args,
self.__class__.__name__,
),
path_to_item=_path_to_item,
valid_classes=(self.__class__,),
)

self._data_store = {}
self._check_type = _check_type
self._spec_property_naming = _spec_property_naming
self._path_to_item = _path_to_item
self._configuration = _configuration
self._visited_composed_classes = _visited_composed_classes + (self.__class__,)
self.value = value
if kwargs:
raise ApiTypeError(
"Invalid named arguments=%s passed to %s. Remove those invalid named arguments." % (
kwargs,
self.__class__.__name__,
),
path_to_item=_path_to_item,
valid_classes=(self.__class__,),
)
3 changes: 2 additions & 1 deletion sdk/turing/generated/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from turing.generated.model.generic_ensembler import GenericEnsembler
from turing.generated.model.generic_sink import GenericSink
from turing.generated.model.id_object import IdObject
from turing.generated.model.id_object1 import IdObject1
from turing.generated.model.job_id import JobId
from turing.generated.model.kafka_config import KafkaConfig
from turing.generated.model.label import Label
from turing.generated.model.log_level import LogLevel
Expand All @@ -71,6 +71,7 @@
from turing.generated.model.router_details_all_of import RouterDetailsAllOf
from turing.generated.model.router_ensembler_config import RouterEnsemblerConfig
from turing.generated.model.router_events import RouterEvents
from turing.generated.model.router_id import RouterId
from turing.generated.model.router_id_and_version import RouterIdAndVersion
from turing.generated.model.router_id_object import RouterIdObject
from turing.generated.model.router_status import RouterStatus
Expand Down
16 changes: 8 additions & 8 deletions sdk/turing/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from turing.generated import ApiClient, Configuration
from turing.generated.apis import EnsemblerApi, EnsemblingJobApi, ProjectApi, RouterApi
from turing.generated.models import (Project, Ensembler, EnsemblingJob, EnsemblerJobStatus, EnsemblersPaginatedResults,
EnsemblingJobPaginatedResults, IdObject, Router, RouterDetails, RouterConfig,
RouterVersion)
EnsemblingJobPaginatedResults, JobId, RouterId, RouterIdObject, RouterIdAndVersion,
Router, RouterDetails, RouterConfig, RouterVersion)


def require_active_project(f):
Expand Down Expand Up @@ -181,7 +181,7 @@ def get_ensembling_job(self, job_id: int) -> EnsemblingJob:
)

@require_active_project
def terminate_ensembling_job(self, job_id: int) -> IdObject:
def terminate_ensembling_job(self, job_id: int) -> JobId:
return EnsemblingJobApi(self._api_client).terminate_ensembling_job(
project_id=self.active_project.id,
job_id=job_id
Expand Down Expand Up @@ -215,7 +215,7 @@ def create_router(self, router_config: RouterConfig) -> RouterDetails:
router_config=router_config)

@require_active_project
def delete_router(self, router_id: int) -> IdObject:
def delete_router(self, router_id: int) -> RouterId:
"""
Delete router given its router ID
"""
Expand Down Expand Up @@ -244,7 +244,7 @@ def update_router(self, router_id: int, router_config: RouterConfig) -> Router:
router_config=router_config)

@require_active_project
def deploy_router(self, router_id: int) -> IdObject:
def deploy_router(self, router_id: int) -> RouterIdAndVersion:
"""
Deploy router given its router ID
"""
Expand All @@ -254,7 +254,7 @@ def deploy_router(self, router_id: int) -> IdObject:
)

@require_active_project
def undeploy_router(self, router_id: int) -> IdObject:
def undeploy_router(self, router_id: int) -> RouterIdObject:
"""
Undeploy router given its router ID
"""
Expand Down Expand Up @@ -285,7 +285,7 @@ def get_router_version(self, router_id: int, version: int) -> RouterVersion:
)

@require_active_project
def delete_router_version(self, router_id: int, version: int) -> IdObject:
def delete_router_version(self, router_id: int, version: int) -> RouterIdAndVersion:
"""
Delete specific router version given its router ID and version
"""
Expand All @@ -296,7 +296,7 @@ def delete_router_version(self, router_id: int, version: int) -> IdObject:
)

@require_active_project
def deploy_router_version(self, router_id: int, version: int) -> IdObject:
def deploy_router_version(self, router_id: int, version: int) -> RouterIdAndVersion:
"""
Deploy specific router version by its router ID and version
"""
Expand Down

0 comments on commit ec080a3

Please sign in to comment.