Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DavidBiesack opened this issue Oct 8, 2014 · 2 comments

Comments

@DavidBiesack
Copy link

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
Copy link
Contributor

phairow commented Oct 8, 2014

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants