OAI / OpenAPI-Specification

The OpenAPI Specification Repository
https://openapis.org
Apache License 2.0
28.94k stars 9.07k forks source link

Swagger Validation for File Downloads: Type: file is shown as response validation error #446

Closed Srithar-ccs closed 9 years ago

Srithar-ccs commented 9 years ago

Swagger Validation failed for ZIP File Download,

I am trying to write a file download API. It is a stream type for response but it is failing as "Response Validation failed"

My Yaml FIles is like this:

produces:
  - application/zip

/library/getacitemspackage:
  # This is the controller for getting the acitem and all its internal references as a deep package for the seamless delivery
    x-swagger-router-controller: library_get_acitems_package
    # this is a post method verb of the api service call
    post:
      summary: The API does the zip of all the given acitems and brings all the deep copy references packages from the cloud library
      description: The API does the zip of all the given acitems and brings all the deep copy references packages from the cloud library
      operationId: libraryGetAcitemsPackage
      parameters:
        - name: acitemsList
          in: body
          description: The list of all the acitems for which the package needs to be delivered as a zip
          schema:
            type: object
      responses:
        "200":
          description: Success
          schema:            
            type: file
        default:
          description: Error
          schema:
            $ref: "#/definitions/ErrorResponse"

My API code is like this :

            var archive = archiver('zip');          
            var totalAcitemListArray = totalAcitemList.toArray();           
            for (var index = 0; index < totalAcitemListArray.length; index++) {
                archive.append(fs.createReadStream(path.join(root_directory, totalAcitemListArray[index])), { name:totalAcitemListArray[index] });
            }           
            archive.finalize();
            archive.on('error', function(err) {
                response.status(500).send({error: err.message});
            });
            response.send('acitemsPackage.zip');            
            archive.pipe(response);
webron commented 9 years ago

You asked the same question in the google group, and should wait for an answer there. That said, it looks like the problem you're trying to solve is in swagger-node, so if you don't want to wait, open the issue there.

Srithar-ccs commented 9 years ago

I am sorry for being in a hurry webron, this is a very critical feature for my cloud design product, so thats why I am opened the issue here, is it fine if I open the issue in swagger-node ??

webron commented 9 years ago

You can, but I've forwarded your google group question to the relevant people and they'd reply if/when they can. You need to understand that this is an open source project (or rather projects) and people don't necessarily work within your time constraints. This is the weekend for most of the developers of the projects.

Srithar-ccs commented 9 years ago

Thanks a lot webron for being very kind in the reply. I very much appreciate you replying on this thread even in the weekend for this. I shall wait for the concerned team to revert on this. have a great day.

webron commented 9 years ago

Well, I said most. It's not the weekend for me ;) I wish I could help you with it myself, but unfortunately I have very little knowledge of that project specifically.

Srithar-ccs commented 9 years ago

Thanks a lot Webron. You guys are great :) . I am actually new to using swagger and I am using swagger-express-mw for the entire cloud service design. so thats why i just thought of bringing it to the notice of diff swagger-projects. But anyways thanks for the reply and once again have a great day :)

webron commented 9 years ago

Wait, which project exactly do you use? Do you know its github repository?

Srithar-ccs commented 9 years ago

{ "name": "Content_Library", "version": "0.0.1", "private": true, "description": "New Swagger API Project", "keywords": [], "author": "Sritharan Mahendra Babu", "license": "", "main": "app.js", "dependencies": { "angular-loading-bar": "^0.8.0", "app-root-path": "^1.0.0", "archiver": "^0.14.4", "body-parser": "~1.4.3", "collections": "^1.2.3", "express": "^4.12.3", "fast-csv": "^0.6.0", "fs-extra": "^0.22.1", "fuzzy": "^0.1.0", "gift": "^0.6.1", "method-override": "^2.3.4", "morgan": "~1.1.1", "node-dir": "^0.1.8", "nodegit": "^0.4.1", "request": "^2.61.0", "suppose": "^0.3.0", "swagger-express-mw": "0.0.x", "swagger-tools": "^0.8.7", "swagger-ui": "^2.1.1", "underscore": "^1.8.3" }, "devDependencies": { "should": "^5.2.0", "supertest": "^0.15.0" } }

https://github.com/BigstickCarpet/swagger-express-middleware

webron commented 9 years ago

In that case, that's not even one of our libraries. I thought you're using swagger-node which is ours.

If so, we can't really help with the error you're getting and you should open an issue on the swagger-express-middleware project instead. Sorry for assuming.

Srithar-ccs commented 9 years ago

oh, now i get it. i shall contact those developers for the errors. Thanks for pointing me out to the right direction. I think,the module which they are using should be outdated to the latest code base of yours. Thank you

webron commented 9 years ago

Yeah, it looks like they are based on some of our tools. They may redirect you to our projects if the problem is in the underlying tools, but they need to do the initial triaging.

Srithar-ccs commented 9 years ago

hmmm now i get it. Thanks a lot @webron Usually i dont get this quick and kind response :)

webron commented 9 years ago

Okay, I think I see the problem.

The file type issue has been resolved in swagger-tools 0.9.1, and it looks like the tool you use depends on an older version.

Srithar-ccs commented 9 years ago

quick thought, i might be stupid, can i just upgrade my swagger-tools to 0.9.1 in my package.json and try it out, or it might break other dependencies !!!!

webron commented 9 years ago

No idea, never used node.

Srithar-ccs commented 9 years ago

Ha Ha :) . I will try to upgrade the packages and use the actual swagger project and let me check it.

Srithar-ccs commented 9 years ago

Hi @webron Just Now i tried doing the same sequence of steps as mentioned in "https://github.com/swagger-api/swagger-node" and tried changing the YAML to send a zip file:

responses:
        "200":
          description: Success
          schema:
          type: file

It is throwing an error as :

API Errors:

  #/paths/~1hello/get/responses/200: Data does not match any schemas from 'oneOf'
    #/paths/~1hello/get/responses/200: Additional properties not allowed: type
    #/paths/~1hello/get/responses/200: Missing required property: $ref

I didnt do any changes i just installed the default swagger-node and ran it . It is throwing an error for the above YAML file change.

webron commented 9 years ago

If you look at swagger-node, you'll see it uses swagger-tools 0.9.0.

Srithar-ccs commented 9 years ago

so is the issue still there in swagger-node or has it been resolved!!! because i just did the 5 steps as mentioned in swagger-node site and just changes the YAML hello-world "response type"!!!!

webron commented 9 years ago

Looks like the issue is still there until the version of swagger-tools is updated.

Srithar-ccs commented 9 years ago

Great, Thanks Ron, You are awesome, without even rejected my thread you patiently attended my request. I very much appreciate your kindness. So I will raise a Issue ticket in the swagger-node for followup and i shall do the progress from there. Sorry for disturbing you at midnight. You have a great day.