Skip to content
Discussion options

You must be logged in to vote

@amirongit I don't know if you found a way to write a custom converter. I haven't found a way to do that, so I just patch the source code with the Enum type in the bindings converter like this

from enum import Enum, EnumType

class SyncBinder(Binder):
    ...
    def _get_default_converter(self, expected_type):
        ...
        if isinstance(expected_type, EnumType):
            return lambda value: value[0] if value else None

The usage is like normal FromQuery.

import typing as t
from enum import Enum, EnumType

from blacksheep import Application, FromQuery, get
from blacksheep.server.openapi.v3 import OpenAPIHandler
from openapidocs.v3 import Info


class OrderEnum(str, Enum):
    ASC =

Replies: 1 comment 1 reply

Comment options

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

Answer selected by amirongit
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