This is an automated email from the ASF dual-hosted git repository.

Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 5e6d5bb7f3 feat(bindings/cpp): generate DeleteOptions from core (#9366)
5e6d5bb7f3 is described below

commit 5e6d5bb7f3be07f8dc5a2baa895a23d1a435f9e1
Author: Chitral Verma <[email protected]>
AuthorDate: Sun Nov 29 17:49:25 2026 +0530

    feat(bindings/cpp): generate DeleteOptions from core (#9366)
    
    * feat(bindings/cpp): generate DeleteOptions from core
    
    Signed-off-by: Chitral Verma <[email protected]>
    
    * fixup! feat(bindings/cpp): generate DeleteOptions from core
    
    Open the generated DeleteOptions struct doc with a C++ note: C++ exposes
    only `version` and `recursive`, neither of which is a condition, and
    setting `version` without `delete_with_version` fails with `Unsupported`
    even for a missing path. The error paragraph's example becomes that
    observable `Unsupported`. Generation fails if the note stops naming an
    exposed member. The ListOptions and StatOptions output is unchanged.
    
    Signed-off-by: Chitral Verma <[email protected]>
    
    * chore: regenerate DeleteOptions docs from core
    
    Signed-off-by: Chitral Verma <[email protected]>
    
    * chore: regenerate DeleteOptions docs from core
    
    Signed-off-by: Chitral Verma <[email protected]>
    
    ---------
    
    Signed-off-by: Chitral Verma <[email protected]>
---
 bindings/cpp/include/data_structure.hpp      |   9 --
 bindings/cpp/include/options.hpp             |  50 +++++++
 bindings/cpp/src/lib.rs                      |  18 +--
 bindings/cpp/src/operator.cpp                |   7 +-
 bindings/cpp/src/options.rs                  |  21 +++
 bindings/cpp/src/options_test.rs             |  34 ++++-
 bindings/cpp/src/utils/options_converter.cpp |   7 +
 bindings/cpp/src/utils/options_converter.hpp |   1 +
 bindings/cpp/tests/options_test.cpp          |  97 +++++++++++++
 dev/src/generate/cpp.rs                      | 210 ++++++++++++++++++++++++---
 10 files changed, 398 insertions(+), 56 deletions(-)

diff --git a/bindings/cpp/include/data_structure.hpp 
b/bindings/cpp/include/data_structure.hpp
index 8c4a419731..080c5030df 100644
--- a/bindings/cpp/include/data_structure.hpp
+++ b/bindings/cpp/include/data_structure.hpp
@@ -148,13 +148,4 @@ struct RenameOptions {
   bool if_not_exists{false};
 };
 
-/**
- * @struct DeleteOptions
- * @brief Options for delete operations.
- */
-struct DeleteOptions {
-  std::optional<std::string> version;
-  bool recursive{false};
-};
-
 }  // namespace opendal
diff --git a/bindings/cpp/include/options.hpp b/bindings/cpp/include/options.hpp
index 2a92152f14..1a37065865 100644
--- a/bindings/cpp/include/options.hpp
+++ b/bindings/cpp/include/options.hpp
@@ -142,4 +142,54 @@ struct StatOptions {
   std::optional<std::string> override_content_disposition;
 };
 
+/**
+ * @struct DeleteOptions
+ * @brief Options for delete operations.
+ */
+/// C++ exposes only `version` and `recursive`. Neither is a condition, so the
+/// conditions below cannot be set from C++ yet. Setting `version` fails with
+/// `Unsupported` when the operator's 
`opendal::Capability::delete_with_version`
+/// is false, even if the path is missing.
+///
+/// Each condition checks the file currently stored at the delete path, and
+/// every condition must hold for the delete to proceed:
+///
+/// - A false condition fails the delete with `ConditionNotMatch`.
+/// - A condition the service does not advertise through its capability fails
+/// the delete with `Unsupported`; OpenDAL never silently drops a condition. A
+/// service that cannot preserve a combination of conditions also returns
+/// `Unsupported`.
+/// - A service-side conflict unrelated to these conditions surfaces as
+/// `Conflict`.
+///
+/// With valid, supported options, deleting a missing file remains a successful
+/// no-op once every condition holds.
+///
+/// See the conditional operation specification for the complete 
cross-operation
+/// contract.
+///
+/// When the operation fails with an error kind that these docs name, such as
+/// `Unsupported`, it throws a `std::exception` whose `what()` starts with that
+/// kind.
+struct DeleteOptions {
+  /// Delete the given version of the file instead of the current one.
+  ///
+  /// This selects which stored version the delete removes; it is not a
+  /// condition on the file.
+  ///
+  /// Check `opendal::Capability::delete_with_version` before using this 
option.
+  std::optional<std::string> version;
+  /// Whether to delete the target recursively.
+  ///
+  /// The default, `false`, deletes a single object. With `true`, a trailing
+  /// slash (for example, `"a/"`) scopes deletion to a directory and its
+  /// descendants across services. Prefix matching for paths without a trailing
+  /// slash is service-specific. On prefix-based services such as `memory`,
+  /// `"a"` also matches entries under `"ab/"`.
+  ///
+  /// With `true`, the operation returns `Unsupported` when the service does 
not
+  /// advertise `opendal::Capability::delete_with_recursive`.
+  bool recursive{false};
+};
+
 }  // namespace opendal
