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

Could not resolve reference: JSON Pointer evaluation failed while evaluating token "schemas" against an ObjectElement #1284

Open
codewithmecoder opened this issue Jan 10, 2025 · 0 comments

Comments

@codewithmecoder
Copy link

codewithmecoder commented Jan 10, 2025

I am using otoipa with actix and facing some issues

image

#[derive(OpenApi)]
#[openapi(
    paths(authHandler::login),
    components(schemas(
        LoginUserDto,
        UserLoginResponseDto,
        Response
    )),
    tags(
        (name = "Rust Authentication Api", description = "Authentication in Rust API")
    ),
    modifiers(&SecurityAddon)
)]
struct ApiDoc;

struct SecurityAddon;

impl Modify for SecurityAddon {
    fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
        openapi.components = Some(
            utoipa::openapi::ComponentsBuilder::new()
                .security_scheme(
                    "token",
                    SecurityScheme::Http(
                        HttpBuilder::new()
                            .scheme(HttpAuthScheme::Bearer)
                            .bearer_format("JWT")
                            .build(),
                    ),
                )
                .build(),
        )
    }
}

#[derive(Debug, Clone, Validate, Serialize, Deserialize, Default, ToSchema)]
pub struct LoginUserDto {
    #[validate(
        email(message = "Invalid email"),
        length(min = 1, message = "Email is required")
    )]
    pub email: String,

    #[validate(length(min = 1, message = "Password is required"))]
    pub password: String,
}

#[utoipa::path(
    post,
    path = "/api/auth/login",
    tag = "Login Endpoint",
    request_body(
        content = LoginUserDto, 
        description = "Credentials to log in to your account", 
        example = json!(
            {
                "email": "[email protected]",
                "password": "password123"
            })),
    responses(
        (
            status = 200, 
            description = "Login successfull", 
            body= UserLoginResponseDto 
        ),
        (
            status=400, 
            description= "Validation Errors", 
            body= Response
        ),
        (
            status=500, 
            description= "Internal Server Error", 
            body= Response
        ),
    )
)]
pub async fn login(
    app_state: web::Data<AppState>,
    body: web::Json<LoginUserDto>,
) -> Result<HttpResponse, HttpError> {
    ...
}
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

No branches or pull requests

1 participant