Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Add path of routes in schema typescript #3612

Open
Kumzy opened this issue Jul 7, 2024 · 1 comment
Open

Enhancement: Add path of routes in schema typescript #3612

Kumzy opened this issue Jul 7, 2024 · 1 comment
Labels
Enhancement This is a new feature or request OpenAPI This is related to our OpenAPI schema

Comments

@Kumzy
Copy link
Member

Kumzy commented Jul 7, 2024

Summary

Hello,

While building a frontend connected to litestar, I found that I had to type URL on my frontend but I would prefer using constant exported from litestar cli.

Using the command schema typescript, it would be nice if the routes (path) can be added to the exported file so we could import and use the route in the frontend.

The command schema openapiexport the paths in the file (in a different format of course)

Also, routes url should include the parameters in the exported file:
/v2/apps/{app_id}/deployments/{deployment_id}/cancel

After some searches, found some examples but do not know if it's relevant:
openapi-typescript

Basic Example

export namespace API {
    export namespace AccountLogin {

// Somewhere there the path 

        export namespace Http201 {
            export type ResponseBody = {
                access_token: string;
                expires_in ? : null | number;
                refresh_token ? : null | string;
                token_type: string;
            };
        };

        export namespace Http400 {
            export type ResponseBody = {
                detail: string;
                extra ? : Record < string,
                unknown > | null | unknown[];
                status_code: number;
            };
        };

        export type RequestBody = {
            password: string;
            username: string;
        };
    };
};

Example in the frontend.
Instead of using the following code:

function submit() {
    router.post("/api/access/login", form);
}

I could use

function submit() {
    router.post(API.AccountLogin.Path, form);
}

Drawbacks and Impact

No response

Unresolved questions

No response


Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@Kumzy Kumzy added the Enhancement This is a new feature or request label Jul 7, 2024
@Kumzy
Copy link
Member Author

Kumzy commented Jul 9, 2024

Also openapi-ts, there is a live demo on the gh page

@JacobCoffee JacobCoffee added the OpenAPI This is related to our OpenAPI schema label Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement This is a new feature or request OpenAPI This is related to our OpenAPI schema
Projects
Status: Triage
Development

No branches or pull requests

2 participants