Skip to content

Commit 317ee37

Browse files
committed
Improved path specific servers
1 parent fa35854 commit 317ee37

File tree

5 files changed

+44
-18
lines changed

5 files changed

+44
-18
lines changed

docs/specs/server-override.yaml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ info:
66
servers:
77
- url: http://www.defaultserver.com
88
paths:
9-
/simple:
9+
/global-api-server:
1010
get:
11-
summary: Test override servers
11+
summary: This path sends request to API servers defined at global level
1212
responses:
1313
'200':
1414
description: successful operation
1515
content:
1616
application/json:
1717
schema:
1818
type: string
19-
/simple-override:
19+
/path-specific-api-server:
2020
get:
21-
summary: Test override servers
21+
summary: This path sends request to API servers defined at Path level
2222
responses:
2323
'200':
2424
description: successful operation
@@ -27,5 +27,18 @@ paths:
2727
schema:
2828
type: string
2929
servers:
30-
- url: 'https://www.customserver1.com'
31-
- url: 'https://www.customserver2.com'
30+
- url: 'http://example.com/api'
31+
description: Test server
32+
- url: '/api'
33+
- url: '{protocol}://dev.com/api'
34+
description: Server with Variable
35+
variables:
36+
protocol:
37+
default: https
38+
description: >
39+
Server choices:
40+
* `http` Not Secured server
41+
* `https` Secured server
42+
enum:
43+
- http
44+
- https

src/components/api-request.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -505,19 +505,31 @@ export default class ApiRequest extends LitElement {
505505

506506
apiCallTemplate() {
507507
// 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>`;
508+
let selectedServerHtml = this.serverUrl
509+
? html`<div style="font-weight:bold;padding-right:5px;">API SERVER: </div> ${this.serverUrl}`
510+
: html`<div style="font-weight:bold;color:var(--red)">NO API Server Selected</div>`;
511+
511512
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>`;
513+
// this.serverUrl = this.servers[0].url;
514+
selectedServerHtml = html`
515+
<div style="display:flex; flex-direction:column;">
516+
<select style="min-width:100px;" @change='${(e) => { this.serverUrl = e.target.value; }}'>
517+
${this.servers.map((v) => html`<option value="${v.url}">${v.url} - ${v.description}</option>`)}
518+
</select>
519+
520+
<div style="display:flex; flex-direction:row; align-items:center; margin-top:10px;">
521+
<div style="font-weight:bold;padding-right:5px;">API SERVER: </div>
522+
<div> ${this.serverUrl ? this.serverUrl : html`<div style="font-weight:bold;color:var(--red)">NO API Server Selected</div>`}</div>
523+
</div>
524+
</div>
525+
`;
514526
}
527+
515528
return html`
516529
<div style="display:flex; align-items: center; margin:16px 0; font-size:var(--font-size-small);">
517530
<div style="display:flex; flex-direction:column; margin:0; width:calc(100% - 60px);">
518531
<div style="display:flex; flex-direction:row; align-items:center; overflow:hidden;">
519-
<div style="font-weight:bold;padding-right:5px;">API SERVER: </div>
520-
${containerServer}
532+
${selectedServerHtml}
521533
</div>
522534
<div style="display:flex;">
523535
<div style="padding-right:5px;">Authentication: </div>
@@ -532,7 +544,7 @@ export default class ApiRequest extends LitElement {
532544
}
533545
</div>
534546
</div>
535-
<button class="m-btn primary try-btn" style="padding: 6px 0px;width:60px; align-self:flex-end;" @click="${this.onTryClick}">TRY</button>
547+
<button class="m-btn primary try-btn" style="padding: 6px 0px;width:60px; align-self:flex-start; margin:1px 0 0 5px;" @click="${this.onTryClick}">TRY</button>
536548
</div>
537549
${this.responseMessage === ''
538550
? ''

src/styles/input-styles.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { html } from 'lit-element';
22

3+
/* eslint-disable max-len */
34
export default html`
45
<style>
56
.m-select, input, select, button {
@@ -64,7 +65,7 @@ input[type="password"] {
6465
6566
select {
6667
padding: 6px 35px 6px 5px;
67-
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2212%22%20height%3D%2212%22%3E%3Cpath%20d%3D%22M10.3%203.3L6%207.6%201.7%203.3A1%201%200%2000.3%204.7l5%205a1%201%200%20001.4%200l5-5a1%201%200%2010-1.4-1.4z%22%20fill%3D%22%23777777%22%2F%3E%3C%2Fsvg%3E");
68+
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2212%22%20height%3D%2212%22%3E%3Cpath%20d%3D%22M10.3%203.3L6%207.6%201.7%203.3A1%201%200%2000.3%204.7l5%205a1%201%200%20001.4%200l5-5a1%201%200%2010-1.4-1.4z%22%20fill%3D%22%23777777%22%2F%3E%3C%2Fsvg%3E");
6869
background-position: calc(100% - 5px) center;
6970
background-repeat: no-repeat;
7071
background-size: 10px;

src/templates/endpoint-template.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ 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;
4948
return html`
5049
<div class='endpoint-body ${path.method}'>
5150
${path.summary || path.description
@@ -70,7 +69,7 @@ function endpointBodyTemplate(path) {
7069
.request_body = "${path.requestBody}"
7170
.api_keys = "${nonEmptyApiKeys}"
7271
.servers = "${path.servers}"
73-
server-url = "${selectedServer}"
72+
server-url = "${path.servers && path.servers.length > 0 ? path.servers[0].url : this.selectedServer.computedUrl}"
7473
active-schema-tab = "${this.defaultSchemaTab}"
7574
allow-try = "${this.allowTry}"
7675
accept = "${accept}"

src/templates/expanded-endpoint-template.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ function endpointBodyTemplate(path) {
100100
.parameters = "${path.parameters}"
101101
.request_body = "${path.requestBody}"
102102
.api_keys = "${nonEmptyApiKeys}"
103-
server-url = "${this.selectedServer.computedUrl}"
103+
.servers = "${path.servers}"
104+
server-url = "${path.servers && path.servers.length > 0 ? path.servers[0].url : this.selectedServer.computedUrl}"
104105
allow-try = "${this.allowTry}"
105106
accept = "${accept}"
106107
render-style="${this.renderStyle}"

0 commit comments

Comments
 (0)