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

Should dump_schema be an instance method of a schema? #6

Closed
fuhrysteve opened this issue Jan 1, 2016 · 0 comments
Closed

Should dump_schema be an instance method of a schema? #6

fuhrysteve opened this issue Jan 1, 2016 · 0 comments

Comments

@fuhrysteve
Copy link
Owner

We may want to avoid imposing a BaseJsonSchema (unless we use mixins, which also seem like something we should avoid unless there are compelling reasons to) since Marhmallow-sqlalchemy uses them and this library needs to be compatible with that library.

However, I'm struggling to think of another way to inject this functionality into marshmallow without doing something funky like monkey patching.

Maybe we could suggest a metaclass sort of plugin system in marshmallow?

Mixin style

from marshmallow_sqlalchemy import ModelSchema
from marshmallow_jsonschema import JSONSchemaMixin
from .models import Book  # some sqlalchemy model

class BookSchema(ModelSchema, JSONSchemaMixin):
    class Meta:
        model = Book

bs = BookSchema()
bs.jsonschema()

Metaclass "plugin" style

from marshmallow import register_plugin  # this doesn't actually exist
from marshmallow_jsonschema import JSONSchemaPlugin
register_plugin(JSONSchemaPlugin)

from marshmallow_sqlalchemy import ModelSchema
from .models import Book  # some sqlalchemy model

class BookSchema(ModelSchema):
    plugins = ['jsonschema']
    class Meta:
        model = Book

bs = BookSchema()
bs.jsonschema()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant