flask-parameter-validation icon indicating copy to clipboard operation
flask-parameter-validation copied to clipboard

Implement Enum Validation

Open smt5541 opened this issue 1 year ago • 1 comments

🛠 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 StrEnum and IntEnum subclasses.

🧠 Rationale behind the change

Why did you choose to make these changes?

  • I have frequently used the func parameter to validate my Enum parameters from str or int, 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

smt5541 avatar Jun 30 '24 04:06 smt5541

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!"

Ge0rg3 avatar Jul 11 '24 16:07 Ge0rg3

Hey @Ge0rg3 just thought I should bump this, no rush though!

smt5541 avatar Aug 06 '24 19:08 smt5541

Hey @smt5541, please can you show some sample usage for this? Thanks!

Ge0rg3 avatar Aug 12 '24 15:08 Ge0rg3

Thanks!

Ge0rg3 avatar Aug 13 '24 14:08 Ge0rg3