Fatal1ty / mashumaro

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

Third party default is not reflected in the generated JSON Schema #141

Closed Fatal1ty closed 1 year ago

Fatal1ty commented 1 year ago

Description

from dataclasses import dataclass
from mashumaro.config import BaseConfig
from mashumaro.jsonschema import build_json_schema

def as_str(value) -> str:
    return str(value)

class Bar:
    pass

@dataclass
class Foo:
    bar: Bar = Bar()

    class Config(BaseConfig):
        serialization_strategy = {
            Bar: {
                "serialize": as_str,
                "deserialize": Bar,
            }
        }

print(build_json_schema(Foo).to_json())

will raise an exception: mashumaro.exceptions.UnserializableField: Field "x" of type Bar in _default.<locals>.CC is not serializable

Expected:

{
    "type": "object",
    "title": "Foo",
    "properties": {
        "bar": {
            "type": "string",
            "default": "<__main__.Bar object at 0x1006e54d0>"
        }
    },
    "additionalProperties": false
}