Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Fatal1ty opened this issue Aug 21, 2023 · 0 comments · Fixed by #142
Closed

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

Fatal1ty opened this issue Aug 21, 2023 · 0 comments · Fixed by #142
Assignees
Labels
bug Something isn't working

Comments

@Fatal1ty
Copy link
Owner

  • mashumaro version: 3.9
  • Python version: 3.11
  • Operating System: MacOS 3.13.1

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
}
@Fatal1ty Fatal1ty added the bug Something isn't working label Aug 21, 2023
@Fatal1ty Fatal1ty self-assigned this Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant