Implement Enum Validation
🛠 Changes being made
Give examples of the changes you've made in this pull request. Include an itemized list if you can.
- Add validation for
StrEnumandIntEnumsubclasses.
🧠 Rationale behind the change
Why did you choose to make these changes?
- I have frequently used the
funcparameter to validate myEnumparameters fromstrorint, but this is overhead that could easily be included in this library to reduce many similar validation functions
Does this pull request resolve any open issues?
Yes. Closes #44
Were there any trade-offs you had to consider?
Not particularly
🧪 Testing
-
[X] Have tests been added or updated for the changes introduced in this pull request?
-
[X] Are the changes backwards compatible?
If the changes aren't backwards compatible, what other options were explored?
N/A
✨ Quality check
-
[X] Are your changes free of any erroneous print statements, debuggers or other leftover code?
-
[X] Has the README been updated to reflect the changes introduced (if applicable)?
💬 Additional comments
Feel free to add any further information below
Dependent on #45
Hey, I'm a little hesitant on the StrEnum import as it'll lock us into Py3.11+ when this was added.
Perhaps for Strs we could just use typing.Literal instead? Eg
@app.route("/fruitshop/buy", methods=["POST"])
@ValidateParameters()
def buy_fruit(
fruit_name: typing.Literal["apple", "banana", "cherry"] = Json(),
):
return "Fruit bought!"
Hey @Ge0rg3 just thought I should bump this, no rush though!
Hey @smt5541, please can you show some sample usage for this? Thanks!
Thanks!