diff --git a/bindings/cpp/src/lib.rs b/bindings/cpp/src/lib.rs
index e480af586d..d509e65ea7 100644
--- a/bindings/cpp/src/lib.rs
+++ b/bindings/cpp/src/lib.rs
@@ -137,11 +137,6 @@ mod ffi {
         if_not_exists: bool,
     }
 
-    struct FfiDeleteOptions {
-        version: OptionalString,
-        recursive: bool,
-    }
-
     #[cxx_name = "SeekDir"]
     enum SeekFrom {
         Start = 0,
@@ -183,6 +178,8 @@ mod ffi {
         type FfiListOptions = crate::options::ffi::FfiListOptions;
         #[namespace = "opendal::ffi::options"]
         type FfiStatOptions = crate::options::ffi::FfiStatOptions;
+        #[namespace = "opendal::ffi::options"]
+        type FfiDeleteOptions = crate::options::ffi::FfiDeleteOptions;
     }
 
     extern "Rust" {
@@ -479,15 +476,6 @@ fn rename_options(opts: ffi::FfiRenameOptions) -> 
od::options::RenameOptions {
     }
 }
 
-fn delete_options(opts: ffi::FfiDeleteOptions) -> od::options::DeleteOptions {
-    od::options::DeleteOptions {
-        version: optional_string(opts.version),
-        recursive: opts.recursive,
-        if_match: None,
-        ..Default::default()
-    }
-}
-
 impl Operator {
     fn read(&self, path: &str) -> Result<Vec<u8>> {
         Ok(self.0.read(path)?.to_vec())
@@ -540,7 +528,7 @@ impl Operator {
     }
 
     fn remove_options(&self, path: &str, opts: ffi::FfiDeleteOptions) -> 
Result<()> {
-        Ok(self.0.delete_options(path, delete_options(opts))?)
+        Ok(self.0.delete_options(path, opts.into())?)
     }
 
     fn remove_all(&self, paths: Vec<String>) -> Result<()> {
diff --git a/bindings/cpp/src/operator.cpp b/bindings/cpp/src/operator.cpp
index 04985a987d..df36a5e3e1 100644
--- a/bindings/cpp/src/operator.cpp
+++ b/bindings/cpp/src/operator.cpp
@@ -160,11 +160,6 @@ ffi::FfiRenameOptions ToFfiOptions(const RenameOptions 
&options) {
   return ffi::FfiRenameOptions{options.if_not_exists};
 }
 
-ffi::FfiDeleteOptions ToFfiOptions(const DeleteOptions &options) {
-  return ffi::FfiDeleteOptions{ToFfiOptionalString(options.version),
-                               options.recursive};
-}
-
 const ffi::Operator &CheckedOperator(const ffi::Operator *op) {
   if (op == nullptr) {
     throw std::logic_error(
@@ -286,7 +281,7 @@ void Operator::Remove(std::string_view path) {
 
 void Operator::Remove(std::string_view path, const DeleteOptions &options) {
   CheckedOperator(operator_).remove_options(utils::rust_str(path),
-                                            ToFfiOptions(options));
+                                            utils::ToFfiOptions(options));
 }
 
 void Operator::RemoveAll(const std::vector<std::string> &paths) {
diff --git a/bindings/cpp/src/options.rs b/bindings/cpp/src/options.rs
index 499da4a14f..37202db974 100644
--- a/bindings/cpp/src/options.rs
+++ b/bindings/cpp/src/options.rs
@@ -58,6 +58,11 @@ pub mod ffi {
         override_cache_control: OptionalString,
         override_content_disposition: OptionalString,
     }
+
+    struct FfiDeleteOptions {
+        version: OptionalString,
+        recursive: bool,
+    }
 }
 
 fn optional_string(v: ffi::OptionalString) -> Option<String> {
@@ -117,3 +122,19 @@ impl TryFrom<ffi::FfiStatOptions> for 
opendal::options::StatOptions {
         })
     }
 }
+
+impl From<ffi::FfiDeleteOptions> for opendal::options::DeleteOptions {
+    fn from(opts: ffi::FfiDeleteOptions) -> Self {
+        Self {
+            version: optional_string(opts.version),
+            recursive: opts.recursive,
+            // Not exposed in C++ yet:
+            // - `if_match`
+            // - `if_none_match`
+            // - `if_version_match`
+            // - `if_version_not_match`
+            // - `if_not_changed`
+            ..Default::default()
+        }
+    }
+}
diff --git a/bindings/cpp/src/options_test.rs b/bindings/cpp/src/options_test.rs
index df923ee0ae..114c0ca61c 100644
--- a/bindings/cpp/src/options_test.rs
+++ b/bindings/cpp/src/options_test.rs
@@ -15,10 +15,11 @@
 // specific language governing permissions and limitations
 // under the License.
 
-//! The generated `ListOptions` and `StatOptions` conversions in `options.rs`
-//! carry every bridge field to the core field of the same name, and absent
-//! values stay absent.
+//! The generated `ListOptions`, `StatOptions`, and `DeleteOptions`
+//! conversions in `options.rs` carry every bridge field to the core field of
+//! the same name, and absent values stay absent.
 
+use opendal::options::DeleteOptions;
 use opendal::options::ListOptions;
 use opendal::options::StatOptions;
 use opendal::raw::Timestamp;
@@ -163,3 +164,30 @@ fn test_stat_options_reject_out_of_range_timestamps() {
         );
     }
 }
+
+#[test]
+fn test_delete_options_carry_every_field() {
+    let opts = ffi::FfiDeleteOptions {
+        version: bridge_string(Some("version")),
+        recursive: true,
+    };
+
+    // The conditions that C++ does not expose stay unset, as on `main`.
+    let expected = DeleteOptions {
+        version: Some("version".to_string()),
+        recursive: true,
+        ..Default::default()
+    };
+    assert_eq!(DeleteOptions::from(opts), expected);
+}
+
+#[test]
+fn test_delete_options_keep_absent_values_absent() {
+    // C++ sends a value behind `has_value == false`; it must not reach core.
+    let opts = ffi::FfiDeleteOptions {
+        version: bridge_string(None),
+        recursive: false,
+    };
+
+    assert_eq!(DeleteOptions::from(opts), DeleteOptions::default());
+}
diff --git a/bindings/cpp/src/utils/options_converter.cpp 
b/bindings/cpp/src/utils/options_converter.cpp
index 8c916f321a..ea186d02fa 100644
--- a/bindings/cpp/src/utils/options_converter.cpp
+++ b/bindings/cpp/src/utils/options_converter.cpp
@@ -98,4 +98,11 @@ ffi::options::FfiStatOptions ToFfiOptions(const StatOptions 
&options) {
   };
 }
 
+ffi::options::FfiDeleteOptions ToFfiOptions(const DeleteOptions &options) {
+  return ffi::options::FfiDeleteOptions{
+      ToFfiOptionalString(options.version),
+      options.recursive,
+  };
+}
+
 }  // namespace opendal::utils
diff --git a/bindings/cpp/src/utils/options_converter.hpp 
b/bindings/cpp/src/utils/options_converter.hpp
index d24f3f646d..884fe62153 100644
--- a/bindings/cpp/src/utils/options_converter.hpp
+++ b/bindings/cpp/src/utils/options_converter.hpp
@@ -29,5 +29,6 @@ namespace opendal::utils {
 
 ffi::options::FfiListOptions ToFfiOptions(const ListOptions &options);
 ffi::options::FfiStatOptions ToFfiOptions(const StatOptions &options);
+ffi::options::FfiDeleteOptions ToFfiOptions(const DeleteOptions &options);
 
 }  // namespace opendal::utils
diff --git a/bindings/cpp/tests/options_test.cpp 
b/bindings/cpp/tests/options_test.cpp
index f0cbc8aa30..ff2eebb578 100644
--- a/bindings/cpp/tests/options_test.cpp
+++ b/bindings/cpp/tests/options_test.cpp
@@ -223,3 +223,100 @@ TEST(OptionsTest, StatOptionsErrorsStartWithErrorKind) {
     }
   }
 }
