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

Add documentation to existing route #202

Open
ChosunOne opened this issue Mar 18, 2025 · 2 comments · May be fixed by #203
Open

Add documentation to existing route #202

ChosunOne opened this issue Mar 18, 2025 · 2 comments · May be fixed by #203

Comments

@ChosunOne
Copy link

I am in the process of trying to adopt leptos into my axum & aide server but i'm facing difficulties because aide requires you to attach the transformation to a route via ApiRouter.api_route which also adds the handler. But I don't want to use ApiRouter to define my routes because leptos does not implement their necessary trait for it, only for axum's Router. I want to be able to attach my get_docs etc. transformation functions to an existing route in the router without having to use the ApiRouter's route definition methods. This way, I can let leptos define my routers and then tag documentation to them later via the from method for ApiRouter from a Router. Is this currently possible? You can see how I'm doing it now (without leptos):

impl Api for UserApi {
    fn router(state: AppState) -> ApiRouter<AppState> {
        ApiRouter::new()
            .api_route("/", get_with(Self::get_list, Self::get_list_docs))
            .api_route("/{id}", get_with(Self::get, Self::get_docs))
            .api_route("/", post_with(Self::create, Self::create_docs))
            .api_route("/{id}", patch_with(Self::update, Self::update_docs))
            .api_route("/{id}", delete_with(Self::delete, Self::delete_docs))
            .layer(
                ServiceBuilder::new()
                    .layer(AsyncRequireAuthorizationLayer::new(Authenticator))
                    .layer(from_fn_with_state(state.clone(), set_user_groups)),
            )
            .with_state(state)
    }
}

But I want something like:

impl Api for UserApi {
    fn router(state: AppState) -> ApiRouter<AppState> {
        let router = Router::new()
             .leptos_routes_with_context(...)
             .layer(...)
             .with_state(state);

        ApiRouter::from(router)
            .api_route_docs("/", get_docs(Self::get_list_docs))
            .api_route_docs("/{id}", get_docs(Self::get_docs))
            .api_route_docs("/", post_docs(Self::create_docs))
            .api_route_docs("/{id}", patch_docs(Self::update_docs))
            .api_route_docs("/{id}", delete_docs(Self::delete_docs))
    }
}

Ideally I think it would be best if I didn't need to depend on using ApiRouter to add documentation to the axum router, rather just implementing traits or something instead.

@jplatte
Copy link
Collaborator

jplatte commented Mar 18, 2025

This project is passively maintained, there is nobody actively driving development. So I'm afraid the only way to make this happen is to fork.

@JakkuSakura
Copy link
Collaborator

I happen to have some time for it. It's a very primitive implementation without handy macros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants