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

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

Closed
Fatal1ty opened this issue Aug 24, 2023 · 0 comments · Fixed by #159
Closed

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

Fatal1ty opened this issue Aug 24, 2023 · 0 comments · Fixed by #159
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Fatal1ty
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant