Repository: Fatal1ty/mashumaro

Issue:
Allow basic types used as serialization methods to be reflected in the JSON schema
**Is your feature request related to a problem? Please describe.**

If we use basic types like `str`, `int`, `float`, `bool` as a serialization method, the generated JSON Schema will use `Any` because they don't have signature:

```python
from dataclasses import dataclass
from yarl import URL
from mashumaro.config import BaseConfig
from mashumaro.jsonschema import build_json_schema


@dataclass
class Foo:
    bar: URL

    class Config(BaseConfig):
        serialization_strategy = {
            URL: {
                "serialize": str
            }
        }


print(build_json_schema(Foo).to_json())
# {"type":"object","title":"Foo","properties":{"bar":{}},"additionalProperties":false,"required":["bar"]}
```

```python
UserWarning: Type Any will be used for __main__.Foo.bar with overridden serialization method: no signature found for builtin type <class 'str'>
```

**Describe the solution you'd like**
Treat `str`, `int`, `float`, `bool` types as functions returning the same type.


Discussion:

Patch:
diff --git a/mashumaro/jsonschema/schema.py b/mashumaro/jsonschema/schema.py
index 35a82b0..44f29ae 100644
--- a/mashumaro/jsonschema/schema.py
+++ b/mashumaro/jsonschema/schema.py
@@ -282,6 +282,9 @@ Registry = InstanceSchemaCreatorRegistry()
 register = Registry.register
 
 
+BASIC_TYPES = {str, int, float, bool}
+
+
 @register
 def on_type_with_overridden_serialization(
     instance: Instance, ctx: Context
@@ -301,6 +304,8 @@ def on_type_with_overridden_serialization(
     overridden_method = instance.get_overridden_serialization_method()
     if overridden_method is pass_through:
         return None
+    elif overridden_method in BASIC_TYPES:
+        instance.update_type(overridden_method)  # type: ignore
     elif callable(overridden_method):
         try:
             new_type = get_function_return_annotation(overridden_method)


Test patch:
diff --git a/tests/test_jsonschema/test_jsonschema_generation.py b/tests/test_jsonschema/test_jsonschema_generation.py
index 659325e..964bdd6 100644
--- a/tests/test_jsonschema/test_jsonschema_generation.py
+++ b/tests/test_jsonschema/test_jsonschema_generation.py
@@ -1019,6 +1019,36 @@ def test_overridden_serialization_method_with_return_annotation():
     )
 
 
+@pytest.mark.parametrize(
+    ("basic_type", "schema_type"),
+    (
+        (str, JSONSchemaInstanceType.STRING),
+        (int, JSONSchemaInstanceType.INTEGER),
+        (float, JSONSchemaInstanceType.NUMBER),
+        (bool, JSONSchemaInstanceType.BOOLEAN),
+    ),
+)
+def test_basic_type_as_overridden_serialization_method(
+    basic_type, schema_type
+):
+    @dataclass
+    class DataClass:
+        x: ThirdPartyType
+        y: List[ThirdPartyType]
+
+        class Config(BaseConfig):
+            serialization_strategy = {
+                ThirdPartyType: {"serialize": basic_type}
+            }
+
+    assert build_json_schema(DataClass).properties["x"] == JSONSchema(
+        type=schema_type
+    )
+    assert build_json_schema(DataClass).properties["y"] == JSONArraySchema(
+        items=JSONSchema(type=schema_type)
+    )
+
+
 def test_dataclass_overridden_serialization_method():
     def serialize_as_str(value: Any) -> str:
         return str(value)  # pragma no cover