Repository: LemmyNet/lemmy (language: rust)

Issue:
Get rid of `Option<Vec<...` in the API and code, and just use `Vec<`
I thought this made sense for clients, but it really just makes things more difficult because it requires two unwraps : 

- first checking the option, then 
- checking to make sure the list has items.

The first step isn't necessary, and you might as well just return an empty vector for missing items.


Discussion / hints:

Fix patch:
diff --git a/crates/api/src/site/leave_admin.rs b/crates/api/src/site/leave_admin.rs
index 40742a8191..bb306aeb91 100644
--- a/crates/api/src/site/leave_admin.rs
+++ b/crates/api/src/site/leave_admin.rs
@@ -69,8 +69,8 @@ pub async fn leave_admin(
     version: VERSION.to_string(),
     all_languages,
     discussion_languages,
-    oauth_providers: Some(oauth_providers),
-    admin_oauth_providers: None,
+    oauth_providers,
+    admin_oauth_providers: vec![],
     blocked_urls,
     tagline,
     my_user: None,
diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs
index c0b75e21fb..601aed5bd6 100644
--- a/crates/api_common/src/site.rs
+++ b/crates/api_common/src/site.rs
@@ -417,10 +417,8 @@ pub struct GetSiteResponse {
   #[cfg_attr(feature = "full", ts(optional))]
   pub tagline: Option<Tagline>,
   /// A list of external auth methods your site supports.
-  #[cfg_attr(feature = "full", ts(optional))]
-  pub oauth_providers: Option<Vec<PublicOAuthProvider>>,
-  #[cfg_attr(feature = "full", ts(optional))]
-  pub admin_oauth_providers: Option<Vec<OAuthProvider>>,
+  pub oauth_providers: Vec<PublicOAuthProvider>,
+  pub admin_oauth_providers: Vec<OAuthProvider>,
   pub blocked_urls: Vec<LocalSiteUrlBlocklist>,
   // If true then uploads for post images or markdown images are disabled. Only avatars, icons and
   // banners can be set.
diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs
index 8f3a08de13..f9b3c38692 100644
--- a/crates/api_crud/src/site/read.rs
+++ b/crates/api_crud/src/site/read.rs
@@ -39,7 +39,7 @@ pub async fn get_site_v4(
     .map(|l| l.local_user.admin)
     .unwrap_or_default()
   {
-    site_response.admin_oauth_providers = None;
+    site_response.admin_oauth_providers = vec![];
   }
 
   Ok(Json(site_response))
@@ -64,8 +64,8 @@ async fn read_site(context: &LemmyContext) -> LemmyResult<GetSiteResponse> {
     discussion_languages,
     blocked_urls,
     tagline,
-    oauth_providers: Some(oauth_providers),
-    admin_oauth_providers: Some(admin_oauth_providers),
+    oauth_providers,
+    admin_oauth_providers,
     image_upload_disabled: context.settings().pictrs()?.image_upload_disabled,
   })
 }


Test patch:
diff --git a/api_tests/package.json b/api_tests/package.json
index ea01a50463..9dd1b3ca6d 100644
--- a/api_tests/package.json
+++ b/api_tests/package.json
@@ -29,7 +29,7 @@
     "eslint": "^9.20.0",
     "eslint-plugin-prettier": "^5.2.3",
     "jest": "^29.5.0",
-    "lemmy-js-client": "0.20.0-show-mod-reports.2",
+    "lemmy-js-client": "0.20.0-api-no-optional-vec.1",
     "prettier": "^3.5.0",
     "ts-jest": "^29.1.0",
     "tsoa": "^6.6.0",
diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml
index c59cbee647..18028e46fd 100644
--- a/api_tests/pnpm-lock.yaml
+++ b/api_tests/pnpm-lock.yaml
@@ -33,8 +33,8 @@ importers:
         specifier: ^29.5.0
         version: 29.7.0(@types/node@22.13.1)
       lemmy-js-client:
-        specifier: 0.20.0-show-mod-reports.2
-        version: 0.20.0-show-mod-reports.2
+        specifier: 0.20.0-api-no-optional-vec.1
+        version: 0.20.0-api-no-optional-vec.1
       prettier:
         specifier: ^3.5.0
         version: 3.5.0
@@ -1528,8 +1528,8 @@ packages:
     resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==}
     engines: {node: '>=6'}
 
-  lemmy-js-client@0.20.0-show-mod-reports.2:
-    resolution: {integrity: sha512-92Zgs5/Nf8h57U5kgL0Q9BZzoTG0JUTGSGg1e9DORzQFVfYv53dzKpdjNxvuHsxlmT4eOeZgCuyUGdRipYy6jw==}
+  lemmy-js-client@0.20.0-api-no-optional-vec.1:
+    resolution: {integrity: sha512-oIlTCiriuZVzTMScix4ubJyIOf3x0FPpnxCfm12EYbiix3Z9D44XMWs3JTV+ipJgmiAqgAiGhI0fF35RNu3FjQ==}
 
   leven@3.1.0:
     resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==}
@@ -4169,7 +4169,7 @@ snapshots:
 
   kleur@3.0.3: {}
 
-  lemmy-js-client@0.20.0-show-mod-reports.2: {}
+  lemmy-js-client@0.20.0-api-no-optional-vec.1: {}
 
   leven@3.1.0: {}