Decorate with multiple/chained parameters
See original GitHub issueI would like to add multiple parameters to an endpoint, essentially chaining them as so:
@api.parameters(SomeParameters())
@api.parameters(MoreParameters())
@api.parameters(EvenMoreParameters())
def get(self, args):
...
However, this results in a separate dict for each set of parameters and does not concatenate the arguments as I had expected. Also, Swagger does not seem to parse all of the argument options as only the topmost decorator appears in the docs.
I could simply create another Parameters class that combines all of the fields from the others, but I’d like to avoid having to create one for each desired combination of parameters.
Another idea I had was to create a method that would accept any number of Parameter objects and return a new dynamic Schema object with all of the combined fields. Something like:
@api.parameters(many_params(SomeParameters(), MoreParameters(), EvenMoreParameters()))
def get(self, args):
...
What is the recommended approach to accomplish this? I feel like I must be missing an easier way…
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
Top GitHub Comments
Here’s what I ended up going with:
And then you can simply put that callable in the decorate and pass in any number of parameter objects to it:
It’s somewhat crude and is definitely limited in handling more complex objects, but it serves my purpose for simple parameters with one or two fields (and it keeps Swagger happy too).
For anyone looking to do something similar, please feel free to improve/refine it!
I’m running across the same problem here. I’d like to add that it would be nice to be able to specify different locations for each set of parameters. Something like:
If I come up with anything I’ll drop it here.