Fix Issue 4554 - handle 204 server response in javascript (#4604)

* issues 4554: Handle 204 response and handle deserialize exceptions

* issue-4554: generate javascript client updated template

Used petstore-with-fake-endpoints-models-for-testing.yaml

* use petstore-with-fake-endpoints-models-for-testing.yaml like sh script
This commit is contained in:
tharders 2017-01-23 08:14:06 +01:00 committed by wing328
parent 8e71dfb512
commit 30315c8570
3 changed files with 19 additions and 7 deletions

View File

@ -5,6 +5,6 @@ If Not Exist %executable% (
) )
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l javascript -o samples\client\petstore\javascript set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -l javascript -o samples\client\petstore\javascript
java %JAVA_OPTS% -jar %executable% %ags% java %JAVA_OPTS% -jar %executable% %ags%

View File

@ -311,7 +311,7 @@
* @returns A value of the specified type. * @returns A value of the specified type.
*/ */
{{/emitJSDoc}} exports.prototype.deserialize = function deserialize(response, returnType) { {{/emitJSDoc}} exports.prototype.deserialize = function deserialize(response, returnType) {
if (response == null || returnType == null) { if (response == null || returnType == null || response.status == 204) {
return null; return null;
} }
// Rely on SuperAgent for parsing response body. // Rely on SuperAgent for parsing response body.
@ -410,8 +410,12 @@
if (error) { if (error) {
reject(error); reject(error);
} else { } else {
var data = _this.deserialize(response, returnType); try {
resolve(data); var data = _this.deserialize(response, returnType);
resolve(data);
} catch (err) {
reject(err);
}
} }
}); });
});{{/usePromises}} });{{/usePromises}}
@ -419,7 +423,11 @@
if (callback) { if (callback) {
var data = null; var data = null;
if (!error) { if (!error) {
data = _this.deserialize(response, returnType); try {
data = _this.deserialize(response, returnType);
} catch (err) {
error = err;
}
} }
callback(error, data, response); callback(error, data, response);
} }

View File

@ -314,7 +314,7 @@
* @returns A value of the specified type. * @returns A value of the specified type.
*/ */
exports.prototype.deserialize = function deserialize(response, returnType) { exports.prototype.deserialize = function deserialize(response, returnType) {
if (response == null || returnType == null) { if (response == null || returnType == null || response.status == 204) {
return null; return null;
} }
// Rely on SuperAgent for parsing response body. // Rely on SuperAgent for parsing response body.
@ -413,7 +413,11 @@
if (callback) { if (callback) {
var data = null; var data = null;
if (!error) { if (!error) {
data = _this.deserialize(response, returnType); try {
data = _this.deserialize(response, returnType);
} catch (err) {
error = err;
}
} }
callback(error, data, response); callback(error, data, response);
} }