Kaynağa Gözat

fix(config): exclude $schema from extra parameters sent to DNS APIs (#576)

* Initial plan

* fix(config): exclude $schema from extra parameters to prevent API errors

Co-authored-by: NewFuture <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: NewFuture <[email protected]>
Copilot 2 gün önce
ebeveyn
işleme
ae5e9d0dc8
2 değiştirilmiş dosya ile 22 ekleme ve 0 silme
  1. 1 0
      ddns/config/config.py
  2. 21 0
      tests/test_config_extra.py

+ 1 - 0
ddns/config/config.py

@@ -97,6 +97,7 @@ class Config(object):
             "debug",
             "config",
             "command",
+            "$schema",  # JSON schema reference, should not be sent to API
         }
 
         # dns related configurations

+ 21 - 0
tests/test_config_extra.py

@@ -163,6 +163,27 @@ class TestConfigExtra(unittest.TestCase):
         # Only custom field should be in extra
         self.assertEqual(config.extra.get("custom"), "custom_value")
 
+    def test_extra_does_not_include_schema_field(self):
+        """Test that $schema field from JSON config is not collected as extra"""
+        json_config = {
+            "$schema": "https://ddns.newfuture.cc/schema/v4.1.json",
+            "dns": "tencentcloud",
+            "id": "test_id",
+            "token": "test_token",
+            "ipv4": ["example.com"],
+            "extra": {
+                "proxied": True,
+            },
+        }
+        config = Config(json_config=json_config)
+        # $schema should not be in extra
+        self.assertNotIn("$schema", config.extra)
+        # Other extra fields should be collected
+        self.assertTrue(config.extra.get("proxied"))
+        # Known fields should be accessible
+        self.assertEqual(config.dns, "tencentcloud")
+        self.assertEqual(config.id, "test_id")
+
     def test_extra_with_json_extra_object_and_undefined_fields(self):
         """Test JSON config with both extra object and undefined fields"""
         json_config = {