Fatal1ty / mashumaro

Fast and well tested serialization library
Apache License 2.0
774 stars 45 forks source link

Allow basic types used as serialization methods to be reflected in the JSON schema #148

Closed Fatal1ty closed 1 year ago

Fatal1ty commented 1 year ago

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:

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"]}
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.