Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Enum Validation #46

Merged
merged 7 commits into from
Aug 13, 2024
Merged

Implement Enum Validation #46

merged 7 commits into from
Aug 13, 2024

Conversation

smt5541
Copy link
Collaborator

@smt5541 smt5541 commented Jun 30, 2024

🛠 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

  • Have tests been added or updated for the changes introduced in this pull request?

  • Are the changes backwards compatible?

If the changes aren't backwards compatible, what other options were explored?

N/A

✨ Quality check

  • Are your changes free of any erroneous print statements, debuggers or other leftover code?

  • 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 smt5541 added the enhancement New feature or request label Jun 30, 2024
@smt5541 smt5541 self-assigned this Jun 30, 2024
@smt5541 smt5541 requested a review from Ge0rg3 June 30, 2024 04:39
@Ge0rg3 Ge0rg3 changed the base branch from master to dev/smt5541/multi_source July 11, 2024 16:14
@Ge0rg3 Ge0rg3 changed the base branch from dev/smt5541/multi_source to master July 11, 2024 16:14
@Ge0rg3
Copy link
Owner

Ge0rg3 commented Jul 11, 2024

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

@smt5541 smt5541 requested a review from Ge0rg3 July 14, 2024 00:56
@smt5541
Copy link
Collaborator Author

smt5541 commented Aug 6, 2024

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

@Ge0rg3
Copy link
Owner

Ge0rg3 commented Aug 12, 2024

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

@smt5541 smt5541 merged commit 9a7f186 into master Aug 13, 2024
4 checks passed
@smt5541 smt5541 deleted the dev/smt5541/enum branch August 13, 2024 14:35
@Ge0rg3
Copy link
Owner

Ge0rg3 commented Aug 13, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validating against enum
3 participants