Skip to content

Commit d68c3db

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 6a530c7 + 5ca82f5 commit d68c3db

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

.github/workflows/build.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
deploy:
9+
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: '3.x'
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install poetry
22+
- name: Build and publish
23+
run: |
24+
poetry version $(git describe --tags --abbrev=0)
25+
poetry build
26+
poetry publish --username ${{ secrets.PYPI_USERNAME }} --password ${{ secrets.PYPI_PASSWORD }}

README.md

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,30 @@
1-
# pydantic-fastapi-converter
2-
pydantic to fastapi model converter.
1+
# pyfa-converter
2+
Makes it pretty easy to create a model based on Field [pydantic] and use the model for www-form-data.
3+
4+
### How to simplify your life?
5+
![image](https://user-images.githubusercontent.com/64792903/161491444-60e211fe-26c3-44ea-aade-a7c4177eaa74.png)
6+
7+
---
8+
9+
### What do I need to do with the model?
10+
* We put the decorator `@PydanticConverter.body` for the model and enjoy.
11+
* `data: YourPydanticModel = FormBody()`
12+
13+
---
14+
15+
If you want to accept a file on an endpoint, then the content-type for that endpoint changes from application/json to www-form-data.
16+
17+
FastAPI does not know how to override the pydantic schema so that parameters are passed as form.
18+
Even if you do
19+
20+
`foo: CustomPydanticModel = Depends()`
21+
all model attributes will be passed as query, but we want them to become body, that's what this library exists for.
22+
23+
### Usually you use something along the lines of:
24+
![image](https://user-images.githubusercontent.com/64792903/161484700-642e3d0e-242f-49f6-82e8-45c5e912a2c2.png)
25+
26+
But, if we accept a lot of fields, then the function becomes very large (the number of attributes for the endpoint increases and it does not look very good).
27+
28+
Thanks to this library, it is possible to force the conversion of Field fields into fields of FastAPI Form with full preservation of all attributes (alias, gt, te, description, title, example and more...)
29+
30+

0 commit comments

Comments
 (0)