+
+TEST(OptionsTest, DeleteOptionsPositionalInitializerReachesBridge) {
+  // Every member in the order `data_structure.hpp` declared them before
+  // `DeleteOptions` was generated.
+  const opendal::DeleteOptions options{
+      /*version=*/"version",
+      /*recursive=*/true,
+  };
+
+  const auto ffi = opendal::utils::ToFfiOptions(options);
+
+  EXPECT_TRUE(ffi.version.has_value);
+  EXPECT_EQ(std::string(ffi.version.value), "version");
+  EXPECT_TRUE(ffi.recursive);
+}
+
+TEST(OptionsTest, DeleteOptionsStructuredBindingsKeepMemberOrder) {
+  opendal::DeleteOptions options;
+  auto &[version, recursive] = options;
+
+  EXPECT_EQ(&version, &options.version);
+  EXPECT_EQ(&recursive, &options.recursive);
+}
+
+TEST(OptionsTest, DefaultDeleteOptionsReachBridgeAbsent) {
+  const opendal::DeleteOptions options;
+
+  const auto ffi = opendal::utils::ToFfiOptions(options);
+
+  EXPECT_FALSE(ffi.version.has_value);
+  EXPECT_FALSE(ffi.recursive);
+}
+
+TEST(OptionsTest, DeleteOptionsRecursiveScopesOnMemory) {
+  opendal::Operator op("memory");
+  const auto write_tree = [&] {
+    op.Write("a/x", "x");
+    op.Write("a/sub/y", "y");
+    op.Write("ab/z", "z");
+  };
+
+  // The default deletes a single object.
+  write_tree();
+  op.Remove("a/x", opendal::DeleteOptions{});
+  EXPECT_FALSE(op.Exists("a/x"));
+  EXPECT_TRUE(op.Exists("a/sub/y"));
+  EXPECT_TRUE(op.Exists("ab/z"));
+
+  // With a trailing slash, a recursive delete removes the directory and its
+  // descendants only.
+  write_tree();
+  opendal::DeleteOptions recursive;
+  recursive.recursive = true;
+  op.Remove("a/", recursive);
+  EXPECT_FALSE(op.Exists("a/x"));
+  EXPECT_FALSE(op.Exists("a/sub/y"));
+  EXPECT_TRUE(op.Exists("ab/z"));
+
+  // Without it, the memory service also matches entries under `ab/`.
+  write_tree();
+  op.Remove("a", recursive);
+  EXPECT_FALSE(op.Exists("a/x"));
+  EXPECT_FALSE(op.Exists("a/sub/y"));
+  EXPECT_FALSE(op.Exists("ab/z"));
+}
+
+TEST(OptionsTest, DeleteOptionsErrorsStartWithErrorKind) {
+  using ::testing::AllOf;
+  using ::testing::HasSubstr;
+  using ::testing::StartsWith;
+  using ::testing::ThrowsMessage;
+
+  opendal::Operator op("memory");
+  op.Write("delete_errors", "hello");
+
+  // With valid, supported options, deleting a missing file succeeds.
+  opendal::DeleteOptions recursive;
+  recursive.recursive = true;
+  for (const auto &options : {opendal::DeleteOptions{}, recursive}) {
+    EXPECT_NO_THROW(op.Remove("delete_errors_missing", options));
+    EXPECT_NO_THROW(op.Remove("delete_errors_missing/", options));
+  }
+
+  // The memory service does not advertise versioned deletes, so core rejects
+  // `version` before looking for the file, and the file stays.
+  ASSERT_FALSE(op.Info().delete_with_version);
+  opendal::DeleteOptions version;
+  version.version = "version";
+  for (const char *path : {"delete_errors", "delete_errors_missing"}) {
+    EXPECT_THAT([&] { op.Remove(path, version); },
+                ThrowsMessage<std::exception>(
+                    AllOf(StartsWith("Unsupported"),
+                          HasSubstr("with the arguments version."))))
+        << path;
+  }
+  EXPECT_TRUE(op.Exists("delete_errors"));
+}
diff --git a/dev/src/generate/cpp.rs b/dev/src/generate/cpp.rs
index ebd92e55a1..c42032791d 100644
--- a/dev/src/generate/cpp.rs
+++ b/dev/src/generate/cpp.rs
@@ -547,6 +547,11 @@ struct OptionsSpec {
     /// designated initializers, so this order is append-only. A core field
     /// that is not listed is not exposed in C++ and keeps its core default.
     fields: &'static [(&'static str, OptionKind)],
