Skip to content

Commit 444a6a9

Browse files
committed
converted security scheme to template and enabled provision of multiple security keys
1 parent df5ca63 commit 444a6a9

14 files changed

+311
-314
lines changed

dist/index.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
-->
2222

2323
<rapi-doc
24-
id="thedoc"
25-
spec-url="./specs/additional-props.yaml"
26-
theme="dark"
27-
render-style = "read"
24+
id = "thedoc"
25+
spec-url = "./specs/pet.yaml"
26+
theme = "dark"
27+
render-style = "view"
2828
regular-font = 'Open Sans'
2929
schema-style = 'tree'
3030
goto-path= 'post-/person'
31+
aapi-key-name = "abcd"
32+
aapi-key-location = "header"
33+
aapi-key-value = "abcd"
3134
> </rapi-doc>
3235

3336

dist/index.html.gz

34 Bytes
Binary file not shown.

dist/rapidoc-min.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rapidoc-min.js.gz

138 Bytes
Binary file not shown.

dist/report.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

src/components/api-request.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ export default class ApiRequest extends LitElement {
2828

2929
static get properties() {
3030
return {
31-
apiKeyName: { type: String, attribute: 'api-key-name' },
32-
apiKeyValue: { type: String, attribute: 'api-key-value' },
33-
apiKeyLocation: { type: String, attribute: 'api-key-location' },
3431
selectedServer: { type: String, attribute: 'selected-server' },
3532
method: { type: String },
3633
path: { type: String },
3734
parameters: { type: Array },
3835
request_body: { type: Object },
36+
api_keys: { type: Array },
3937
parser: { type: Object },
4038
accept: { type: String },
4139
responseMessage: { type: String, attribute: false },
@@ -104,7 +102,7 @@ export default class ApiRequest extends LitElement {
104102
color:var(--blue);
105103
}
106104
107-
@media only screen and (min-width: 768px){
105+
@media only screen and (min-width: 768px) {
108106
.textarea {
109107
padding:16px;
110108
}
@@ -463,21 +461,23 @@ export default class ApiRequest extends LitElement {
463461
return html`
464462
<div style="display:flex; align-items: center; margin:16px 0; font-size:var(--font-size-small);">
465463
<div style="display:flex; flex-direction:column; margin:0; width:calc(100% - 60px);">
466-
<div style="display:flex;flex-direction:row;overflow:hidden;"> <div style="font-weight:bold;padding-right:5px;">API SERVER: </div>
464+
<div style="display:flex;flex-direction:row;overflow:hidden;">
465+
<div style="font-weight:bold;padding-right:5px;">API SERVER: </div>
467466
${this.selectedServer
468467
? html`${this.selectedServer}`
469468
: html`<div style="font-weight:bold;color:var(--red)">Not Set</div>`
470469
}
471470
</div>
472-
<div style="display:flex;flex-direction:row;overflow:hidden;line-height:16px;color:var(--fg3)">
473-
${this.apiKeyValue && this.apiKeyName
474-
? html`
475-
<div style="font-weight:bold;color:var(--blue)">Authentication: &nbsp; </div>
476-
send <div style="font-family:var(--font-mono); color:var(--fg)"> '${this.apiKeyName}' </div>
477-
in<div style="font-family:var(--font-mono); color:var(--fg)"> '${this.apiKeyLocation}' </div>
478-
with value<div style="font-family:var(--font-mono); color:var(--fg)"> '${`${this.apiKeyValue.substring(0, 3)}***`}' </div>
479-
`
480-
: html`<div style="color:var(--light-fg)">No Authentication Token provided</div>`
471+
<div style="display:flex;">
472+
<div style="padding-right:5px;">Authentication: </div>
473+
${this.api_keys.length > 0
474+
? html`<div style="font-weight:bold;color:var(--blue); overflow:hidden;">
475+
${this.api_keys.length === 1
476+
? `API Key '${this.api_keys[0].name}' in ${this.api_keys[0].in}`
477+
: `${this.api_keys.length} API keys applied`
478+
}
479+
</div>`
480+
: html`<div style="font-weight:bold; color:var(--red)">No API key applied</div>`
481481
}
482482
</div>
483483
</div>
@@ -626,9 +626,11 @@ export default class ApiRequest extends LitElement {
626626

627627

628628
// Add authentication Query-Param if provided
629-
if (this.apiKeyValue && this.apiKeyName && this.apiKeyLocation === 'query') {
630-
fetchUrl = `${fetchUrl}${fetchUrl.includes('?') ? '&' : '?'}${this.apiKeyName}=${encodeURIComponent(this.apiKeyValue)}`;
631-
}
629+
this.api_keys
630+
.filter((v) => (v.in === 'query'))
631+
.forEach((v) => {
632+
fetchUrl = `${fetchUrl}${fetchUrl.includes('?') ? '&' : '?'}${v.name}=${encodeURIComponent(v.finalKeyValue)}`;
633+
});
632634

633635
// Final URL for API call
634636
fetchUrl = `${this.selectedServer.replace(/\/$/, '')}${fetchUrl}`;
@@ -653,10 +655,12 @@ export default class ApiRequest extends LitElement {
653655
}
654656
});
655657
// Add Authentication Header if provided
656-
if (this.apiKeyValue && this.apiKeyName && this.apiKeyLocation === 'header') {
657-
fetchOptions.headers[this.apiKeyName] = this.apiKeyValue;
658-
curlHeaders += ` -H "${this.apiKeyName}: ${this.apiKeyValue}"`;
659-
}
658+
this.api_keys
659+
.filter((v) => (v.in === 'header'))
660+
.forEach((v) => {
661+
fetchOptions.headers[v.name] = v.finalKeyValue;
662+
curlHeaders += ` -H "${v.name}: ${v.finalKeyValue}"`;
663+
});
660664

661665
// Submit Form Params (url-encoded or form-data)
662666
if (formParamEls.length >= 1) {

src/components/security-schemes.js

Lines changed: 0 additions & 212 deletions
This file was deleted.

0 commit comments

Comments
 (0)