I have a GET router function
which searches for employee(s) and return complete information of employee(s) . It works fine but when I check code quality it shows too-many-arguments error
in async function
.
I don't wants to disable this pylint error since its not a good practice.
Here is my code snippet.
@router.get('/employee', response_model=List[schemas.Employee],
responses={502: {"model": schemas.ErrorResponse},
422: {"model": schemas.ErrorResponse}}, status_code=200
async def get_employee(request: Request,emp_name: str = Query(None, example="John"),
search_string: str = Query(None, example="Canada"),
skip: int = Query(0, ge=0),
limit: int = Query(100, ge=0),
db_: Session = Depends(get_db)):
'''fetches all the employees with details
* the optional query parameter can be used to filter the result set
* skip=n: skips the first n objects in return list
* limit=n: limits the no. of items to be returned to n'''
return search_employee(db_, emp_name=emp_name,
search_string = search_string, skip=skip, limit=limit)
When i use args/**kwargs
as below I could only see a single field in swagger named args/kwargs
.
async def get_persons(request: Request, db_: Session = Depends(get_db), **kwargs):
emp_name = kwargs.get('emp_name', None)
search_string = kwargs.get('search_string', None)
skip = kwargs.get('skip', 0)
limit = kwargs.get('limit', 100)
return search_employee(db_, emp_name=emp_name,
search_string = search_string, skip=skip, limit=limit)
What I need in Swagger
is different fields emp_name,search_string,skip,limit where I can enter values separately. Please help. TIA