Skip to content

Commit

Permalink
schema progress
Browse files Browse the repository at this point in the history
Signed-off-by: Jason <git@jasoncameron.dev>
  • Loading branch information
JasonLovesDoggo committed Feb 7, 2024
1 parent 6745d8e commit 3907456
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions core/schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dataclasses
from dataclasses import dataclass, Field
from dataclasses import dataclass
from functools import wraps
from typing import (
Optional,
Expand All @@ -10,20 +10,21 @@
Type,
Tuple,
List,
NamedTuple,
)

from drf_spectacular.drainage import set_override
from drf_spectacular.utils import F, OpenApiExample
from rest_framework.serializers import Serializer
from memoization import cached
from rest_framework.serializers import Serializer, BaseSerializer

from logging import getLogger

from core.api.utils.polymorphism import get_provider, get_providers_by_operation
from core.api.utils.polymorphism import (
get_provider,
get_providers_by_operation,
providers,
)
from core.api.v3.objects import BaseProvider
from core.utils.types import APIObjOperations, PathData

logger = getLogger(__name__)
from core.utils.types import APIObjOperations


def metro_extend_schema_serializer( # modified version of drf_spectacular.utils.extend_schema_serializer
Expand Down Expand Up @@ -87,6 +88,7 @@ def wrapped_view(*args, **kwargs):
return decorator


@cached
def run_fixers(result, generator, request, public):
fixer = Api3ObjSpliter(result)
fixer.run()
Expand All @@ -100,6 +102,20 @@ class SingleOperationData:
data: dict


@dataclass
class APISerializerOperations:
operation: APIObjOperations
serializer: BaseSerializer
# tags?


@dataclass
class ProviderDetails:
provider: BaseProvider
operations_supported: List[APISerializerOperations]
data: dict


@dataclass
class ObjectModificationData:
retrieve: Optional[SingleOperationData] = None
Expand Down Expand Up @@ -131,6 +147,7 @@ def __init__(self, schema):
self.operation_data: ObjectModificationData = ObjectModificationData()
self.keys_to_delete: Tuple = ()
self.schema = schema
self._provider_details: Dict[str, ProviderDetails] = dict()

def run(self):
# ObjectModificationData._make
Expand All @@ -153,12 +170,17 @@ def set_obj_paths(self, paths: Dict[str, dict]) -> List[Tuple[str, dict]]:
for path, value in paths.items()
if path.startswith(PATH_PREFIX)
]
self.keys_to_delete = tuple([path for path, _ in _obj_paths])
self.keys_to_delete = tuple(
[path for path, _ in _obj_paths]
) # designates the api3 obj polymorphic paths to be deleted.
for _, value in _obj_paths:
http_method = list(value.keys())[0]
operation_id = value[http_method]["operationId"]
name = self._get_name_from_id(operation_id)
# set values for ObjectModificationData
print(f"Setting {name} for {http_method} with OperationID: {operation_id}")
##self._provider_details[name] = ProviderDetails(

insertable_value = SingleOperationData(
operation=name,
data=value[http_method],
Expand All @@ -168,12 +190,21 @@ def set_obj_paths(self, paths: Dict[str, dict]) -> List[Tuple[str, dict]]:
if not self.operation_data:
raise ValueError("No paths found, API3 obj docs will be broken.")

def _generate_data(self):
for provider_name, provider_obj in providers.items():
self._provider_details[provider_name] = ProviderDetails(
provider=provider_obj,
operations_supported=[],
data=dict(),
)

@staticmethod
def _get_name_from_id(operation_id: str) -> str:

return operation_id.split("_")[-1]

def get_providers_from_name(self, enum: List[str]) -> List[BaseProvider]:
@staticmethod
def get_providers_from_name(enum: List[str]) -> List[BaseProvider]:
return [get_provider(key) for key in enum]

def create_obj_views(self, operation: SingleOperationData): ...

0 comments on commit 3907456

Please sign in to comment.