jmcarp / jmcarp/flask-apispec

Multiple schemas per-endpoint possible?

Open
#72 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
652
Forks
151
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.