Skip to content

Commit bd6fda7

Browse files
committed
new feature: added ability to programmatically set the API server
1 parent 80d1f02 commit bd6fda7

File tree

6 files changed

+35
-26
lines changed

6 files changed

+35
-26
lines changed

src/rapidoc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { advancedSearch, pathIsInSearch, componentIsInSearch, rapidocApiKey, sle
2727
import ProcessSpec from '~/utils/spec-parser';
2828
import mainBodyTemplate from '~/templates/main-body-template';
2929
import { applyApiKey, onClearAllApiKeys } from '~/templates/security-scheme-template';
30+
import { setApiServer } from '~/templates/server-template';
3031

3132
export default class RapiDoc extends LitElement {
3233
constructor() {
@@ -923,6 +924,12 @@ export default class RapiDoc extends LitElement {
923924
return onClearAllApiKeys.call(this);
924925
}
925926

927+
// Public Method
928+
setApiServer(apiServerUrl) {
929+
// return apiServerUrl;
930+
return setApiServer.call(this, apiServerUrl);
931+
}
932+
926933
// Event handler for Advanced Search text-inputs and checkboxes
927934
onAdvancedSearch(ev, delay) {
928935
const eventTargetEl = ev.target;

src/styles/font-styles.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ export default css`
8484
}
8585
8686
.m-markdown p,
87-
.m-markdown span,
88-
.m-markdown li {
87+
.m-markdown span {
8988
font-size: var(--font-size-regular);
89+
line-height:calc(var(--font-size-regular) + 8px);
90+
}
91+
.m-markdown li{
9092
line-height:calc(var(--font-size-regular) + 12px);
9193
}
9294

src/styles/nav-styles.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export default css`
1515
flex-wrap:nowrap;
1616
word-break:break-word;
1717
}
18+
::slotted(*){
19+
padding:16px 30px 0 16px;
20+
}
1821
.nav-scroll {
1922
overflow-x: hidden;
2023
overflow-y: auto;
@@ -73,7 +76,7 @@ export default css`
7376
color: var(--nav-accent-color);
7477
border-left:4px solid transparent;
7578
font-weight:bold;
76-
padding: 15px calc(var(--scroll-bar-width) + 5px) 15px 10px;
79+
padding: 15px 15px 15px 10px;
7780
text-transform: capitalize;
7881
}
7982
@@ -110,9 +113,7 @@ export default css`
110113
font-size: var(--font-size-small);
111114
color: var(--nav-text-color);
112115
padding: var(--nav-item-padding);
113-
filter:opacity(0.5);
114116
font-weight:bold;
115-
border-bottom: 1px solid var(--nav-text-color);
116117
}
117118
.nav-bar-section.operations {
118119
cursor:pointer;

src/templates/navbar-template.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,13 @@ export default function navbarTemplate() {
4040
if (!this.resolvedSpec || this.resolvedSpec.specLoadError) {
4141
return html`
4242
<nav class='nav-bar' part="section-navbar">
43-
<div style="padding:16px 30px 0 16px;">
44-
<slot name="nav-logo" class="logo"></slot>
45-
</div>
43+
<slot name="nav-logo" class="logo"></slot>
4644
</nav>
4745
`;
4846
}
4947
return html`
5048
<nav class='nav-bar ${this.renderStyle}' part="section-navbar">
51-
<div style="padding:16px 30px 0 16px;">
52-
<slot name="nav-logo" class="logo"></slot>
53-
</div>
49+
<slot name="nav-logo" class="logo"></slot>
5450
${(this.allowSearch === 'false' && this.allowAdvancedSearch === 'false')
5551
? ''
5652
: html`

src/templates/server-template.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ import { html } from 'lit-element';
22
import marked from 'marked';
33
import { unsafeHTML } from 'lit-html/directives/unsafe-html';
44

5-
function onApiServerChange(e, server) {
6-
if (e && e.target.checked) {
7-
this.selectedServer = server;
8-
this.requestUpdate();
9-
this.dispatchEvent(new CustomEvent('api-server-change', {
10-
bubbles: true,
11-
composed: true,
12-
detail: {
13-
selectedServer: server,
14-
},
15-
}));
5+
export function setApiServer(serverUrl) {
6+
const serverObj = this.resolvedSpec?.servers.find((s) => s.url === serverUrl);
7+
if (!serverObj) {
8+
return false;
169
}
10+
this.selectedServer = serverObj;
11+
this.requestUpdate();
12+
this.dispatchEvent(new CustomEvent('api-server-change', {
13+
bubbles: true,
14+
composed: true,
15+
detail: {
16+
selectedServer: serverObj,
17+
},
18+
}));
19+
return true;
1720
}
1821

1922
function onApiServerVarChange(e, serverObj) {
@@ -93,7 +96,7 @@ export default function serverTemplate() {
9396
name = 'api_server'
9497
id = 'srvr-opt-${i}'
9598
value = '${server.url}'
96-
@change = ${(e) => { onApiServerChange.call(this, e, server); }}
99+
@change = ${() => { setApiServer.call(this, server.url); }}
97100
.checked = '${this.selectedServer.url === server.url}'
98101
style = 'margin:4px 0; cursor:pointer'
99102
/>

src/utils/theme.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ export default function setTheme(baseTheme, theme = {}) {
200200
--font-regular: ${this.regularFont || '"Open Sans", Avenir, "Segoe UI", Arial, sans-serif'};
201201
--scroll-bar-width: 8px;
202202
--nav-item-padding: ${this.navItemSpacing === 'relaxed'
203-
? '10px calc(var(--scroll-bar-width, 8px) + 5px) 10px 10px'
203+
? '10px 16px 10px 10px'
204204
: (this.navItemSpacing === 'compact'
205-
? '5px calc(var(--scroll-bar-width, 8px) + 5px) 5px 10px'
206-
: '7px calc(var(--scroll-bar-width, 8px) + 5px) 7px 10px')};
205+
? '5px 16px 5px 10px'
206+
: '7px 16px 7px 10px')};
207207
208208
--resp-area-height: ${this.responseAreaHeight};
209209
--font-size-small: ${this.fontSize === 'default' ? '12px' : (this.fontSize === 'large' ? '13px' : '14px')};

0 commit comments

Comments
 (0)