Comments (6)
@fgsalomon, Firstly, Field should be used inside the pydantic model, not Form.
class MyRequest(BaseModel):
a: str | None = Field(default=None)
b: str | None = Field(default=None)
@validator('a')
def a_must_contain_space(cls, v):
if not v:
return v
if ' ' not in v:
raise ValueError('must contain a space')
return v.title()
@app.post("/test")
async def test(data: MyRequest | None = FormDepends(MyRequest)):
print(data)
from pyfa-converter.
Successful sending of the request, if you uncheck the swagger on send empty value buton.
from pyfa-converter.
@fgsalomon, Firstly, Field should be used inside the pydantic model, not Form.
class MyRequest(BaseModel): a: str | None = Field(default=None) b: str | None = Field(default=None)
Ooops, my bad. I've fixed this now. However, it seems to me it doesn't change anything.
Successful sending of the request, if you uncheck the swagger on send empty value buton.
Yeah, I know I can do that but what I would like is the model to be None
when no data is sent:
curl -X 'POST' \
'http://127.0.0.1:8000/test' \
-H 'accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded'
"Has form data"%
from pyfa-converter.
class MyRequest(BaseModel):
a: str | None = Field(default=None)
b: str | None = Field(default=None)
@root_validator
def all_is_none(cls, values: dict[str, Any]):
if all(v is None for v in values.values()):
raise ValueError("all is none")
return values
from pyfa-converter.
You need it?
from pyfa-converter.
i don't understand the essence of your task, first you want to allow None value, now you don't want None value...
from pyfa-converter.
Related Issues (8)
- Error: TypeError: unsupported operand type(s) for |: 'ModelMetaclass' and 'type' HOT 4
- error when adding Field constraint HOT 9
- Error with some specific field types HOT 4
- Default value "False" of BaseModel is ignored HOT 5
- support pydantic v2 HOT 3
- update python-multipart version to 0.0.6
- Add License HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyfa-converter.