forked from loafle/openapi-generator-original
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:
committed by
William Cheng
parent
9d3c1f2262
commit
305f78c52b
@@ -137,6 +137,7 @@
|
|||||||
}
|
}
|
||||||
var url = this.basePath + path;
|
var url = this.basePath + path;
|
||||||
|
|
||||||
|
|
||||||
// use API (operation, path) base path if defined
|
// use API (operation, path) base path if defined
|
||||||
if (apiBasePath !== null && apiBasePath !== undefined) {
|
if (apiBasePath !== null && apiBasePath !== undefined) {
|
||||||
url = apiBasePath + path;
|
url = apiBasePath + path;
|
||||||
@@ -664,7 +665,8 @@
|
|||||||
// go through variable and assign a value
|
// go through variable and assign a value
|
||||||
for (var variable_name in server['variables']) {
|
for (var variable_name in server['variables']) {
|
||||||
if (variable_name in 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]);
|
url = url.replace("{" + variable_name + "}", variables[variable_name]);
|
||||||
} else {
|
} 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'] + ".");
|
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'] + ".");
|
||||||
|
|||||||
@@ -645,7 +645,8 @@ class ApiClient {
|
|||||||
// go through variable and assign a value
|
// go through variable and assign a value
|
||||||
for (var variable_name in server['variables']) {
|
for (var variable_name in server['variables']) {
|
||||||
if (variable_name in 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]);
|
url = url.replace("{" + variable_name + "}", variables[variable_name]);
|
||||||
} else {
|
} 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'] + ".");
|
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'] + ".");
|
||||||
|
|||||||
@@ -576,7 +576,8 @@ class ApiClient {
|
|||||||
// go through variable and assign a value
|
// go through variable and assign a value
|
||||||
for (var variable_name in server['variables']) {
|
for (var variable_name in server['variables']) {
|
||||||
if (variable_name in 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]);
|
url = url.replace("{" + variable_name + "}", variables[variable_name]);
|
||||||
} else {
|
} 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'] + ".");
|
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'] + ".");
|
||||||
|
|||||||
@@ -575,7 +575,8 @@ class ApiClient {
|
|||||||
// go through variable and assign a value
|
// go through variable and assign a value
|
||||||
for (var variable_name in server['variables']) {
|
for (var variable_name in server['variables']) {
|
||||||
if (variable_name in 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]);
|
url = url.replace("{" + variable_name + "}", variables[variable_name]);
|
||||||
} else {
|
} 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'] + ".");
|
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'] + ".");
|
||||||
|
|||||||
@@ -136,6 +136,7 @@
|
|||||||
}
|
}
|
||||||
var url = this.basePath + path;
|
var url = this.basePath + path;
|
||||||
|
|
||||||
|
|
||||||
// use API (operation, path) base path if defined
|
// use API (operation, path) base path if defined
|
||||||
if (apiBasePath !== null && apiBasePath !== undefined) {
|
if (apiBasePath !== null && apiBasePath !== undefined) {
|
||||||
url = apiBasePath + path;
|
url = apiBasePath + path;
|
||||||
@@ -611,7 +612,8 @@
|
|||||||
// go through variable and assign a value
|
// go through variable and assign a value
|
||||||
for (var variable_name in server['variables']) {
|
for (var variable_name in server['variables']) {
|
||||||
if (variable_name in 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]);
|
url = url.replace("{" + variable_name + "}", variables[variable_name]);
|
||||||
} else {
|
} 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'] + ".");
|
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'] + ".");
|
||||||
|
|||||||
@@ -136,6 +136,7 @@
|
|||||||
}
|
}
|
||||||
var url = this.basePath + path;
|
var url = this.basePath + path;
|
||||||
|
|
||||||
|
|
||||||
// use API (operation, path) base path if defined
|
// use API (operation, path) base path if defined
|
||||||
if (apiBasePath !== null && apiBasePath !== undefined) {
|
if (apiBasePath !== null && apiBasePath !== undefined) {
|
||||||
url = apiBasePath + path;
|
url = apiBasePath + path;
|
||||||
@@ -622,7 +623,8 @@
|
|||||||
// go through variable and assign a value
|
// go through variable and assign a value
|
||||||
for (var variable_name in server['variables']) {
|
for (var variable_name in server['variables']) {
|
||||||
if (variable_name in 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]);
|
url = url.replace("{" + variable_name + "}", variables[variable_name]);
|
||||||
} else {
|
} 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'] + ".");
|
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'] + ".");
|
||||||
|
|||||||
Reference in New Issue
Block a user