Skip to content

How to impl this case with aide #243

Closed

Description

@joebnb

hello, i have a quest about when handler recive a Result, the api docs seem out put empty(expect string)

a aide apirouter

use super::handler;
use aide::axum::{ApiRouter, routing::*};

pub fn register() -> ApiRouter {
    let test_router = ApiRouter::new()
        .api_route(
            "/session_save",
            get(handler::session_save),
        );
    ApiRouter::new().nest_api_service("/test", test_router)
}

when out put session with string with wrapper HttpResult

pub async fn session_save() -> http::HttpResult<String> {
    http::response_200(Some(format!("{} session saved ", total)), None)
}

http result implment

pub type HttpResult<T> = Result<SResponseBasic<T>, HttpInternalError>;

#[derive(Debug, Clone, JsonSchema)]
pub struct SResponseBasic<T> {
    pub body: Option<T>,
    #[schemars(skip)]
    pub status_code: Option<StatusCode>,
    pub msg: Option<String>,
}
impl<T> IntoResponse for SResponseBasic<T>
where
    T: Serialize + Clone + JsonSchema + Send,
{
    fn into_response(self) -> Response<Body> {
        let status_code = self.status_code.unwrap_or(StatusCode::OK);
        let response_data = SReponseStruct {
            success: status_code == StatusCode::OK,
            data: self.body,
            msg: self.msg.unwrap_or("success".to_string()),
        };
        Json(response_data).into_response()
    }
}
impl<T> OperationOutput for SResponseBasic<T>
where
    T: Serialize + Clone + Send + JsonSchema + 'static,
{
    type Inner = SResponseBasic<T>;
}



#[derive(Serialize, Deserialize, JsonSchema)]
pub struct HttpInternalError(String);
impl IntoResponse for HttpInternalError {
    fn into_response(self) -> Response {
        (StatusCode::INTERNAL_SERVER_ERROR, Json(self.0)).into_response()
    }
}
impl OperationOutput for HttpInternalError {
    type Inner = Infallible;
}

but empty was output

Image

SResponseBasic also implement IntoResponse

Activity

  1. joebnb commented on Oct 17, 2025

    @joebnb
    Author

    would any one give me some suggest, im stuck on this

  2. AstrickHarren commented on Oct 19, 2025

    @AstrickHarren

    I think you need to use get_with instead of get

  3. Repository owner locked and limited conversation to collaborators on Oct 20, 2025
  4. converted this issue into a discussion #249 on Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions