Skip to content

Commit 3aa9019

Browse files
committed
Fixed failing tests
1 parent da6f8c1 commit 3aa9019

15 files changed

+131
-22
lines changed

ellar/common/params/decorators/models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def Path(
2424
example: t.Any = Undefined,
2525
examples: t.Optional[t.Dict[str, t.Any]] = None,
2626
deprecated: t.Optional[bool] = None,
27+
include_in_schema: bool = True,
2728
**extra: t.Any,
2829
) -> t.Any:
2930
"""
@@ -44,6 +45,7 @@ def Path(
4445
example=example,
4546
examples=examples,
4647
deprecated=deprecated,
48+
include_in_schema=include_in_schema,
4749
**extra,
4850
)
4951

@@ -64,6 +66,7 @@ def Query(
6466
example: t.Any = Undefined,
6567
examples: t.Optional[t.Dict[str, t.Any]] = None,
6668
deprecated: t.Optional[bool] = None,
69+
include_in_schema: bool = True,
6770
**extra: t.Any,
6871
) -> t.Any:
6972
"""
@@ -84,6 +87,7 @@ def Query(
8487
example=example,
8588
examples=examples,
8689
deprecated=deprecated,
90+
include_in_schema=include_in_schema,
8791
**extra,
8892
)
8993

@@ -105,6 +109,7 @@ def Header(
105109
example: t.Any = Undefined,
106110
examples: t.Optional[t.Dict[str, t.Any]] = None,
107111
deprecated: t.Optional[bool] = None,
112+
include_in_schema: bool = True,
108113
**extra: t.Any,
109114
) -> t.Any:
110115
"""
@@ -126,6 +131,7 @@ def Header(
126131
example=example,
127132
examples=examples,
128133
deprecated=deprecated,
134+
include_in_schema=include_in_schema,
129135
**extra,
130136
)
131137

@@ -146,6 +152,7 @@ def Cookie(
146152
example: t.Any = Undefined,
147153
examples: t.Optional[t.Dict[str, t.Any]] = None,
148154
deprecated: t.Optional[bool] = None,
155+
include_in_schema: bool = True,
149156
**extra: t.Any,
150157
) -> t.Any:
151158
"""
@@ -166,6 +173,7 @@ def Cookie(
166173
example=example,
167174
examples=examples,
168175
deprecated=deprecated,
176+
include_in_schema=include_in_schema,
169177
**extra,
170178
)
171179

@@ -187,6 +195,7 @@ def Body(
187195
regex: t.Optional[str] = None,
188196
example: t.Any = Undefined,
189197
examples: t.Optional[t.Dict[str, t.Any]] = None,
198+
include_in_schema: bool = True,
190199
**extra: t.Any,
191200
) -> t.Any:
192201
"""
@@ -208,6 +217,7 @@ def Body(
208217
regex=regex,
209218
example=example,
210219
examples=examples,
220+
include_in_schema=include_in_schema,
211221
**extra,
212222
)
213223

@@ -228,6 +238,7 @@ def Form(
228238
regex: t.Optional[str] = None,
229239
example: t.Any = Undefined,
230240
examples: t.Optional[t.Dict[str, t.Any]] = None,
241+
include_in_schema: bool = True,
231242
**extra: t.Any,
232243
) -> t.Any:
233244
"""
@@ -248,6 +259,7 @@ def Form(
248259
regex=regex,
249260
example=example,
250261
examples=examples,
262+
include_in_schema=include_in_schema,
251263
**extra,
252264
)
253265

@@ -268,6 +280,7 @@ def File(
268280
regex: t.Optional[str] = None,
269281
example: t.Any = Undefined,
270282
examples: t.Optional[t.Dict[str, t.Any]] = None,
283+
include_in_schema: bool = True,
271284
**extra: t.Any,
272285
) -> t.Any:
273286
"""
@@ -288,6 +301,7 @@ def File(
288301
regex=regex,
289302
example=example,
290303
examples=examples,
304+
include_in_schema=include_in_schema,
291305
**extra,
292306
)
293307

@@ -309,6 +323,7 @@ def WsBody(
309323
regex: t.Optional[str] = None,
310324
example: t.Any = Undefined,
311325
examples: t.Optional[t.Dict[str, t.Any]] = None,
326+
include_in_schema: bool = True,
312327
**extra: t.Any,
313328
) -> t.Any:
314329
"""
@@ -330,5 +345,6 @@ def WsBody(
330345
regex=regex,
331346
example=example,
332347
examples=examples,
348+
include_in_schema=include_in_schema,
333349
**extra,
334350
)

