Skip to content

#79 feat: parse validation attributes for OpenAPI constraints#87

Merged
RAprogramm merged 2 commits into78-doc-commentsfrom
79-validation-constraints
Jan 7, 2026
Merged

#79 feat: parse validation attributes for OpenAPI constraints#87
RAprogramm merged 2 commits into78-doc-commentsfrom
79-validation-constraints

Conversation

@RAprogramm
Copy link
Owner

Summary

  • Add validation.rs module for parsing #[validate(...)] attributes
  • Extract validation rules for conversion to OpenAPI schema constraints
  • Store raw attributes for passthrough to generated DTOs

Supported Validators

Validator OpenAPI Constraint
length(min = N) minLength: N
length(max = N) maxLength: N
range(min = N) minimum: N
range(max = N) maximum: N
email format: email
url format: uri
regex = "..." pattern: ...

Usage

#[derive(Entity)]
#[entity(table = "users")]
pub struct User {
    #[id]
    pub id: Uuid,
    
    #[validate(length(min = 1, max = 255))]
    #[validate(email)]
    #[field(create, update, response)]
    pub email: String,
    
    #[validate(range(min = 0, max = 150))]
    #[field(create, update, response)]
    pub age: i32,
}

Generated OpenAPI Schema

email:
  type: string
  minLength: 1
  maxLength: 255
  format: email
age:
  type: integer
  minimum: 0
  maximum: 150

Test plan

  • 8 unit tests for validation parsing
  • clippy clean
  • Format check
  • All 87 tests pass

Closes #79
Depends on #86

@RAprogramm RAprogramm force-pushed the 79-validation-constraints branch from e82799b to 2f306b7 Compare January 7, 2026 04:09
@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

❌ Patch coverage is 91.37056% with 17 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...y-derive-impl/src/entity/parse/field/validation.rs 94.14% 11 Missing ⚠️
...rates/entity-derive-impl/src/entity/parse/field.rs 33.33% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

- Add utils/docs.rs module for doc comment extraction
- Extract /// comments from entity struct for tag descriptions
- Extract /// comments from fields for schema descriptions
- Use entity doc as fallback for tag_description in OpenAPI
- 6 unit tests for doc extraction functions
- Add validation.rs module for #[validate(...)] parsing
- Support length(min, max), range(min, max), email, url, regex
- Generate OpenAPI schema constraints (minLength, maxLength, etc.)
- Store raw attrs for passthrough to generated DTOs
- 8 unit tests for validation parsing
@RAprogramm RAprogramm force-pushed the 79-validation-constraints branch from 2f306b7 to 0db154a Compare January 7, 2026 04:19
@RAprogramm RAprogramm changed the base branch from 78-doc-comments to dev January 7, 2026 04:19
@RAprogramm RAprogramm changed the base branch from dev to 78-doc-comments January 7, 2026 04:20
@RAprogramm RAprogramm merged commit 33501f3 into 78-doc-comments Jan 7, 2026
2 checks passed
@RAprogramm RAprogramm deleted the 79-validation-constraints branch January 7, 2026 04:23
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 this pull request may close these issues.

1 participant