Repository: Fatal1ty/mashumaro

Issue:
Allow customizing additionalProperties in jsonschemas
**Is your feature request related to a problem? Please describe.**
We have some classes for which we set additionalProperties=True in the jsonschema. Would it be possible to allow setting that in the embedded Config class?

**Describe the solution you'd like**
Also accept an additionalProperties key when the "properties" key is set from json_schema in the Config

**Describe alternatives you've considered**
Can set it directly in the jsonschema object, but we have a lot of nested classes so this gets messay.



Discussion:

Patch:
diff --git a/README.md b/README.md
index d1287b9..f6e11e6 100644
--- a/README.md
+++ b/README.md
@@ -2698,7 +2698,9 @@ Object constraints:
 ### Extending JSON Schema
 
 Using a `Config` class it is possible to override some parts of the schema.
-Currently, it works for dataclass fields via "properties" key:
+Currently, you can do the following:
+* override some field schemas using the "properties" key
+* change `additionalProperties` using the "additionalProperties" key
 
 ```python
 from dataclasses import dataclass
@@ -2716,7 +2718,8 @@ class FooBar:
                     "type": "string",
                     "description": "bar"
                 }
-            }
+            },
+            "additionalProperties": True,
         }
 
 print(build_json_schema(FooBar).to_json())
@@ -2738,7 +2741,7 @@ print(build_json_schema(FooBar).to_json())
             "type": "integer"
         }
     },
-    "additionalProperties": false,
+    "additionalProperties": true,
     "required": [
         "foo",
         "bar"
@@ -2747,6 +2750,9 @@ print(build_json_schema(FooBar).to_json())
 ```
 </details>
 
+You can also change the "additionalProperties" key to a specific schema
+by passing it a `JSONSchema` instance instead of a bool value.
+
 ### JSON Schema and custom serialization methods
 
 Mashumaro provides different ways to override default serialization methods for
diff --git a/mashumaro/jsonschema/schema.py b/mashumaro/jsonschema/schema.py
index 65c3ec3..9bce042 100644
--- a/mashumaro/jsonschema/schema.py
+++ b/mashumaro/jsonschema/schema.py
@@ -285,15 +285,16 @@ def override_field_instance_type_if_needed(
 def on_dataclass(instance: Instance, ctx: Context) -> Optional[JSONSchema]:
     # TODO: Self references might not work
     if is_dataclass(instance.origin_type):
+        jsonschema_config = instance.get_config().json_schema
         schema = JSONObjectSchema(
             title=instance.origin_type.__name__,
-            additionalProperties=False,
+            additionalProperties=jsonschema_config.get(
+                "additionalProperties", False
+            ),
         )
         properties: Dict[str, JSONSchema] = {}
         required = []
-        field_schema_overrides = instance.get_config().json_schema.get(
-            "properties", {}
-        )
+        field_schema_overrides = jsonschema_config.get("properties", {})
         for f_name, f_type, has_default, f_default in instance.fields():
             override = field_schema_overrides.get(f_name)
             f_instance = instance.copy(type=f_type, name=f_name)


Test patch:
diff --git a/tests/test_jsonschema/test_jsonschema_generation.py b/tests/test_jsonschema/test_jsonschema_generation.py
index 626f977..0b08833 100644
--- a/tests/test_jsonschema/test_jsonschema_generation.py
+++ b/tests/test_jsonschema/test_jsonschema_generation.py
@@ -1051,3 +1051,45 @@ def test_jsonschema_with_ref_prefix():
         .items.to_dict()
         == schema
     )
+
+
+def test_jsonschema_with_additional_properties_true():
+    @dataclass
+    class DataClass:
+        x: int
+
+        class Config(BaseConfig):
+            json_schema = {"additionalProperties": True}
+
+    schema = JSONObjectSchema(
+        title="DataClass",
+        properties={
+            "x": JSONSchema(type=JSONSchemaInstanceType.INTEGER),
+        },
+        additionalProperties=True,
+        required=["x"],
+    )
+    assert build_json_schema(DataClass) == schema
+
+
+def test_jsonschema_with_additional_properties_schema():
+    @dataclass
+    class DataClass:
+        x: int
+
+        class Config(BaseConfig):
+            json_schema = {
+                "additionalProperties": JSONSchema(
+                    type=JSONSchemaInstanceType.INTEGER
+                )
+            }
+
+    schema = JSONObjectSchema(
+        title="DataClass",
+        properties={
+            "x": JSONSchema(type=JSONSchemaInstanceType.INTEGER),
+        },
+        additionalProperties=JSONSchema(type=JSONSchemaInstanceType.INTEGER),
+        required=["x"],
+    )
+    assert build_json_schema(DataClass) == schema