gitea_sdk_rs/options/
oauth2.rs1use crate::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct CreateOauth2Option {
12 pub name: String,
13 #[serde(rename = "confidential_client", default)]
14 pub confidential_client: bool,
15 #[serde(
16 rename = "redirect_uris",
17 default,
18 skip_serializing_if = "Vec::is_empty"
19 )]
20 pub redirect_uris: Vec<String>,
21}
22
23#[derive(Debug, Clone, Default)]
24pub struct ListOauth2Option {
26 pub list_options: crate::pagination::ListOptions,
27}
28
29impl crate::pagination::QueryEncode for ListOauth2Option {
30 fn query_encode(&self) -> String {
31 self.list_options.query_encode()
32 }
33}
34
35impl CreateOauth2Option {
36 pub fn validate(&self) -> crate::Result<()> {
38 if self.name.trim().is_empty() {
39 return Err(crate::Error::Validation("name is required".to_string()));
40 }
41 Ok(())
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_create_oauth2_option_validate_success() {
51 let opt = CreateOauth2Option {
52 name: "my-app".to_string(),
53 confidential_client: false,
54 redirect_uris: Vec::new(),
55 };
56 assert!(opt.validate().is_ok());
57 }
58
59 #[test]
60 fn test_create_oauth2_option_validate_empty_name() {
61 let opt = CreateOauth2Option {
62 name: String::new(),
63 confidential_client: false,
64 redirect_uris: Vec::new(),
65 };
66 assert!(opt.validate().is_err());
67 }
68}