I am developing an API using flask-restplus. One of my endpoint returns a list of object, e.g.
[
{
"id": "1342",
"index": "meta",
"score": 3.0630198
},
{
"id": "1645",
"index": "meta",
"score": 3.0630198
},
{
"id": "2345",
"index": "meta",
"score": 3.0630198
}
]
Now I am trying to develop a model using fields so I can marshal it as a result of get, e.g
model = namespace.model('MyModel', {
"some_attribute":fields.List(fields.Nested(some_nested_object))
})
@namespace.route('')
class FlashcardAutocompleteAPI(Resource):
...
@namespace.marshal_with(model,code=200)
def get(self):
...
The above code of course works, but does not marshal the correct structure.
Is there any way to NOT declare the "some_attribute" part, such that the model would marshal the json structure as provided above? Trying this:
model = namespace.model('MyModel', {
fields.List(fields.Nested(some_nested_object))
})
I receive:
TypeError: cannot convert dictionary update sequence element #0 to a
sequence