JS Client - Add support for empty enum in server object (#2853)

* Add support for empty enum in server object

* Updated samples
This commit is contained in:
Jonas DOREL
2019-05-13 08:21:43 +02:00
committed by William Cheng
parent 9d3c1f2262
commit 305f78c52b
6 changed files with 15 additions and 6 deletions

View File

@@ -136,6 +136,7 @@
}
var url = this.basePath + path;
// use API (operation, path) base path if defined
if (apiBasePath !== null && apiBasePath !== undefined) {
url = apiBasePath + path;
@@ -611,7 +612,8 @@
// go through variable and assign a value
for (var variable_name in server['variables']) {
if (variable_name in variables) {
if (server['variables'][variable_name]['enum_values'].includes(variables[variable_name])) {
let variable = server['variables'][variable_name];
if ( !('enum_values' in variable) || variable['enum_values'].includes(variables[variable_name]) ) {
url = url.replace("{" + variable_name + "}", variables[variable_name]);
} else {
throw new Error("The variable `" + variable_name + "` in the host URL has invalid value " + variables[variable_name] + ". Must be " + server['variables'][variable_name]['enum_values'] + ".");