mashery / iodocs

Interactive API documentation system
MIT License
1.89k stars 415 forks source link

POST with Content-Type application/vnd.x+json does not send JSON body #213

Open DavidBiesack opened 10 years ago

DavidBiesack commented 10 years ago

If a method is defined as

 "batchMicroUrl" : {
                  "name" : "Batch create/update",
                  "description" : "Create or update a set of MicroUrls",
                  "httpMethod" : "POST",
                  "path" : "/microUrls",
                  "parameters" : {
                      "Content-Type" : {
                          "description" : "The media type of the request body",
                          "location" : "header",
                          "required" : true,
                          "title" : "Content-Type",
                          "type" : "string",
                          "enum" : [ "application/vnd.sas.mus+json" ]
                        }
                    },
                  "request" : { "$ref" : "MicroUrls" }
              },

where the request body is defined in the "schemas" section


  "schemas" : {
      "MicroUrl" : {
          "type" : "object",
          "properties" : {
              "description" : {
                  "description" : "The optional description or text label for the long URL.",
                  "required" : false,
                  "type" : "string"
              },
              "longUrl" : {
                  "description" : "The full URL this microUrl redirects to.",
                  "required" : true,
                  "type" : "string"
              },
              "owner" : {
                  "description" : "The owner of this microUrl instance (user id or email address, etc.).",
                  "required" : true,
                  "type" : "string"
              },
              "shortcut" : {
                  "description" : "The optional shortcut to use for this microUrl/",
                  "required" : false,
                  "type" : "string"
              }
          }
      },
      "MicroUrls" : {
          "type" : "array",
          "items" : { "$ref" : "MicroUrl" }
      }
  }

if Content-Type is application/vnd.sas.mus+json , I/O Docs will not send the request body as JSON. Rather, it encodes it as

MicroUrls=&MicroUrls=

(I added two objects and set their required member properties)

(unfortunately, I cannot add application/json here)

phairow commented 10 years ago

looks like it's hard-coded on line 669 of app.js if (['POST','PUT'].indexOf(httpMethod) !== -1) { var requestBody; requestBody = (options.headers['Content-Type'] === 'application/json') ? JSON.stringify(bodyParams) : query.stringify(bodyParams); } I think the structure of this part of the code needs some love.

hasmanyguitars commented 9 years ago

Thanks, @phairow. You saved me some digging. "Example #2" in the readme doesn't have that header, so it doesn't work either.