Skip to content

feat(api): security configuration for endpoints #81

@RAprogramm

Description

@RAprogramm

Summary

Configure authentication requirements for API endpoints.

Parent Issue

Part of #75

Syntax

Entity-level default

#[entity(api(
    security = "bearer",              // Default for all endpoints
    public = [Register, Login],       // Exceptions (no auth required)
))]

Command-level override

#[command(AdminDelete, security = "admin")]  // Requires admin role
#[command(PublicList, security = "none")]    // No auth

Security Schemes

// In OpenApi derive
security_schemes(
    ("bearer" = (ty = "http", scheme = "bearer", bearer_format = "JWT")),
    ("api_key" = (ty = "apiKey", in = "header", name = "X-API-Key")),
    ("admin" = (ty = "http", scheme = "bearer", bearer_format = "JWT")),
)

Generated Code

#[utoipa::path(
    // ...
    security(
        ("bearer" = [])
    ),
)]
async fn update_user(...) { ... }

#[utoipa::path(
    // ... no security for public endpoints
)]
async fn register_user(...) { ... }

Implementation

  1. Parse security attributes
  2. Generate security requirements per endpoint
  3. Support predefined schemes: bearer, api_key, oauth2

Files to Modify

  • crates/entity-derive-impl/src/entity/parse.rs
  • crates/entity-derive-impl/src/entity/api.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiAPI generation and documentationenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions