Closed ivarflakstad-zz closed 6 years ago
I think you need to register the MIME type "application/javascript" ( check this http://flask-restful.readthedocs.io/en/0.3.5/extending.html ). I think the only MIME type supported by default by Swagger is "application/json". Look also in flask_restplus/api.py in the constructor: DEFAULT_REPRESENTATIONS = [('application/json', output_json)] self.representations = OrderedDict(DEFAULT_REPRESENTATIONS)
If that was the issue, why would it work with curl?
In your example code, the output is normal in Swagger, because if you look at the implementation: default_mediatype='application/json', decorators=None. The difference between Swagger in curl is exactly that :D , curl is not Swagger. Look at how Swagger creates the documentation (http://docs.swagger.io/spec.html) in 5.2.2.1 Object Example: { "apiVersion": "1.0.0", "swaggerVersion": "1.2", "basePath": "http://petstore.swagger.wordnik.com/api", "resourcePath": "/store", "produces": [ "application/json" ], Flask-rest+ changes the "produces" fields in the Swagger XML's based on the registered MIME representation. Curl does not temper with that. This is my opinion anyhow. Curl and Swagger are clients and behave differently.
Of course curl and swagger behave differently, was never any doubt about that. I did not know there was such an elaborate response content-type scheme in swagger, so I treated it as I would any other header. For the project I am working on, it would be much easier to do it the way I intended, but I can make it work like this as well. This solved my problem, thank you for the help! :+1:
Is it the using the @api.representation decorator you're referring to?
Consider this minimal-ish example:
Which results in the following bug in swagger:
The problem must be in swagger itself, right? Should I open a issue there?
It works great with curl: