Skip to content

Commit f6207bd

Browse files
committed
fixed #105 unable to set api-key programatically
1 parent 2b166ed commit f6207bd

File tree

8 files changed

+71
-29
lines changed

8 files changed

+71
-29
lines changed

dist/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222

2323
<rapi-doc
2424
id = "thedoc"
25-
spec-url = "./specs/data-types.yaml"
25+
spec-url = "./specs/basic.json"
2626
theme = "dark"
2727
render-style = "read"
2828
schema-style = 'tree'
2929
api-key-name = "my-key"
3030
api-key-location = "header"
31-
api-key-value = "mye-password"
31+
api-key-value = "my-password"
3232
server-url="http://192.168.7.32:8080"
3333
> </rapi-doc>
3434

dist/index.html.gz

-3 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

157 Bytes
Binary file not shown.

dist/report.html

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

docs/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.

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222

2323
<rapi-doc
2424
id = "thedoc"
25-
spec-url = "./specs/data-types.yaml"
25+
spec-url = "./specs/basic.json"
2626
theme = "dark"
2727
render-style = "read"
2828
schema-style = 'tree'
2929
api-key-name = "my-key"
3030
api-key-location = "header"
31-
api-key-value = "mye-password"
31+
api-key-value = "my-password"
3232
server-url="http://192.168.7.32:8080"
3333
> </rapi-doc>
3434

src/rapidoc.js

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,57 @@ export default class RapiDoc extends LitElement {
582582
this.intersectionObserver.disconnect();
583583
}
584584
}
585+
if (name === 'api-key-name' || name === 'api-key-location' || name === 'api-key-value') {
586+
let updateSelectedApiKey = false;
587+
let apiKeyName = '';
588+
let apiKeyLocation = '';
589+
let apiKeyValue = '';
590+
591+
if (name === 'api-key-name') {
592+
if (this.getAttribute('api-key-location') && this.getAttribute('api-key-value')) {
593+
apiKeyName = newVal;
594+
apiKeyLocation = this.getAttribute('api-key-location');
595+
apiKeyValue = this.getAttribute('api-key-value');
596+
updateSelectedApiKey = true;
597+
}
598+
} else if (name === 'api-key-location') {
599+
if (this.getAttribute('api-key-name') && this.getAttribute('api-key-value')) {
600+
apiKeyLocation = newVal;
601+
apiKeyName = this.getAttribute('api-key-name');
602+
apiKeyValue = this.getAttribute('api-key-value');
603+
updateSelectedApiKey = true;
604+
}
605+
} else if (name === 'api-key-value') {
606+
if (this.getAttribute('api-key-name') && this.getAttribute('api-key-location')) {
607+
apiKeyValue = newVal;
608+
apiKeyLocation = this.getAttribute('api-key-location');
609+
apiKeyName = this.getAttribute('api-key-name');
610+
updateSelectedApiKey = true;
611+
}
612+
}
613+
if (updateSelectedApiKey) {
614+
if (this.resolvedSpec) {
615+
const rapiDocApiKey = this.resolvedSpec.securitySchemes.find((v) => v.apiKeyId === '_rapidoc_api_key');
616+
if (!rapiDocApiKey) {
617+
this.resolvedSpec.securitySchemes.push({
618+
apiKeyId: '_rapidoc_api_key',
619+
description: 'api-key provided in rapidoc element attributes',
620+
type: 'apiKey',
621+
name: apiKeyName,
622+
in: apiKeyLocation,
623+
value: apiKeyValue,
624+
finalKeyValue: apiKeyValue,
625+
});
626+
} else {
627+
rapiDocApiKey.name = apiKeyName;
628+
rapiDocApiKey.in = apiKeyLocation;
629+
rapiDocApiKey.value = apiKeyValue;
630+
rapiDocApiKey.finalKeyValue = apiKeyValue;
631+
}
632+
this.requestUpdate();
633+
}
634+
}
635+
}
585636
super.attributeChangedCallback(name, oldVal, newVal);
586637
}
587638

@@ -653,15 +704,6 @@ export default class RapiDoc extends LitElement {
653704

654705
afterSpecParsedAndValidated(spec) {
655706
this.resolvedSpec = spec;
656-
if (this.getAttribute('api-key-name') && this.getAttribute('api-key-location') && this.getAttribute('api-key-value')) {
657-
this.selected_api_keys = [{
658-
apiKeyId: '_rapidoc_key_',
659-
apiKeyName: this.getAttribute('api-key-name'),
660-
apiKeyLocation: this.getAttribute('api-key-location'),
661-
apiKeyValue: this.getAttribute('api-key-value'),
662-
}];
663-
}
664-
665707
if (this.defaultApiServerUrl) {
666708
if (this.defaultApiServerUrl === this.serverUrl) {
667709
this.selectedServer = {

0 commit comments

Comments
 (0)