koxudaxi / fastapi-code-generator

This code generator creates FastAPI app from an openapi file.
MIT License
1.03k stars 104 forks source link

Amend reserved names when used as parameters #429

Open Zukunftsmusik opened 3 months ago

Zukunftsmusik commented 3 months ago

In my OAD, I'm using a query parameter called from. Code generation failed while formatting with black, since from is a reserved word in python and the operation's function signature couldn't be parsed.

A solution would be to automatically append an underscore (_) to the parameter name in the function signature, if it's a reserved word. Then use the alias keyword in the parameter definition's constructor (Path, Query etc.).