+    /// C++-specific paragraphs, in core's doc syntax, that open the struct
+    /// doc before core's details. They tell C++ callers when core's struct
+    /// doc describes options that C++ does not expose, and name every member
+    /// in `fields`.
+    cpp_doc: &'static [&'static str],
 }
 
 /// Options structs generated into `include/options.hpp`. The other options
@@ -565,6 +570,7 @@ const OPTIONS: &[OptionsSpec] = {
                 ("versions", Bool),
                 ("deleted", Bool),
             ],
+            cpp_doc: &[],
         },
         OptionsSpec {
             name: "StatOptions",
@@ -579,6 +585,21 @@ const OPTIONS: &[OptionsSpec] = {
                 ("override_cache_control", OptionString),
                 ("override_content_disposition", OptionString),
             ],
+            cpp_doc: &[],
+        },
+        OptionsSpec {
+            name: "DeleteOptions",
+            brief: "Options for delete operations.",
+            fields: &[("version", OptionString), ("recursive", Bool)],
+            // Core's struct doc is about delete conditions, which C++ does not
+            // expose yet. Opening with an error that C++ callers can observe
+            // also makes it the example of the error paragraph.
+            cpp_doc: &[
+                "C++ exposes only `version` and `recursive`. Neither is a 
condition, so the",
+                "conditions below cannot be set from C++ yet. Setting 
`version` fails with",
+                "[`ErrorKind::Unsupported`] when the operator's",
+                "[`Capability::delete_with_version`] is false, even if the 
path is missing.",
+            ],
         },
     ]
 };
