flask-restx icon indicating copy to clipboard operation
flask-restx copied to clipboard

How do I manually enforce Swagger UI to include a model's definition?

Open pinyiw opened this issue 4 years ago • 6 comments

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?

pinyiw avatar May 28 '20 01:05 pinyiw

This way worked for me: @api.doc(model=MyModel)

SDxKeeper avatar Jun 02 '20 14:06 SDxKeeper

@SDxKeeper Thanks for the comments. I'm trying to use list of MyModel though.

pinyiw avatar Jun 02 '20 18:06 pinyiw

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 avatar Jun 03 '20 10:06 SDxKeeper

@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?

pinyiw avatar Jun 07 '20 22:06 pinyiw

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).

pulseb avatar Dec 03 '20 13:12 pulseb

@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!

darrenchang avatar Dec 12 '23 10:12 darrenchang