Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.
This repository was 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

@seansylvan

Description

@seansylvan

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;
            }
          }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions