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

Inheriting Schema models #18

Open
JoakimSoderberg opened this issue Jun 5, 2017 · 1 comment
Open

Inheriting Schema models #18

JoakimSoderberg opened this issue Jun 5, 2017 · 1 comment

Comments

@JoakimSoderberg
Copy link

Hello,

Is it possible in the Schema classes to inherit the properties from another class somehow?

The use case I have is that I have a bunch of different lists. All the lists share some common properties for pagination, the only thing that is different is the schema reference for the items in that list.

So what I would like is to reuse all those properties.

class ListModel(Schema):
    type = "object"
    properties = {
        "count": {
            "description": "The total number of items in the list",
            "type": "int"
        },
        "limit": {
            "description": "The number of items to show per page",
            "type": "int"
        },
        "offset": {
            "description": "Number of items to offset the pagination",
            "type": "int"
        }
        # "items" goes here in the inherited
    }

And then have multiple specific schemas for the different types:

class SomeListModel(ListModel):
    # properties should now get "items": SomeModel.array() added to it
@JoakimSoderberg
Copy link
Author

JoakimSoderberg commented Jun 5, 2017

Hmmm I mean I tried doing something like this:

class SomeListModel(Schema):
    type = "object"
    properties = dict_with_base_stuff.copy().update({"items": SomeModel.array()})

But I guess all that happens after the serialization is done. Because the result is just null in the output.

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