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

Multiple schemas per-endpoint possible? #72

Open
revmischa opened this issue Nov 20, 2017 · 1 comment
Open

Multiple schemas per-endpoint possible? #72

revmischa opened this issue Nov 20, 2017 · 1 comment

Comments

@revmischa
Copy link

Our use case is that in a Resource View we want to return either a single item for GET /foo/pk or a list of items for GET /foo. Not only does one schema have many=True and the other doesn't, but often we have different fields in them because listing may use a stripped-down schema for efficiency.
Right now if we want to declare this in the documentation we have to use different status codes, which is obviously not ideal:

(permission checks etc removed):

    @marshal_with(Ref('_marshal_schema_class'), code=200)
    @marshal_with(Ref('_marshal_schema_class_multi'), code=201)
    def get(self, id):
        """Get single resource or list of resources."""
        if id:
            item = self._get(id)
            return item, 200
        else:
            return self._query_for_current_user().all(), 201

Is there some way to support both schemas for code 200?

@rth
Copy link
Contributor

rth commented Mar 13, 2019

It should be possible with oneOf, anyOf schemas (see related discussion in OAI/OpenAPI-Specification#270)

https://github.com/marshmallow-code/marshmallow-oneofschema might do what you are looking for.

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

2 participants