Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add other Pydantic dict params to path operations#264

Merged
tiangolo merged 6 commits intomasterfrom
pydantic-dict-params
May 27, 2019
Merged

Add other Pydantic dict params to path operations#264
tiangolo merged 6 commits intomasterfrom
pydantic-dict-params

Conversation

@tiangolo
Copy link
Member

Add other Pydantic dict params to path operations.

To include all the parameters supported by Pydantic's model's.dict().

@codecov
Copy link

codecovbot commentedMay 27, 2019
edited
Loading

Codecov Report

Merging#264 intomaster willnot change coverage.
The diff coverage is100%.

Impacted file tree graph

@@          Coverage Diff           @@##           master   #264    +/-   ##======================================  Coverage     100%   100%            ======================================  Files         183    190     +7       Lines        4539   4649   +110     ======================================+ Hits         4539   4649   +110
Impacted FilesCoverage Δ
...t_tutorial/test_response_model/test_tutorial004.py100% <ø> (ø)⬆️
docs/src/body_updates/tutorial001.py100% <100%> (ø)
docs/src/response_model/tutorial006.py100% <100%> (ø)
docs/src/response_model/tutorial005.py100% <100%> (ø)
fastapi/routing.py100% <100%> (ø)⬆️
fastapi/applications.py100% <100%> (ø)⬆️
docs/src/response_model/tutorial004.py100% <100%> (ø)⬆️
...est_tutorial/test_body_updates/test_tutorial001.py100% <100%> (ø)
...t_tutorial/test_response_model/test_tutorial006.py100% <100%> (ø)
tests/test_operations_signatures.py100% <100%> (ø)
... and9 more

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last update747ae82...59b6ca4. Read thecomment docs.

@tiangolotiangolo merged commit7b63bc5 intomasterMay 27, 2019
@tiangolotiangolo deleted the pydantic-dict-params branchMay 27, 2019 12:08
@bs32g1038
Copy link

bs32g1038 commentedMay 27, 2019
edited
Loading

To be honest, these are good features, but I think it makesget, orother request functions bloated and less expansive.

  • too many fields are confusing. The function should keep simple. if we need select fields, that may be provide a extra higher order function to copy with the Pydantic model. what's more, directly using the the Pydantic model combination.
  • It doesn't make the code clearer and effectively reduce code duplication. most of data are composed of multiple models in daily use.

In my opinion, if the docs can auto generate the doc data by the real data, it will be a great thing.

class Item(BaseModel):    name: str = None    description: str = Noneitems = {    "foo": {"name": "Foo", "price": 50.2},    "bar": {"name": "Bar"},}@app.get("/items/{item_id}", response_model=Item)async def read_item(item_id: str):    return items[item_id]# resultonly show the name field in the doc modelbecause the response result only include the name field in the model.

Besides, Fastapi can provide a util function to reduce code repeat.

class Name(BaseModel):    name: str = Noneclass Description(BaseModel):    description: str = Noneclass Base(BaseModel):    code: int = None    data: combination({        items: List[combination(Name, Description)],        count: int    }) = Noneitems = {    "foo": {        "code": 0,        "data": {            "items": [],            "count": 0        }    }}@app.get("/items/{item_id}", response_model=Item)async def read_item(item_id: str):    return items[item_id]

To sum up, I look forward to these features very much.

@tiangolo
Copy link
MemberAuthor

@bs32g1038 these additional parameters are mainly for completeness.

The name of the parameters is temporal, as I think it's quite long. But I don't expect users to use them a lot. That's why they are at the end of the function.

But for completeness, it might help some use cases.

About your first use case, you can enable that behavior with one of these parameters (from a previous PR):response_model_skip_defaults=True:https://fastapi.tiangolo.com/tutorial/response-model/#use-the-response_model_skip_defaults-parameter

That's something that can help some use cases, but others might need to keep the default values.

@bs32g1038
Copy link

bs32g1038 commentedMay 29, 2019
edited
Loading

@tiangolo thanks, I got it!

tiangolo reacted with thumbs up emoji

lmignon pushed a commit to acsone/fastapi that referenced this pull requestSep 19, 2024
Signed-off-by lmignon
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@tiangolo@bs32g1038

Comments


[8]ページ先頭

©2009-2026 Movatter.jp