@@ -778,18 +799,21 @@ fn option_doc_lines(doc: &[String], prefix: &str, names: 
&CppNames) -> Vec<Strin
 /// The doc of a public options struct after its `@brief` block.
 ///
 /// The released `@brief` replaces core's summary paragraph, so the doc is
-/// the rest of core's struct doc, rendered by `option_doc_lines`. When that
-/// doc or a member doc names an error kind, a last paragraph tells C++
-/// callers how such an error reaches them.
+/// `cpp_doc` followed by the rest of core's struct doc, both rendered by
+/// `option_doc_lines`. When that doc or a member doc names an error kind, a
+/// last paragraph tells C++ callers how such an error reaches them, with the
+/// first kind named as its example.
 fn struct_doc_lines(
+    cpp_doc: &[&str],
     core_doc: &[String],
     member_docs: &[&[String]],
     names: &CppNames,
 ) -> Vec<String> {
-    let details: Vec<String> = core_doc
+    let core_details = core_doc.iter().skip_while(|line| 
!line.trim().is_empty());
+    let details: Vec<String> = cpp_doc
         .iter()
-        .skip_while(|line| !line.trim().is_empty())
-        .cloned()
+        .map(|line| line.to_string())
+        .chain(core_details.cloned())
         .collect();
     let mut lines = option_doc_lines(&details, HPP_STRUCT_DOC_PREFIX, names);
     let docs = 
std::iter::once(details.as_slice()).chain(member_docs.iter().copied());
@@ -907,9 +931,10 @@ fn doxygen_text(text: &str) -> String {
 /// models.
 ///
 /// Fails if a listed struct or field is missing from core, because dropping it
-/// would silently break source compatibility, if a field is listed twice, or
-/// if a field's kind in core differs from its listed kind, because that would
-/// change the public C++ member type.
+/// would silently break source compatibility, if a field is listed twice, if
+/// a field's kind in core differs from its listed kind, because that would
+/// change the public C++ member type, or if a spec's `cpp_doc` does not name
+/// one of its fields, because the doc would then list stale members.
 fn options_models(
     parsed: &[core_options::OptionsStruct],
     specs: &[OptionsSpec],
@@ -947,6 +972,19 @@ fn options_models(
             members.push(option_member(spec.name, field, kind, names)?);
             member_docs.push(field.doc.as_slice());
         }
+        if !spec.cpp_doc.is_empty() {
+            let cpp_doc = spec.cpp_doc.join(" ");
+            if let Some((name, _)) = spec
+                .fields
+                .iter()
+                .find(|(name, _)| !cpp_doc.contains(&format!("`{name}`")))
+            {
+                bail!(
+                    "the C++ doc of `{}` does not name its member `{name}`",
+                    spec.name
+                );
+            }
+        }
         let unexposed: Vec<String> = core
             .fields
             .iter()
@@ -959,7 +997,7 @@ fn options_models(
             brief: spec.brief,
             fills_defaults: !unexposed.is_empty() || 
core.has_unmirrored_fields,
             fallible: members.iter().any(|m| m.fallible),
-            hpp_doc_lines: struct_doc_lines(&core.doc, &member_docs, names),
+            hpp_doc_lines: struct_doc_lines(spec.cpp_doc, &core.doc, 
&member_docs, names),
             members,
             unexposed,
         });
@@ -1147,8 +1185,9 @@ mod tests {
         assert!(err.contains("`cache_control` is missing from core"));
     }
 
-    /// `ListOptions` and `StatOptions` as 
`bindings/cpp/include/data_structure.hpp`
-    /// declared them on `main` before they were generated, copied verbatim.
+    /// `ListOptions`, `StatOptions`, and `DeleteOptions` as
+    /// `bindings/cpp/include/data_structure.hpp` declared them on `main` 
before
+    /// they were generated, copied verbatim.
     /// Callers depend on each member's name, type, default member initializer,
     /// and position. The generated header adds doc comments, which these texts
     /// omit.
@@ -1179,6 +1218,15 @@ struct StatOptions {
   std::optional<std::string> override_content_disposition;
 };"#;
 
+    const MAIN_DELETE_OPTIONS: &str = r#"/**
+ * @struct DeleteOptions
+ * @brief Options for delete operations.
+ */
+struct DeleteOptions {
+  std::optional<std::string> version;
+  bool recursive{false};
+};"#;
+
     fn core_names() -> CppNames {
         CppNames::parse(&workspace_dir()).expect("parse core names")
     }
@@ -1214,7 +1262,7 @@ struct StatOptions {
     fn test_rendered_options_header_keeps_main_declarations() {
         let header = rendered_options("bindings/cpp/include/options.hpp");
         let code = code_lines(&header);
-        for main in [MAIN_LIST_OPTIONS, MAIN_STAT_OPTIONS] {
+        for main in [MAIN_LIST_OPTIONS, MAIN_STAT_OPTIONS, 
MAIN_DELETE_OPTIONS] {
             assert!(
                 code.contains(&code_lines(main)),
                 "header no longer declares:\n{main}\n\nheader:\n{header}"
@@ -1223,7 +1271,7 @@ struct StatOptions {
             let head: String = main.lines().take(3).map(|l| 
format!("{l}\n")).collect();
             assert!(header.contains(&head), "header lacks:\n{head}");
         }
-        assert_eq!(header.matches("\nstruct ").count(), 2);
+        assert_eq!(header.matches("\nstruct ").count(), 3);
         assert!(header.contains("\n#include <chrono>\n"));
     }
 
@@ -1323,6 +1371,16 @@ struct StatOptions {
             .collect()
     }
 
+    /// C++-specific paragraphs, in core's doc syntax, that must open the doc
+    /// of each listed struct.
+    const CPP_NOTES: &[(&str, &str)] = &[(
+        "DeleteOptions",
+        "C++ exposes only `version` and `recursive`. Neither is a condition, 
so the
+conditions below cannot be set from C++ yet. Setting `version` fails with
+[`ErrorKind::Unsupported`] when the operator's
+[`Capability::delete_with_version`] is false, even if the path is missing.",
+    )];
+
     #[test]
     fn test_rendered_options_header_documents_members_with_core_docs() {
         let header = rendered_options("bindings/cpp/include/options.hpp");
@@ -1349,17 +1407,24 @@ struct StatOptions {
                 docs.push(core_doc.join(" "));
             }
 
-            // Core's struct doc after its summary, which the released
-            // `@brief` replaces, then how C++ callers see the first error
-            // kind that these docs name.
+            // The C++ note, then core's struct doc after its summary, which
+            // the released `@brief` replaces, then how C++ callers see the
+            // first error kind that these docs name.
+            let note: Vec<String> = CPP_NOTES
+                .iter()
+                .filter(|(name, _)| *name == spec.name)
+                .flat_map(|(_, note)| note.lines().map(String::from))
+                .collect();
             let details: Vec<String> = core
                 .doc
                 .iter()
                 .skip_while(|line| !line.trim().is_empty())
                 .cloned()
                 .collect();
-            let mut expected = expected_paragraphs(&details);
+            let mut expected = expected_paragraphs(&note);
+            expected.extend(expected_paragraphs(&details));
             docs.insert(0, details.join(" "));
+            docs.insert(0, note.join(" "));
             if let Some(first) = kind.captures(&docs.join(" ")) {
                 expected.push(format!(
                     "When the operation fails with an error kind that these 
docs name, such as \
@@ -1379,6 +1444,21 @@ struct StatOptions {
                 spec.name
             );
         }
+        // C++ cannot set a delete condition, so the example is the error that
+        // `version` raises.
+        assert_eq!(
+            paragraphs(
+                struct_comment(&header, "DeleteOptions")
+                    .iter()
+                    .map(String::as_str)
+            )
+            .last()
+            .map(String::as_str),
+            Some(
+                "When the operation fails with an error kind that these docs 
name, such as \
+                 `Unsupported`, it throws a `std::exception` whose `what()` 
starts with that kind."
+            )
+        );
         for rust in ["[`", "](", "crate::", "ErrorKind::", "`Capability::"] {
             assert!(!header.contains(rust), "header contains `{rust}`");
         }
@@ -1496,7 +1576,7 @@ struct StatOptions {
         .map(String::from);
         let member: &[String] = &["Fails with 
`ErrorKind::Unsupported`.".to_string()];
         assert_eq!(
-            struct_doc_lines(&doc, &[member], &names),
+            struct_doc_lines(&[], &doc, &[member], &names),
             [
                 "# Groups",
                 "- Pagination: `limit`, `start_after`.",
@@ -1514,14 +1594,49 @@ struct StatOptions {
         // and without any kind there is no note.
         let summary_only = ["Summary only.".to_string()];
         assert_eq!(
-            struct_doc_lines(&summary_only, &[&[], member], &names),
+            struct_doc_lines(&[], &summary_only, &[&[], member], &names),
+            [
+                "When the operation fails with an error kind that these docs 
name, such as",
+                "`Unsupported`, it throws a `std::exception` whose `what()` 
starts with that",
+                "kind.",
+            ]
+        );
+        assert!(struct_doc_lines(&[], &summary_only, &[&[]], 
&names).is_empty());
+
+        // A C++ note opens the doc, rendered like core's text, and the first
+        // kind it names becomes the example.
+        let note = [
+            "C++ exposes only `limit`. Setting it fails with",
+            "[`ErrorKind::Unsupported`] without 
[`Capability::list_with_limit`].",
+        ];
+        assert_eq!(
+            struct_doc_lines(&note, &doc, &[member], &names),
+            [
+                "C++ exposes only `limit`. Setting it fails with `Unsupported` 
without",
+                "`opendal::Capability::list_with_limit`.",
+                "",
+                "# Groups",
+                "- Pagination: `limit`, `start_after`.",
+                "- Versioning: `versions`, `deleted`.",
+                "",
+                "A missing file returns `NotFound`. See the specification for 
more.",
+                "",
+                "When the operation fails with an error kind that these docs 
name, such as",
+                "`Unsupported`, it throws a `std::exception` whose `what()` 
starts with that",
+                "kind.",
+            ]
+        );
+        assert_eq!(
+            struct_doc_lines(&note, &summary_only, &[&[]], &names),
             [
+                "C++ exposes only `limit`. Setting it fails with `Unsupported` 
without",
+                "`opendal::Capability::list_with_limit`.",
+                "",
                 "When the operation fails with an error kind that these docs 
name, such as",
                 "`Unsupported`, it throws a `std::exception` whose `what()` 
starts with that",
                 "kind.",
             ]
         );
-        assert!(struct_doc_lines(&summary_only, &[&[]], &names).is_empty());
     }
 
     #[test]
@@ -1556,15 +1671,25 @@ struct StatOptions {
     }
 
     #[test]
-    fn test_stat_options_convert_with_try_from() {
+    fn test_only_stat_options_convert_with_try_from() {
         let models = options_models(&parsed_options(), OPTIONS, 
&core_names()).unwrap();
         let fallible: Vec<(&str, bool)> = models.iter().map(|m| (m.name, 
m.fallible)).collect();
-        assert_eq!(fallible, [("ListOptions", false), ("StatOptions", true)]);
+        assert_eq!(
+            fallible,
+            [
+                ("ListOptions", false),
+                ("StatOptions", true),
+                ("DeleteOptions", false)
+            ]
+        );
 
         let rust = rendered_options("bindings/cpp/src/options.rs");
         assert!(
             rust.contains("impl From<ffi::FfiListOptions> for 
opendal::options::ListOptions {")
         );
+        assert!(
+            rust.contains("impl From<ffi::FfiDeleteOptions> for 
opendal::options::DeleteOptions {")
+        );
         assert!(rust.contains(
             "impl TryFrom<ffi::FfiStatOptions> for 
opendal::options::StatOptions {\n    type Error = opendal::Error;\n"
         ));
@@ -1583,6 +1708,7 @@ struct StatOptions {
                 name,
                 brief: "",
                 fields,
+                cpp_doc: &[],
             };
             options_models(&parsed, &[spec], &core_names())
                 .unwrap_err()
@@ -1623,6 +1749,18 @@ struct StatOptions {
                 OptionString,
                 "core `StatOptions::if_modified_since` has kind OptionString, 
but OPTIONS lists OptionTimestamp",
             ),
+            (
+                "DeleteOptions",
+                "recursive",
+                OptionString,
+                "core `DeleteOptions::recursive` has kind OptionString, but 
OPTIONS lists Bool",
+            ),
+            (
+                "DeleteOptions",
+                "version",
+                Bool,
+                "core `DeleteOptions::version` has kind Bool, but OPTIONS 
lists OptionString",
+            ),
         ] {
             let mut changed = parsed.clone();
             changed
@@ -1641,10 +1779,36 @@ struct StatOptions {
                 expected
             );
         }
+        let mut without_recursive = parsed.clone();
+        without_recursive
+            .iter_mut()
+            .find(|s| s.name == "DeleteOptions")
+            .unwrap()
+            .fields
+            .retain(|f| f.name != "recursive");
+        assert_eq!(
+            options_models(&without_recursive, OPTIONS, &core_names())
+                .unwrap_err()
+                .to_string(),
+            "OPTIONS member `DeleteOptions::recursive` is missing from core"
+        );
         assert_eq!(
             error("ReadOptions", &[("range", BytesRange)]),
             "the C++ bridge cannot carry `ReadOptions::range` of kind 
BytesRange yet"
         );
+        // A C++ note that no longer names every exposed member is stale.
+        let stale = OptionsSpec {
+            name: "DeleteOptions",
+            brief: "",
+            fields: &[("version", OptionString), ("recursive", Bool)],
+            cpp_doc: &["C++ exposes only `version`; `recursively` is not a 
member."],
+        };
+        assert_eq!(
+            options_models(&parsed, &[stale], &core_names())
+                .unwrap_err()
+                .to_string(),
+            "the C++ doc of `DeleteOptions` does not name its member 
`recursive`"
+        );
     }
 
     #[test]

Reply via email to