starmallow 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- starmallow/__init__.py +1 -1
- starmallow/applications.py +5 -2
- starmallow/exceptions.py +8 -1
- starmallow/ext/marshmallow/openapi.py +1 -1
- starmallow/routing.py +1 -1
- starmallow/schema_generator.py +11 -7
- starmallow/utils.py +4 -3
- {starmallow-0.2.0.dist-info → starmallow-0.2.1.dist-info}/METADATA +1 -1
- {starmallow-0.2.0.dist-info → starmallow-0.2.1.dist-info}/RECORD +11 -11
- {starmallow-0.2.0.dist-info → starmallow-0.2.1.dist-info}/WHEEL +0 -0
- {starmallow-0.2.0.dist-info → starmallow-0.2.1.dist-info}/licenses/LICENSE.md +0 -0
starmallow/__init__.py
CHANGED
starmallow/applications.py
CHANGED
@@ -35,7 +35,7 @@ from starmallow.exception_handlers import (
|
|
35
35
|
http_exception_handler,
|
36
36
|
request_validation_exception_handler,
|
37
37
|
)
|
38
|
-
from starmallow.exceptions import RequestValidationError
|
38
|
+
from starmallow.exceptions import RequestValidationError, SchemaGenerationError
|
39
39
|
from starmallow.middleware import AsyncExitStackMiddleware
|
40
40
|
from starmallow.responses import JSONResponse
|
41
41
|
from starmallow.routing import APIRoute, APIRouter
|
@@ -168,7 +168,10 @@ class StarMallow(Starlette):
|
|
168
168
|
def init_openapi(self):
|
169
169
|
if self.openapi_url:
|
170
170
|
async def openapi(req: Request) -> JSONResponse:
|
171
|
-
|
171
|
+
try:
|
172
|
+
return JSONResponse(self.openapi())
|
173
|
+
except Exception as e:
|
174
|
+
raise SchemaGenerationError() from e
|
172
175
|
|
173
176
|
self.add_route(self.openapi_url, openapi, include_in_schema=False)
|
174
177
|
|
starmallow/exceptions.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
from typing import Any, Dict, List, Union
|
2
2
|
|
3
3
|
from starlette.exceptions import HTTPException
|
4
|
-
from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY
|
4
|
+
from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY, HTTP_500_INTERNAL_SERVER_ERROR
|
5
5
|
|
6
6
|
|
7
7
|
class RequestValidationError(HTTPException):
|
@@ -20,3 +20,10 @@ class WebSocketRequestValidationError(HTTPException):
|
|
20
20
|
) -> None:
|
21
21
|
super().__init__(status_code=HTTP_422_UNPROCESSABLE_ENTITY)
|
22
22
|
self.errors = errors
|
23
|
+
|
24
|
+
|
25
|
+
class SchemaGenerationError(HTTPException):
|
26
|
+
def __init__(
|
27
|
+
self,
|
28
|
+
) -> None:
|
29
|
+
super().__init__(status_code=HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to generate schema")
|
@@ -240,7 +240,7 @@ class OpenAPIConverter(ApiSpecOpenAPIConverter):
|
|
240
240
|
ret["explode"] = True
|
241
241
|
ret["style"] = "form"
|
242
242
|
if prop.get("description", None):
|
243
|
-
ret["description"] = prop.pop("description")
|
243
|
+
ret["description"] = prop.pop("description", None)
|
244
244
|
ret["schema"] = prop
|
245
245
|
|
246
246
|
if 'deprecated' in field.metadata:
|
starmallow/routing.py
CHANGED
starmallow/schema_generator.py
CHANGED
@@ -4,6 +4,7 @@ import itertools
|
|
4
4
|
import re
|
5
5
|
import warnings
|
6
6
|
from collections import defaultdict
|
7
|
+
from logging import getLogger
|
7
8
|
from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Type
|
8
9
|
|
9
10
|
import marshmallow as ma
|
@@ -29,6 +30,7 @@ from starmallow.utils import (
|
|
29
30
|
status_code_ranges,
|
30
31
|
)
|
31
32
|
|
33
|
+
logger = getLogger(__name__)
|
32
34
|
|
33
35
|
class SchemaRegistry(dict):
|
34
36
|
'''
|
@@ -410,10 +412,8 @@ class SchemaGenerator(BaseSchemaGenerator):
|
|
410
412
|
|
411
413
|
# Add default error response
|
412
414
|
if (any_params or endpoint.body_params or endpoint.form_params) and not any(
|
413
|
-
[
|
414
|
-
status in schema['responses']
|
415
|
+
status in schema['responses']
|
415
416
|
for status in ["422", "4XX", "default"]
|
416
|
-
],
|
417
417
|
):
|
418
418
|
self._add_default_error_response(schema)
|
419
419
|
|
@@ -449,9 +449,13 @@ class SchemaGenerator(BaseSchemaGenerator):
|
|
449
449
|
endpoints_info = self.get_endpoints(routes)
|
450
450
|
|
451
451
|
for path, endpoints in endpoints_info.items():
|
452
|
-
|
453
|
-
path
|
454
|
-
|
455
|
-
|
452
|
+
try:
|
453
|
+
self.spec.path(
|
454
|
+
path=path,
|
455
|
+
operations=self.get_operations(endpoints),
|
456
|
+
)
|
457
|
+
except Exception:
|
458
|
+
logger.error(f'Failed to generate schema for path {path}')
|
459
|
+
raise
|
456
460
|
|
457
461
|
return self.spec.to_dict()
|
starmallow/utils.py
CHANGED
@@ -32,6 +32,7 @@ import marshmallow as ma
|
|
32
32
|
import marshmallow.fields as mf
|
33
33
|
import marshmallow_dataclass.collection_field as collection_field
|
34
34
|
from marshmallow.validate import Equal, OneOf
|
35
|
+
from starlette.responses import Response
|
35
36
|
from typing_inspect import is_final_type, is_generic_type, is_literal_type
|
36
37
|
|
37
38
|
from starmallow.concurrency import contextmanager_in_threadpool
|
@@ -257,9 +258,9 @@ def eq_marshmallow_fields(left: mf.Field, right: mf.Field) -> bool:
|
|
257
258
|
This compares them instead.
|
258
259
|
'''
|
259
260
|
left_dict = left.__dict__.copy()
|
260
|
-
left_dict.pop('_creation_index')
|
261
|
+
left_dict.pop('_creation_index', None)
|
261
262
|
right_dict = right.__dict__.copy()
|
262
|
-
right_dict.pop('_creation_index')
|
263
|
+
right_dict.pop('_creation_index', None)
|
263
264
|
|
264
265
|
return left_dict == right_dict
|
265
266
|
|
@@ -302,7 +303,7 @@ def deep_dict_update(main_dict: Dict[Any, Any], update_dict: Dict[Any, Any]) ->
|
|
302
303
|
|
303
304
|
|
304
305
|
def create_response_model(type_: Type[Any]) -> ma.Schema | mf.Field | None:
|
305
|
-
if type_
|
306
|
+
if type_ in [inspect._empty, None] or issubclass(type_, Response):
|
306
307
|
return None
|
307
308
|
|
308
309
|
field = get_model_field(type_)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
starmallow/__init__.py,sha256=
|
2
|
-
starmallow/applications.py,sha256=
|
1
|
+
starmallow/__init__.py,sha256=Z9SbracH7YsHAB1n1L9nHMbxRCARFs22aHL9Nq8F9oU,312
|
2
|
+
starmallow/applications.py,sha256=2lgblSsk9vbVI9t-r0RcvfFuvLB_vFw2OebSDiVO_TM,29311
|
3
3
|
starmallow/concurrency.py,sha256=MVRjo4Vqss_yqhaoeVt3xb7rLaSuAq_q9uYgTwbsojE,1375
|
4
4
|
starmallow/constants.py,sha256=u0h8cJKhJY0oIZqzr7wpEZG2bPLrw5FroMnn3d8KBNQ,129
|
5
5
|
starmallow/dataclasses.py,sha256=ap9DInvQjH2AyI4MAAnbDEuNnbPb94PigaNmEb7AQU8,2658
|
@@ -10,19 +10,19 @@ starmallow/docs.py,sha256=eA39LunVMEoPU5ge4qxm2eiJbrFTUSUu5EhG1L_LKxk,6268
|
|
10
10
|
starmallow/endpoint.py,sha256=5oHoWu2dSG_nnctRM60ZPkB1R9Mh4cJv5yxRbYEZHec,15593
|
11
11
|
starmallow/endpoints.py,sha256=UrwVZCxbmWI20iNtJ0oXxo4d3-y12TjsOGs_jnStTiU,939
|
12
12
|
starmallow/exception_handlers.py,sha256=gr2qLYWEtsIEH28n7OreEiiLVz6Y7b6osRyS9esJbBk,891
|
13
|
-
starmallow/exceptions.py,sha256=
|
13
|
+
starmallow/exceptions.py,sha256=vabtPJkTmtCdC8_2OPBE8Osz0v0KxaSOX6IWf1jgNkc,872
|
14
14
|
starmallow/fields.py,sha256=arrTabCYoJFZcoY69EZTBH3YUg7CUSr3-zYLiAjYLTM,1238
|
15
15
|
starmallow/params.py,sha256=XRWIFLm2H5jQUIo4gm5Oi4xVqGNosaQSSi7QYqjJyxQ,7000
|
16
16
|
starmallow/responses.py,sha256=k2pf_m21ykf_FECdODUz400pMucMJJf_Zm8TXFujvaU,2012
|
17
|
-
starmallow/routing.py,sha256=
|
18
|
-
starmallow/schema_generator.py,sha256=
|
17
|
+
starmallow/routing.py,sha256=UaqP4NLw7g3-gBFO85x83NDpsbFCZJMIjxQPT31BCS4,47257
|
18
|
+
starmallow/schema_generator.py,sha256=6cMXlovR9xiA3g3Aryt6XFlzC74VVE-s_Ltsfl0nm-M,16815
|
19
19
|
starmallow/serializers.py,sha256=rBEKMNgONgz_bai12uDvAEMCI_aEFGsqMSeIoWtlrOI,12514
|
20
20
|
starmallow/types.py,sha256=8GXWjvzXQhF5NMHf14fbid6uErxVd1Xk_w2I4FoUgZ4,717
|
21
|
-
starmallow/utils.py,sha256=
|
21
|
+
starmallow/utils.py,sha256=MS44NCYDpKA3JRCvJ7lRhrBK57wT5T8QlylZxlcZLEU,9484
|
22
22
|
starmallow/websockets.py,sha256=yIz3LzTBMNclpEoG7oTMbQwxbcdKNU6M8XcqZMyBTuA,2223
|
23
23
|
starmallow/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
24
|
starmallow/ext/marshmallow/__init__.py,sha256=33jENGdfPq4-CDG0LOmN3KOGW1pXTy7a2oMwy4hrYzM,208
|
25
|
-
starmallow/ext/marshmallow/openapi.py,sha256=
|
25
|
+
starmallow/ext/marshmallow/openapi.py,sha256=5aGvbwLGVucsVhXExpYeyt8n5dQTzazrf-nuh6mVhmA,9017
|
26
26
|
starmallow/middleware/__init__.py,sha256=vtNm85Z9pUPjJd-9giJGg3YL1wO7Jm5ooXBm31pDOK8,53
|
27
27
|
starmallow/middleware/asyncexitstack.py,sha256=0GPhQSxqSVmAiVIqBIN5slueWYZ8bwh9f2bBPy7AbP0,1191
|
28
28
|
starmallow/security/__init__.py,sha256=1rQFBIGnEbE51XDZSSi9NgPjXLScFq3RoLu4vk0KVYw,191
|
@@ -32,7 +32,7 @@ starmallow/security/http.py,sha256=rMwBYQQRil5iVjM87b0gsCENSFQXiqsdAfy0g6Qmvt8,6
|
|
32
32
|
starmallow/security/oauth2.py,sha256=PWdrgqUeijxzRAQilXMXRb9DnA-U2-xMQ5LKL4S66t8,9914
|
33
33
|
starmallow/security/open_id_connect_url.py,sha256=ykokB7mJYu4pFsHW4Ro1y71h-5H11mt90jyv64EIQBM,1386
|
34
34
|
starmallow/security/utils.py,sha256=bd8T0YM7UQD5ATKucr1bNtAvz_Y3__dVNAv5UebiPvc,293
|
35
|
-
starmallow-0.2.
|
36
|
-
starmallow-0.2.
|
37
|
-
starmallow-0.2.
|
38
|
-
starmallow-0.2.
|
35
|
+
starmallow-0.2.1.dist-info/METADATA,sha256=a-W6lFF1CHbt1bMQxz-VBT-flN3cZh_5FHB-WF0MBDA,5651
|
36
|
+
starmallow-0.2.1.dist-info/WHEEL,sha256=y1bSCq4r5i4nMmpXeUJMqs3ipKvkZObrIXSvJHm1qCI,87
|
37
|
+
starmallow-0.2.1.dist-info/licenses/LICENSE.md,sha256=QelyGgOzch8CXzy6HrYwHh7nmj0rlWkDA0YzmZ3CPaY,1084
|
38
|
+
starmallow-0.2.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|