flasgger-flask-swagger: request parameters not displayed in Webpage - flask

I want to create a REST API using flask. I also would like to document the api using swagger 2.0. This is the reason why I chose flasgger to create a webpage for the documentation. Right now the web page is rendered but the parameters for the request are not displayed, although I did add them in the yaml file.
I added the result of the webpage as image.
Part of the content of the yaml file can be seen in the other image.
In the main file I configured the Swagger object like in the image below.
I would be really thankful, if you could help find the reason why, I am not able to see those parameters.
Source code
documentation file
webpage result

you need to wrap your view with the decorator #swag_from("your_yaml_file_here")
for example:
from flasgger import swag_from
#app.route('/colors/<palette>/')
#swag_from('colors.yml')
def colors(palette):
....
If you do not want to use the decorator you can use the docstring file: shortcut.
#app.route('/colors/<palette>/')
def colors(palette):
"""
file: colors.yml
"""
...
Refer the link https://github.com/flasgger/flasgger to know more.

Related

How to get html page displayed in swagger UI (flask)

I have used apispec and flask-swagger-ui with flask.
The flask route returns a html page but on swagger UI I could only see the html code not the actual page.
Is there any way to get the html page displayed on swagger UI.
the flask code along with the APIspec documentation
swagger UI response
expected response
OpenAPI describes the text/code response your API will return. Swagger UI is correctly displaying the body of your response, not how that response will be interpreted and displayed by a particular consumer of your API (in this case a web browser). What you are trying to do is outside the intended scope of this tool. See this issue in which the developers rejected this idea for reasons of security.
Alternative:
Use the description property to include a link to additional documentation that includes images or screenshots of what this response would look like.

use django-rest-swagger 2 with custom swagger.json

I have a project build with django-rest-framework, and I want to use django-rest-swagger to get API documentation, so I made a swagger.json file via swagger editor, then my question is:
How can I make django-rest-swagger read and render my own swagger.json instead of auto-generated from code?
I've checked the django-rest-swagger doc over and over again but nothing found about that.
Any comment will be appreciated.
I know this is old post, but I ran into the same issue and wanted to provide my work around.
If you are trying to create a Swagger UI from an external JSON, this was my work around. I am using django but wanted to provide the swagger api of another framework and server. Here are two options:
The simplest solution is to just manually render the swagger html template and insert the endpoint url that provides the JSON inside SwaggerUi(), this is generally located in the last block.
Alternatively, if you cannot access the json directly or have a static file, create your own rest end point that either reads the file, or makes the request to the remote server, and then itself serves up the desired JSON. Reference this endpoint in your swagger template.

Use Google Docs Viewer to open document from rails app (paperclup, cloudfiles)

In our rails app we use paperclip to save files to rackspace cloudfiles. We want to allow users to VIEW the files without needing to download them and use a program on their computer. We have found https://docs.google.com/viewer which looks good for the job
We have the following method in the controller:
def view
att = Attachment.find(params[:id])
redirect_to "http://docs.google.com/viewer?url=#{CGI.escape(att.file.expiring_url((Time.now + 60.seconds)).gsub(/^http:/, "https:"))}"
end
This generates the following url:
https://drive.google.com/viewerng/viewer?url=https://snet-storage101.syd2.clouddrive.com/v1/MossoCloudFS_4a360775-1b68-41f9-884f-e62e7567af25/container//attachments/files/000/003/488/original/AK-_Time_Recording.pdf?temp_url_sig%3Dd36797290b85f2dcd752xxxxxxe6a08951ad%26temp_url_expires%3D14xxxxx7408&u=0
The google docs viewer then tells us:
Apologies, there is no preview available.
I suspect it has to do with the "temp_url_sig" and "temp_url_expires" parameters that are appended to the pdf file url.
Any ideas how we can get this to work?

How to begin creating a web application using a Python and xlrd/django script?

I'm not sure where to begin, as in do I start working towards PHP, Ruby or what, but here is what I'd like to do:
I have a Python script that takes a pre-formatted Excel document and using xlrd and Django, I output a nicely formatted HTML page, based on a template HTML page.
But currently on my team, I'm the only one that can use this Python script because our setups, and I'd like to simplify the process by creating a web app that has a couple drop down menus to specify which script to run, then let me upload the .xls file, at which point the HTML file is automatically generated and a download link is created or the HTML file is spit out somehow.
Does anyone have any guidance as to how I should even begin this project?
I would suggest having a good read of the django docs, and probably working through the tutorials.
Django's documentation is very good.
If you just want to hack at the code you've got then probably read the following to get a very basic overview of some core django functionality -
url dispatcher
views
models
forms
templating
With your app, the url dispatcher will pass the request to a view which will use a template to render your excel document.
You want a form to handle your user parameters and a single view to render and process the form and also render the excel template.

SOAP service in Django with soaplib

Hi I am looking to create a SOAP service within my Django App, but have come across a few hitches.
Firstly I have been able to successfully follow the soaplib Hello World tutorial (google "soaplib hello world" since I only can use 1 hyperlink as this is my first question) which uses a CheryPy WSGI server to run the service, and the soaplib client to initiate a SOAP request.
I am having trouble converting that into a service within Django through following this djangosnippets snippet. Currently I am using the Django development server.
Viewing http://localhost:8000/hello_world/ in the browser or making a SOAP request using the soaplib client returns a Django error page with the error:
Tried hello_world_service in module foo.views. Error was: 'module' object has no attribute 'hello_world_service'
Obviously urls.py is matching correctly, but according to that django snippet I linked to, there shouldn't be a view hello_world_service.
I feel I am missing the last step and any knowledge would be really helpful.
Thanks, Marcus
According to the snippet you link to, the bottom of your views.py file should contain the following line:
hello_world_service = HelloWorldService()
This maps an instance of the HelloWorldService class onto the name hello_world_service, for use in your urls.py file.
If that line is included, then there will indeed be a view with that name - so the URL Dispatcher should be able to find it.
Hope that does it,
Rob