ellar/common/params/params.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(
6060
example: t.Any = Undefined,
6161
examples: t.Optional[t.Dict[str, t.Any]] = None,
6262
deprecated: t.Optional[bool] = None,
63+
include_in_schema: bool = True,
6364
**extra: t.Any,
6465
) -> None:
6566
self.deprecated = deprecated
@@ -76,6 +77,7 @@ def __init__(
7677
le=le,
7778
min_length=min_length,
7879
max_length=max_length,
80+
include_in_schema=include_in_schema,
7981
regex=regex,
8082
**extra,
8183
)
@@ -114,6 +116,7 @@ def __init__(
114116
example: t.Any = Undefined,
115117
examples: t.Optional[t.Dict[str, t.Any]] = None,
116118
deprecated: t.Optional[bool] = None,
119+
include_in_schema: bool = True,
117120
**extra: t.Any,
118121
) -> None:
119122
super().__init__(
@@ -129,6 +132,7 @@ def __init__(
129132
max_length=max_length,
130133
regex=regex,
131134
deprecated=deprecated,
135+
include_in_schema=include_in_schema,
132136
example=example,
133137
examples=examples,
134138
**extra,
@@ -162,6 +166,7 @@ def __init__(
162166
example: t.Any = Undefined,
163167
examples: t.Optional[t.Dict[str, t.Any]] = None,
164168
deprecated: t.Optional[bool] = None,
169+
include_in_schema: bool = True,
165170
**extra: t.Any,
166171
):
167172
self.convert_underscores = convert_underscores
@@ -178,6 +183,7 @@ def __init__(
178183
max_length=max_length,
179184
regex=regex,
180185
deprecated=deprecated,
186+
include_in_schema=include_in_schema,
181187
example=example,
182188
examples=examples,
183189
**extra,
@@ -213,6 +219,7 @@ def __init__(
213219
regex: t.Optional[str] = None,
214220
example: t.Any = Undefined,
215221
examples: t.Optional[t.Dict[str, t.Any]] = None,
222+
include_in_schema: bool = True,
216223
**extra: t.Any,
217224
) -> None:
218225
self.embed = embed
@@ -231,6 +238,7 @@ def __init__(
231238
max_length=max_length,
232239
regex=regex,
233240
examples=examples,
241+
include_in_schema=include_in_schema,
234242
example=example,
235243
**extra,
236244
)
@@ -266,6 +274,7 @@ def __init__(
266274
regex: t.Optional[str] = None,
267275
example: t.Any = Undefined,
268276
examples: t.Optional[t.Dict[str, t.Any]] = None,
277+
include_in_schema: bool = True,
269278
**extra: t.Any,
270279
):
271280
super().__init__(
@@ -282,6 +291,7 @@ def __init__(
282291
regex=regex,
283292
example=example,
284293
examples=examples,
294+
include_in_schema=include_in_schema,
285295
**extra,
286296
)
287297
self.embed = True

examples/01-carapp/carapp/apps/car/routers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ def index(request: Request):
1414

1515
from ellar.common import (
1616
DataclassSerializer,
17+
Inject,
1718
ModuleRouter,
18-
Provide,
19-
Req,
2019
render,
2120
render_template,
2221
)
22+
from ellar.core import Request
2323
from ellar.openapi import ApiTags
2424

2525
from .services import CarRepository
@@ -39,16 +39,18 @@ class CarObject(DataclassSerializer):
3939

4040

4141
@router.get(response={200: List[CarObject]})
42-
async def get_cars(repo: CarRepository = Provide()):
42+
async def get_cars(repo: Inject[CarRepository]):
4343
return repo.get_all()
4444

4545

4646
@router.http_route("/html", methods=["get", "post"])
4747
@render("index.html")
48-
async def get_car_html(repo: CarRepository = Provide()):
48+
async def get_car_html(repo: Inject[CarRepository]):
4949
return repo.get_all()
5050

5151

5252
@router.get("/html/outside")
53-
async def get_car_html_with_render(repo: CarRepository = Provide(), request=Req()):
53+
async def get_car_html_with_render(
54+
repo: Inject[CarRepository], request: Inject[Request]
55+
):
5456
return render_template("car/list.html", request=request, model=repo.get_all())

tests/test_routing/test_body_schema.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ async def create_item(product: Product):
2525
"requestBody": {
2626
"content": {
2727
"application/json": {
28-
"schema": {"$ref": "#/components/schemas/Product"}
28+
"schema": {
29+
"title": "Product",
30+
"allOf": [{"$ref": "#/components/schemas/Product"}],
31+
"include_in_schema": True,
32+
}
2933
}
3034
},
3135
"required": True,

tests/test_routing/test_body_schema_extra_properties.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ def foo(items: Items_):
3333
"requestBody": {
3434
"content": {
3535
"application/json": {
36-
"schema": {"$ref": "#/components/schemas/Items_"}
36+
"schema": {
37+
"title": "Items",
38+
"allOf": [{"$ref": "#/components/schemas/Items_"}],
39+
"include_in_schema": True,
40+
}
3741
}
3842
},
3943
"required": True,

tests/test_routing/test_body_union_schema.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
@post("/items/")
1616
def save_union_body_and_embedded_body(
17-
item: Union[OtherItem, Item], qty: int = Body(12)
17+
item: Body[Union[OtherItem, Item]], qty: Body[int, Body.P(default=12)]
1818
):
1919
return {"item": item, "qty": qty}
2020

@@ -116,12 +116,18 @@ def embed_qty(qty: int = Body(12, embed=True)):
116116
"properties": {
117117
"item": {
118118
"title": "Item",
119+
"include_in_schema": True,
119120
"anyOf": [
120121
{"$ref": "#/components/schemas/OtherItem"},
121122
{"$ref": "#/components/schemas/Item"},
122123
],
123124
},
124-
"qty": {"title": "Qty", "type": "integer", "default": 12},
125+
"qty": {
126+
"title": "Qty",
127+
"type": "integer",
128+
"default": 12,
129+
"include_in_schema": True,
130+
},
125131
},
126132
},
127133
}

tests/test_routing/test_cookie_schema.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,23 @@ def test_cookie_schema():
8787
assert params == [
8888
{
8989
"required": False,
90-
"schema": {"title": "To", "type": "string", "format": "date-time"},
90+
"schema": {
91+
"title": "To",
92+
"type": "string",
93+
"format": "date-time",
94+
"include_in_schema": True,
95+
},
9196
"name": "to",
9297
"in": "cookie",
9398
},
9499
{
95100
"required": False,
96-
"schema": {"title": "From", "type": "string", "format": "date-time"},
101+
"schema": {
102+
"title": "From",
103+
"type": "string",
104+
"format": "date-time",
105+
"include_in_schema": True,
106+
},
97107
"name": "from",
98108
"in": "cookie",
99109
},
@@ -102,6 +112,7 @@ def test_cookie_schema():
102112
"schema": {
103113
"allOf": [{"$ref": "#/components/schemas/Range"}],
104114
"default": 20,
115+
"include_in_schema": True,
105116
},
106117
"name": "range",
107118
"in": "cookie",

tests/test_routing/test_extra_args.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def query_params_extra(
8989
"title": "To",
9090
"type": "string",
9191
"format": "date-time",
92+
"include_in_schema": True,
9293
},
9394
"name": "to",
9495
"in": "query",
@@ -99,6 +100,7 @@ def query_params_extra(
99100
"title": "From",
100101
"type": "string",
101102
"format": "date-time",
103+
"include_in_schema": True,
102104
},
103105
"name": "from",
104106
"in": "query",
@@ -108,19 +110,28 @@ def query_params_extra(
108110
"schema": {
109111
"allOf": [{"$ref": "#/components/schemas/Range"}],
110112
"default": 20,
113+
"include_in_schema": True,
111114
},
112115
"name": "range",
113116
"in": "query",
114117
},
115118
{
116119
"required": True,
117-
"schema": {"title": "Query1", "type": "string"},
120+
"schema": {
121+
"title": "Query1",
122+
"type": "string",
123+
"include_in_schema": True,
124+
},
118125
"name": "query1",
119126
"in": "query",
120127
},
121128
{
122129
"required": True,
123-
"schema": {"title": "Query2", "type": "string"},
130+
"schema": {
131+
"title": "Query2",
132+
"type": "string",
133+
"include_in_schema": True,
134+
},
124135
"name": "query2",
125136
"in": "query",
126137
},

tests/test_routing/test_form_schema.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ def test_schema():
5555
assert params == {
5656
"content": {
5757
"application/x-www-form-urlencoded": {
58-
"schema": {"$ref": "#/components/schemas/Filter"}
58+
"schema": {
59+
"allOf": [{"$ref": "#/components/schemas/Filter"}],
60+
"include_in_schema": True,
61+
"title": "Will Not Work For Schema With Many Field",
62+
}
5963
}
6064
},
6165
"required": True,

0 commit comments

Comments
 (0)