aiogram/tg-codegen

Parse enums from documentation

Opened this issue · 0 comments

Example

We have type attribute in Chat class
image

So we should create an enum like this:

from aiogram.utils.enum import AutoName

from enum import auto


class ChatType(AutoName):
    PRIVATE = auto()
    GROUP = auto()
    SUPERGROUP = auto()
    CHANNEL = auto()

Enum class name should be generated from base class name and target field name capitalized: Chat + Type.
For MessageEntity.type field it should be MessageEntityType, so following the same rules.

More complex example

We have ChatMember and its subclasses that differ in status attribute
image

So we should create an enum like this:

from aiogram.utils.enum import AutoName

from enum import auto


class ChatMemberStatus(AutoName):
    CREATOR = auto()
    ADMINISTRATOR = auto()
    MEMBER = auto()
    RESTRICTED = auto()
    LEFT = auto()
    KICKED = auto()

Enum class name should be generated in the same way: ChatMember + Status.