flask-restx
flask-restx copied to clipboard
How do I manually enforce Swagger UI to include a model's definition?
It seems like using list response with nested model mentioned here #65 doesn't automatically add the definition of the model. As a result, I got an error saying "Could not resolve reference: Could not resolve pointer: /definitions/MyModel does not exist in document" at the Swagger UI page.
@api.response(200, '', fields.List(fields.Nested(MyModel))
Can someone help me with this?
This way worked for me:
@api.doc(model=MyModel)
@SDxKeeper Thanks for the comments. I'm trying to use list of MyModel
though.
I was too fast yesterday, actually api.doc(model=MyModel) replaced definition of list.
I've been struggling with correct solution for list of models for few hours, but the only possible way to generate appropriate swagger doc I found was
@api.marshal_list_with(model)
All other recommended in doc ways: to use model defined in namespace, root api didn't work for me
@SDxKeeper I see. I do know that one way to specify that you are expecting a list of model is @api.response(200, 'Success', [my_model])
. Have you tried this?
Just to confirm that @api.response(200, 'Success', [my_model])
works for me, but I didn't get to work with @api.marshal_list_with(my_model)
.
@SDxKeeper I see. I do know that one way to specify that you are expecting a list of model is
@api.response(200, 'Success', [my_model])
. Have you tried this?
This method worked for me too! Awesome!