Skip to content
This repository was archived by the owner on Oct 22, 2023. It is now read-only.
This repository was archived by the owner on Oct 22, 2023. It is now read-only.

Rewrite the Generate Endpoints script #30

@EmmmaTech

Description

@EmmmaTech

Overview of the Feature Request
Rewrite the generate endpoints script, renaming it to generate_routes.py, rename the data/endpoints folder to data/routes, and change the type of the files used in data/routes from JSON to TOML.

What is this Feature Request for?
DisCatCore

The Problem
The generate endpoints script needs a good code scrub. There are some things that could be done better or just completely removed, like the function generator's generate method. Also the function generator's methods for managing arguments can be removed in favor of the publicly available list of args. There might be more, and they'll be seen in my PR.

Now to the name changes. Since the beginning of the endpoint generator, I thought that the name "endpoint" sounded more appropriate and did not consider the name "route" at all. The name "route" is used for the HTTP client to specify the metadata about a Discord API route. It makes more sense to name our endpoint generate a route generator since the route wrappers generated wrap Discord API routes (obviously).

Finally, the file change. JSON is unreadable for our purposes.. TOML would be a better format, since it's designed to be a config file format and human readable.

The Solution
Here's what a new route file under TOML will look like:

name = "UserRoutes"
requires = ["typing", "discord_typings"]

[get_current_user]
method = "GET"
url = "/users/@me"

[get_user]
method = "GET"
url.link = "/users/{user_id}"
url.parameters = [{name = "user_id", type = "dt.Snowflake"}]

[modify_current_user]
method = "PATCH"
url = "/users/@me"
json.parameters = [
    {name = "username", type = "UnsetOr[str]", default = "Unset"},
    {name = "avatar", type = "UnsetOr[t.Optional[str]]", default = "Unset"},
]

[get_current_user_guilds]
method = "GET"
url.link = "/users/@me/guilds"
url.parameters = [
    {name = "before", type = "UnsetOr[dt.Snowflake]", default = "Unset"},
    {name = "after", type = "UnsetOr[dt.Snowflake]", default = "Unset"},
    {name = "limit", type = "int", default = "200"},
]

Current Solution
N/A

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    lib: discatcoreThis PR/issue is for DisCatCore.p: lowpriority: low - This PR/issue is not important, can be delayed for a while.t: refactortype: refactor - This PR refactors code or this issue proposes to refactor code.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions