Open csachot opened 7 years ago
It looks like the request/response validation needs to be updated to not happen for application/xml
. For JSON and JavaScript primitives describable via Swagger, it will work but anything else will likely fail as you're seeing. I'll get it sorted.
Hi guys. I'm trying to use an application/xml request body to post some data. I tested the "pet store api" from swagger.io : http://petstore.swagger.io/. It all works fins with xml body.
I downloaded the generated nodejs server from swagger-api github : https://github.com/swagger-api/swagger-codegen/tree/master/samples/server/petstore/nodejs.
When i launch it and execute the same request with application/xml body data, i got the following error (with debug enabled) : Error: Parameter (body) failed schema validation at throwErrorWithCode
swagger-tools:middleware:validator POST /v2/pet +1ms swagger-tools:middleware:validator Will process: yes +1ms swagger-tools:middleware:validator Request validation: +0ms swagger-tools:middleware:validator Validation: failed +5ms swagger-tools:middleware:validator Reason: Failed schema validation +7ms swagger-tools:middleware:validator Errors: +1ms swagger-tools:middleware:validator 0: +1ms swagger-tools:middleware:validator code: OBJECT_MISSING_REQUIRED_PROPERTY +1ms swagger-tools:middleware:validator message: Missing required property: photoUrls +1ms swagger-tools:middleware:validator path: [] +0ms swagger-tools:middleware:validator 1: +1ms swagger-tools:middleware:validator code: OBJECT_MISSING_REQUIRED_PROPERTY +1ms swagger-tools:middleware:validator message: Missing required property: name +0ms swagger-tools:middleware:validator path: [] +1ms swagger-tools:middleware:validator Stack: +1ms swagger-tools:middleware:validator at throwErrorWithCode (D:\Users\csachot\Desktop\nodejs\node_modules\swagger-tools\lib\validators.js:121:13) +1ms swagger-tools:middleware:validator at Object.module.exports.validateAgainstSchema (D:\Users\csachot\Desktop\nodejs\node_modules\swagger-tools\lib\valid ators.js:176:7) +1ms swagger-tools:middleware:validator at D:\Users\csachot\Desktop\nodejs\node_modules\swagger-tools\middleware\swagger-validator.js:143:22 +0ms swagger-tools:middleware:validator at D:\Users\csachot\Desktop\nodejs\node_modules\async\lib\async.js:356:13 +1ms swagger-tools:middleware:validator at async.forEachOf.async.eachOf (D:\Users\csachot\Desktop\nodejs\node_modules\async\lib\async.js:233:13) +0ms swagger-tools:middleware:validator at _asyncMap (D:\Users\csachot\Desktop\nodejs\node_modules\async\lib\async.js:355:9) +0ms swagger-tools:middleware:validator at Object.map (D:\Users\csachot\Desktop\nodejs\node_modules\async\lib\async.js:337:20) +1ms swagger-tools:middleware:validator at validateValue (D:\Users\csachot\Desktop\nodejs\node_modules\swagger-tools\middleware\swagger-validator.js:136:11) +0ms swagger-tools:middleware:validator at D:\Users\csachot\Desktop\nodejs\node_modules\swagger-tools\middleware\swagger-validator.js:343:21 +1ms swagger-tools:middleware:validator at D:\Users\csachot\Desktop\nodejs\node_modules\async\lib\async.js:356:13 +1ms Error: Parameter (body) failed schema validation at throwErrorWithCode (D:\Users\csachot\Desktop\nodejs\node_modules\swagger-tools\lib\validators.js:121:13) at Object.module.exports.validateAgainstSchema (D:\Users\csachot\Desktop\nodejs\node_modules\swagger-tools\lib\validators.js:176:7) at D:\Users\csachot\Desktop\nodejs\node_modules\swagger-tools\middleware\swagger-validator.js:143:22 at D:\Users\csachot\Desktop\nodejs\node_modules\async\lib\async.js:356:13 at async.forEachOf.async.eachOf (D:\Users\csachot\Desktop\nodejs\node_modules\async\lib\async.js:233:13) at _asyncMap (D:\Users\csachot\Desktop\nodejs\node_modules\async\lib\async.js:355:9) at Object.map (D:\Users\csachot\Desktop\nodejs\node_modules\async\lib\async.js:337:20) at validateValue (D:\Users\csachot\Desktop\nodejs\node_modules\swagger-tools\middleware\swagger-validator.js:136:11) at D:\Users\csachot\Desktop\nodejs\node_modules\swagger-tools\middleware\swagger-validator.js:343:21 at D:\Users\csachot\Desktop\nodejs\node_modules\async\lib\async.js:356:13
My request :
curl -X POST "http://localhost:8080/v2/pet" -H "accept: application/xml" -H "content-type: application/xml" -d "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Pet>\t<id>0</id>\t<Category>\t\t<id>0</id>\t\t<name>string</name>\t</Category>\t<name>doggie</name>\t<photoUrl>\t\t<photoUrl>string</photoUrl>\t</photoUrl>\t<tag>\t\t<Tag>\t\t\t<id>0</id>\t\t\t<name>string</name>\t\t</Tag>\t</tag>\t<status>available</status></Pet>"