Skip to content

How to add a validator to the path parameter of a request? #126

Answered by kemingy
Qparrot asked this question in Q&A
Discussion options

You must be logged in to vote

You almost got it. As you mentioned, flask URL variables doesn't support Enum. But you can use Enum in the URL query.

class Enum(str, Enum):
    nom = "nom"
    prenom ="prenom"
    commune = "commune"

class Query(BaseModel):
    column: Enum = Enum.nom

@utils.route('/distinct', methods=["GET"])
@spectree_api.validate(query=Query, resp=Response("HTTP_403", HTTP_200=DistinctResp), tags=["Utils"])
def get_distinct(column):
    ....

Try to query this service with http :8000/distinct?column=nom

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Qparrot
Comment options

Answer selected by Qparrot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants