'Fastapi: put method

I want to be able to change only one field in the put method at the swagger without having to define a new class for put.In this case, since all fields are required, I do not have permission to delete them and change only one item in the put field, but I just want to change one field without adding a new class. Thank you for your help

from pydantic import BaseModel
class User(BaseModel):
name: str 
email: str 
password: str




#------------------------------------------------------
from fastapi import FastAPI
user_ = FastAPI()
@user_.post("/")
def write_data(user_: User):
conn.execute(users.insert().values(
    name= user_.name,
    email= user_.email,
    password= user_.password
))



return{ 'New data  added' }

@user_.put("/{id}")
def update_data(id: int, user_: User):
a=conn.execute("SELECT id FROM users")
b=a.fetchall()
my_list=np.array(b)
if id in my_list:
    conn.execute(users.update().values(
    name= user_.name,
    email= user_.email,
    password= user_.password
        
    ).where(users.c.id == id ))
    

    
    return {'data updated white ID ' +str(id)} 
else: 
    
   
    return {'No data has been registered for ID ' +str(id)}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source