Crates.io | poem_openapi_validator_derive |
lib.rs | poem_openapi_validator_derive |
version | 0.1.1 |
source | src |
created_at | 2022-01-12 15:56:55.378523 |
updated_at | 2022-01-12 16:58:12.365983 |
description | poem openapi validator |
homepage | https://github.com/tingfeng-key/poem_openapi_validator |
repository | https://github.com/tingfeng-key/poem_openapi_validator |
max_upload_size | |
id | 512854 |
size | 15,588 |
register.rs
use validator::Validate;
use poem_openapi::Object;
use poem_openapi_validator_derive::Validation;
#[derive(Object, Validate, Validation)]
pub struct Register {
#[validate(length(min = 6, max = 20, message = "user field length error"))]
pub username: String,
#[validate(length(min = 6, max = 20, message = "password field length error"))]
pub password: String,
}
auth.rs
use poem_openapi::{payload::PlainText, OpenApi};
use poem_openapi::payload::Json;
#[OpenApi]
impl Authorize {
#[oai(path="/register", method="post")]
async fn register(&self, register: Json<Register>) -> PlainText<String> {
//validator request
match register.validator_is_error() {
Some(error) => PlainText(error),
None => PlainText("ok".to_string())
}
}
}