This repository was archived by the owner on Dec 2, 2024. It is now read-only.
Description 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 ( / ^ J S O N o b j e c t / , '' ) ) ;
} 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 ;
}
}
}