Skip to content

Commit c9cc77f

Browse files
authored
Merge pull request #148 from fbacker/feature/override-server
Override server if provided at path
2 parents d969b9c + c7800ea commit c9cc77f

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

docs/specs/server-override.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
openapi: 3.0.2
2+
info:
3+
version: '1.0'
4+
title: Server Override
5+
description: For testing operation server override. Possible to list servers for specific operation that overrides default list.
6+
servers:
7+
- url: http://www.defaultserver.com
8+
paths:
9+
/simple:
10+
get:
11+
summary: Test override servers
12+
responses:
13+
'200':
14+
description: successful operation
15+
content:
16+
application/json:
17+
schema:
18+
type: string
19+
/simple-override:
20+
get:
21+
summary: Test override servers
22+
responses:
23+
'200':
24+
description: successful operation
25+
content:
26+
application/json:
27+
schema:
28+
type: string
29+
servers:
30+
- url: 'https://www.customserver1.com'
31+
- url: 'https://www.customserver2.com'

src/components/api-request.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default class ApiRequest extends LitElement {
2929
static get properties() {
3030
return {
3131
serverUrl: { type: String, attribute: 'server-url' },
32+
servers: { type: Array },
3233
method: { type: String },
3334
path: { type: String },
3435
parameters: { type: Array },
@@ -503,15 +504,20 @@ export default class ApiRequest extends LitElement {
503504
}
504505

505506
apiCallTemplate() {
507+
// use default server url, if multiple overrides exists show select
508+
let containerServer = this.serverUrl
509+
? html`${this.serverUrl}`
510+
: html`<div style="font-weight:bold;color:var(--red)">Not Set</div>`;
511+
if (this.servers && this.servers.length > 0) {
512+
const opts = this.servers.map((value) => html`<option value="${value.url}" selected="${value.url === this.serverUrl}" >${value.url}</option>`);
513+
containerServer = html`<select @change='${(e) => { this.serverUrl = e.target.value; }}'>${opts}</select>`;
514+
}
506515
return html`
507516
<div style="display:flex; align-items: center; margin:16px 0; font-size:var(--font-size-small);">
508517
<div style="display:flex; flex-direction:column; margin:0; width:calc(100% - 60px);">
509518
<div style="display:flex;flex-direction:row;overflow:hidden;">
510519
<div style="font-weight:bold;padding-right:5px;">API SERVER: </div>
511-
${this.serverUrl
512-
? html`${this.serverUrl}`
513-
: html`<div style="font-weight:bold;color:var(--red)">Not Set</div>`
514-
}
520+
${containerServer}
515521
</div>
516522
<div style="display:flex;">
517523
<div style="padding-right:5px;">Authentication: </div>

src/templates/endpoint-template.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function endpointBodyTemplate(path) {
4545
}
4646
accept = accept.replace(/,\s*$/, ''); // remove trailing comma
4747
const nonEmptyApiKeys = this.resolvedSpec.securitySchemes.filter((v) => (v.finalKeyValue)) || [];
48+
const selectedServer = path.servers && path.servers.length > 0 ? path.servers[0].uri : this.selectedServer.computedUrl;
4849
return html`
4950
<div class='endpoint-body ${path.method}'>
5051
${path.summary || path.description
@@ -68,7 +69,8 @@ function endpointBodyTemplate(path) {
6869
.parameters = "${path.parameters}"
6970
.request_body = "${path.requestBody}"
7071
.api_keys = "${nonEmptyApiKeys}"
71-
server-url = "${this.selectedServer.computedUrl}"
72+
.servers = "${path.servers}"
73+
server-url = "${selectedServer}"
7274
active-schema-tab = "${this.defaultSchemaTab}"
7375
allow-try = "${this.allowTry}"
7476
accept = "${accept}"

0 commit comments

Comments
 (0)