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

body parameter type should not include body as part of the structure #33

Open
seansylvan opened this issue Sep 13, 2014 · 0 comments
Open

Comments

@seansylvan
Copy link

for an API parameter definition:

"parameters": [
  {
      "name": "body",
      "dataType": "Data",
      "paramType": "body"
  }
]
...
"Data": {
    "id": "Data",
    "properties": {
        "a": {
          "type": "string"
        },
        "b":
        {
          "type": "string"
        }
}

the current implementation of the validator expects:

{"body": {"a": "xxx", "b": "yyy"}}

Instead of

{"a": "xxx", "b": "yyy"}}

This is incorrect according to Swagger 1.1 spec (and subsequent versions):

If paramType is body, the name is used only for UI and codegeneration.

Simple fixes are in validator.js

        case 'body':
          errPrefix = "body parameter " + spec.name;
          if (spec.name) {
            if (type === 'file') {
              value = (_ref1 = bodyContainer.files) != null ? _ref1[spec.name] : void 0;
              return done(!(value != null) && spec.schema.schema.required ? new Error("" + errPrefix + " is required") : void 0);
            } else {
              if (bodyContainer.body) {
//fix:
                value = bodyContainer.body;
//broken:  value = bodyContainer.body[spec.name];
              } else {
                value = void 0;
              }
            }
          } else {

and

        if (err != null) {
          err.message = "" + errPrefix + " " + (err.message.replace(/^JSON object /, ''));
        } else {
          if (spec.kind !== 'body') {
            input[spec.name] = value;
          } else {
 //fix:
           if (spec.name != null && spec.name !== 'body') {
//broken: if (spec.name != null) {
              bodyContainer.body[spec.name] = value;
            } else {
              bodyContainer.body = value;
            }
          }
        }
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

1 participant