ng-openapi-gen
ng-openapi-gen copied to clipboard
Support selection of Server Variables
OpenApi 3.1 allows a Server Variable Object like:
{
"servers": [
{
"url": "https://{username}.gigantic-server.com:{port}/{basePath}",
"description": "The production API server",
"variables": {
"username": {
"default": "demo",
"description": "this value is assigned by the service provider, in this example `gigantic-server.com`"
},
"port": {
"enum": [
"8443",
"443"
],
"default": "8443"
},
"basePath": {
"default": "v2"
}
}
}
]
}
ng-openapi-gen
only uses the provided default values:
private readRootUrl() {
if (!this.openApi.servers || this.openApi.servers.length === 0) {
return '';
}
const server = this.openApi.servers[0];
let rootUrl = server.url;
if (rootUrl == null || rootUrl.length === 0) {
return '';
}
const vars = server.variables || {};
for (const key of Object.keys(vars)) {
const value = String(vars[key].default);
rootUrl = rootUrl.replace(`{${key}}`, value);
}
return rootUrl;
}
It would be great if users can provide values for the variables