Skip to content

Add QueryMask#97

Open
neocim wants to merge 7 commits intoreagento:developfrom
neocim:add-query-mask
Open

Add QueryMask#97
neocim wants to merge 7 commits intoreagento:developfrom
neocim:add-query-mask

Conversation

@neocim
Copy link
Copy Markdown
Contributor

@neocim neocim commented Apr 19, 2026

This class allows to create masks to convert the names of certain query parameters through a regular expression.

Usage:

class Api:
    @rest.get("/", QueryMask(lambda n: n.upper(), "^p.*$"))
    # only `phone_number` converts to `PHONE_NUMBER`
    def do_get(self, user_id: int, phone_number: str) -> Model: ...

If we need to set a default QueryMask for all rest methods, we can do it using default_query parameter:

# we may not to use regex
query_mask = QueryMask(lambda n: n.upper())
rest = RestBuilder(default_query=query_mask)

class Api:
    # parameters `a`, `b`, `c` will be converted to the ​​`A`, `B`, and `C` respectively, 
    # but `d` will be ignored, because it is an explicit query parameter
    @rest.get("/", Query("d"))
    def do_get(self, a: int, b: int, c: int, d: int) -> Model: ...

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant