Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant