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

Rewrite the Generate Endpoints script #30

Open
EmmmaTech opened this issue Jul 20, 2023 · 0 comments
Open

Rewrite the Generate Endpoints script #30

EmmmaTech opened this issue Jul 20, 2023 · 0 comments
Labels
lib: discatcore This PR/issue is for DisCatCore. p: low priority: low - This PR/issue is not important, can be delayed for a while. t: refactor type: refactor - This PR refactors code or this issue proposes to refactor code.

Comments

@EmmmaTech
Copy link
Member

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

@EmmmaTech EmmmaTech added p: low priority: low - This PR/issue is not important, can be delayed for a while. t: refactor type: refactor - This PR refactors code or this issue proposes to refactor code. lib: discatcore This PR/issue is for DisCatCore. labels Jul 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lib: discatcore This PR/issue is for DisCatCore. p: low priority: low - This PR/issue is not important, can be delayed for a while. t: refactor type: refactor - This PR refactors code or this issue proposes to refactor code.
Projects
None yet
Development

No branches or pull requests

1 participant