Contributions
Swagger OpenAPI3 POST Array of images and media file together
I am using the swagger python-flask framework to create an OpenAPI 3 API which needs to do the following: 1. Upload a video file 2. Upload an array of images 3. Upload extra string data. I can successfully upload a single file successfully using: MyFileUploadAPI: post: operationId: my_file_upload requestBody: content: multipart/form-data: schema: $ref: '#/components/schemas/videofile' components: schemas: videofile: type: object properties: upload: type: string format: binary # This works fine def my_file_upload(videofile): file_name = videofile.filename And I can upload an array of images and other data using: MyMultipleImagesUploadAPI: post: operationId: multiple_files requestBody: content: application/json: schema: $ref: '#/components/schemas/multiplefiles' components: schemas: multiplefiles: type: object properties: Images: items: $ref: '#/components/schemas/MyImage' TotalCount: type: integer # This works fine def multiple_files(body): if connexion.request.is_json: body = multiplefiles.from_dict(connexion.request.get_json()) images = body._images count = body._totalcount Now I wish to combine the two together (Video upload + Multiple images + extra data) So I have did the following: /MyEverythingAPI: post: operationId: video_multiple_images requestBody: content: multipart/form-data: schema: $ref: '#/components/schemas/everything' components: schemas: everything: type: object properties: Video: type: string format: binary Images: type: array items: $ref: '#/components/schemas/MyImage' TotalCount: type: integer # This has issues def video_multiple_images(body, video_clip, **kwargs): #body = {'images': ['[object File]'], 'totalcount': 2} uploaded_file_name = video_clip.filename Now there are 2 issues that I see that are just not correct: Issue 1. The video_clip was not getting passed through to the function video_multiple_images. I debugged and tracked it down and saw that it was not getting added because there were no **kwargs added to my function signature. When I added the**kwargs then the video file started to get passed through. This post helped me solve that part: https://github.com/zalando/connexion/pull/753/files I can live with this issue but would like to know why this is the case. Issue 2. The image array is coming through as [object File]''[Object File]'' etc. This post indicates that this is not supported in OpenAPI 3: In Swagger openapi v3.0.0, facing issue in multiple file uploads So how can I pass a video file + an array of images?1.3KViews0likes0CommentsSwagger Python Flask server sluggish over HTTPS
I have a swagger openapi v3 python flask generated REST API server. I have just added HTTPS support to it and have used a self signed cert as follows. CERTIFICATE_FILE = '/cert/server-cert.pem' KEY_FILE = '/cert/server-key.pem' def main(): app = connexion.App(__name__, specification_dir='./swagger/') app.app.json_encoder = encoder.JSONEncoder app.add_api('swagger.yaml', arguments={'title': 'My API'}, pythonic_params=True) CORS(app.app) app.run(port=8080, debug=True, ssl_context=(CERTIFICATE_FILE, KEY_FILE)) I assess the swagger UI as follows: https://10.190.111.23:8080/ui/ I notice that very often there is a very long rersponse time when the swagger UI loads in the web browser and lots of times it does not load at all and simply times out. If I do not use HTTPS then it loads fine every time. Why could this be?838Views0likes0Comments- 1.4KViews0likes0Comments
Flask OAuth2 Server
I am creating a REST API using Swagger based on the PetStore example. I am using the Python-Flask Generated Server. I need to use OAuth2 for authentication. From what I undeerstand I need to: 1. Implement a user database. 2. Log in with a registered user and return an Access Token. 3. Use this token with any subsequent API calls to access resources. I see examples where one uses e.g. FaceBook or Google to obtain the AccessToken but I want my server to handle everything. Are there any examples of a python OAuth2 Server that works with Swagger? When I test the online PetStore Editor:https://editor.swagger.io it directs me to this link: http://petstore.swagger.io/oauth/login.jsp which says: "You can find the source code to the server" but the link is broken :(1.4KViews0likes1CommentOpen API 3 Flask Server
Fromhttp://editor.swagger.io/withswagger 2.0I am able to selectGenerate Server-->python-flaskand generate a python server that I can deploy and use. BUT When I change to useOpenAPI v3by selectingEdit--> Convert to Open API 3I now no longer see the option to generate a python flask server. Is this implemented? If not will this be implemented in the future? Is there another way to do this?Solved1.8KViews0likes2CommentsUpload a file to server using NodeJS and Swagger
I want to upload a file to a server using Swagger. I have created the YAML to upload file as follows: /Upload: post: summary: Uploads a file. operationId: bulkUpload consumes: - multipart/form-data parameters: - in: formData name: upfile type: file description: The file to upload. responses: 200: description: "File Uploaded" x-swagger-router-controller: "Default" My DefaultService.js file contaians the function: var fs = require('fs'); exports.bulkUpload = function(args, res, next) { var stream = fs.createWriteStream("UploadedFile.txt"); stream.once('open', function () { stream.write('blah blah'); //works - writes 'blah blah' to file stream.write(JSON.stringify(args.upfile.value));//bombs out after a while stream.write(args.upfile); //does not work stream.write(args.upfile.value); //does not work stream.end(); }); res.setHeader('Content-Type', 'application/json'); res.statusCode = 200; res.end(JSON.stringify('File Uploaded')); } I want to upload the original file without having to create my own test file. How can I do this? You will see that I am trying to write the uploaded file to a test file "UploadedFile.txt". It is currently failing as you can see from my attempts.3.7KViews0likes0CommentsEnable swagger to listen on IP address instead of localhost.
I have installed Swagger Editor on my Ubuntu 16.04 OS by doing the following steps: 1. sudo apt-get install nodejs-legacy 2. git clone https://github.com/swagger-api/swagger-editor.git 3. sudo apt-get install npm 4. cd swagger-editor 5. npm start 6. I edited the APIs I wanted using Swagger Editor 7. I generated a NodeJS Server from Swagger Editor Menu 8. I extracted my server zip file and CD into it. 9. npm install connect 10. npm install swagger-tools 11. npm install js-yaml 12. node index.js <-- START MY SERVER Result is: me@ubuntu:~/Downloads/nodejs-server-server$ node index.js Your server is listening on port 8081 (http://localhost:8081) Swagger-ui is available on http://localhost:8081/docs Question:You see here that its listening only onlocalhost. How do I get the server to listen on the actual IP address of my Server e.g. 10.12.13.23 and not localhost? As I want to access it from another PC?1.8KViews0likes0Comments