Код: Выделить всё
import enum
from typing import Annotated, Literal
import uvicorn
from fastapi import FastAPI, Query, Depends
from pydantic import BaseModel
app = FastAPI()
class MyEnum(enum.Enum):
ab = "ab"
cd = "cd"
class MyInput(BaseModel):
q: Annotated[MyEnum, Query(...)]
@app.get("/")
def test(inp: MyInput = Depends()):
return "Hello world"
def main():
uvicorn.run("run:app", host="0.0.0.0", reload=True, port=8001)
if __name__ == "__main__":
main()
Код: Выделить всё
curl http://127.0.0.1:8001/?q=abНо любой из этих
Код: Выделить всё
curl http://127.0.0.1:8001/?q=aBКод: Выделить всё
curl http://127.0.0.1:8001/?q=ABКод: Выделить всё
curl http://127.0.0.1:8001/?q=Cd- etc
Как сделать эту проверку нечувствительной к регистру?
Подробнее здесь: https://stackoverflow.com/questions/761 ... nd-fastapi
Мобильная версия