Skip to content

Commit

Permalink
Add Annotated example to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanderlee committed Jan 8, 2024
1 parent 5c6945c commit 893b725
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ An example of Pydantic's limitations can be found in [Issue 2277](https://github
Create a file `main.py` with:

```python
from typing import Annotated
from marshmallow_dataclass import dataclass
from starmallow import Body, Path, StarMallow

Expand All @@ -32,7 +33,7 @@ class MyBody:

@app.get("/body")
async def get_body(body: MyBody = Body()) -> int:
return MyBody.item_id
return body.item_id


# Example with explicit marshmallow schema
Expand All @@ -42,6 +43,13 @@ class MyBodySchema(ma.Schema):
@app.get("/path/body_schema")
def get_body_from_schema(body: Dict[str, int] = Body(model=MyBodySchema)) -> int:
return body['item_id']


# Example with Annotated

@app.get("/body_annotated")
async def get_body_annotated(body: Annotated[MyBody, Body()]) -> int:
return body.item_id
```

### Run it
Expand Down

0 comments on commit 893b725

Please sign in to comment.