Skip to content

Commit 464eff1

Browse files
committed
fix import errors
1 parent b500c4b commit 464eff1

File tree

6 files changed

+56
-54
lines changed

6 files changed

+56
-54
lines changed

martin_eden/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from martin_eden import core
22
from martin_eden import database
33
from martin_eden import http_utils
4-
from martin_eden import main
4+
from martin_eden import base
55
from martin_eden import openapi
66
from martin_eden import routing
77
from martin_eden import utils
@@ -10,7 +10,7 @@
1010
'core',
1111
'database',
1212
'http_utils',
13-
'main',
13+
'base',
1414
'openapi',
1515
'routing',
1616
'utils',

martin_eden/base.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from typing import ParamSpecArgs, ParamSpecKwargs, Any
2+
3+
from marshmallow import Schema
4+
from marshmallow.decorators import post_dump
5+
from marshmallow_jsonschema import JSONSchema
6+
7+
8+
class Controller:
9+
"""The class needs only as type hint"""
10+
request_schema: Schema
11+
response_schema: Schema
12+
query_params: dict
13+
14+
def __call__(
15+
self, *args: ParamSpecArgs, **kwargs: ParamSpecKwargs,
16+
) -> None:
17+
pass
18+
19+
20+
class CustomSchema(Schema):
21+
def __init__(
22+
self,
23+
*args: ParamSpecArgs,
24+
json_schema_name: str = None,
25+
**kwargs: ParamSpecKwargs,
26+
) -> None:
27+
super().__init__(*args, **kwargs)
28+
self.json_schema_name = json_schema_name
29+
self.__name__ = json_schema_name
30+
31+
32+
class CustomJsonSchema(JSONSchema):
33+
@post_dump
34+
def wrap(self, data: dict, **_) -> dict[str, Any]:
35+
"""Wrap this with the root schema definitions."""
36+
if self.nested: # no need to wrap, will be in outer defs
37+
return data
38+
39+
schema_name = self.obj.json_schema_name
40+
41+
data["additionalProperties"] = False
42+
43+
self._nested_schema_classes[schema_name] = data
44+
root = {
45+
"$schema": "http://json-schema.org/draft-07/schema#",
46+
"definitions": self._nested_schema_classes,
47+
"$ref": f"#/definitions/{schema_name}",
48+
}
49+
return root

martin_eden/core.py

+2-49
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
from typing import ParamSpecArgs, ParamSpecKwargs
2-
3-
from marshmallow import Schema
4-
from marshmallow.decorators import post_dump
5-
from marshmallow_jsonschema import JSONSchema
61

72
import asyncio
83
import dataclasses
@@ -19,58 +14,16 @@
1914
from martin_eden.openapi import OpenApiBuilder
2015
from martin_eden.routing import ControllerDefinitionError, get_controller, register_route
2116
from martin_eden.utils import get_argument_names
17+
from martin_eden.base import Controller
2218

2319
db = DataBase()
2420

21+
2522
@register_route('/schema/', 'get')
2623
async def get_openapi_schema() -> str:
2724
return json.dumps(OpenApiBuilder().openapi_object)
2825

2926

30-
class Controller:
31-
"""The class needs only as type hint"""
32-
request_schema: Schema
33-
response_schema: Schema
34-
query_params: dict
35-
36-
def __call__(
37-
self, *args: ParamSpecArgs, **kwargs: ParamSpecKwargs,
38-
) -> None:
39-
pass
40-
41-
42-
class CustomSchema(Schema):
43-
def __init__(
44-
self,
45-
*args: ParamSpecArgs,
46-
json_schema_name: str = None,
47-
**kwargs: ParamSpecKwargs,
48-
) -> None:
49-
super().__init__(*args, **kwargs)
50-
self.json_schema_name = json_schema_name
51-
self.__name__ = json_schema_name
52-
53-
54-
class CustomJsonSchema(JSONSchema):
55-
@post_dump
56-
def wrap(self, data: dict, **_) -> dict[str, Any]:
57-
"""Wrap this with the root schema definitions."""
58-
if self.nested: # no need to wrap, will be in outer defs
59-
return data
60-
61-
schema_name = self.obj.json_schema_name
62-
63-
data["additionalProperties"] = False
64-
65-
self._nested_schema_classes[schema_name] = data
66-
root = {
67-
"$schema": "http://json-schema.org/draft-07/schema#",
68-
"definitions": self._nested_schema_classes,
69-
"$ref": f"#/definitions/{schema_name}",
70-
}
71-
return root
72-
73-
7427
class HttpRequestHandler:
7528
def __init__(
7629
self, event_loop: AbstractEventLoop, client_socket: socket.socket,

martin_eden/database.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414
from sqlalchemy.orm import DeclarativeBase
1515

16-
from martin_eden.core import CustomSchema
16+
from martin_eden.base import CustomSchema
1717
from martin_eden.utils import (
1818
get_name_of_model,
1919
get_python_field_type_from_alchemy_field,

martin_eden/openapi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from typing import TYPE_CHECKING
55

6-
from martin_eden.core import CustomJsonSchema, CustomSchema
6+
from martin_eden.base import CustomJsonSchema, CustomSchema
77
from martin_eden.utils import (
88
dict_set,
99
get_name_of_model,

martin_eden/routing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Callable, ParamSpecArgs, ParamSpecKwargs
22

3-
from martin_eden.core import Controller, CustomSchema
3+
from martin_eden.base import Controller, CustomSchema
44
from martin_eden.openapi import OpenApiBuilder
55

66
DictOfRoutes = dict[str, dict[str, Controller]]

0 commit comments

Comments
 (0)