- {renderSecurities(authInputRef, operation, this.onChange, oauth, e => {
+ {renderSecurities(authInputRef, operation, this.onChange, oauth, apiKey, e => {
e.preventDefault();
onSubmit();
})}
diff --git a/packages/api-explorer/src/Doc.jsx b/packages/api-explorer/src/Doc.jsx
index bea46a308..f44e1a2cf 100644
--- a/packages/api-explorer/src/Doc.jsx
+++ b/packages/api-explorer/src/Doc.jsx
@@ -37,6 +37,24 @@ class Doc extends React.Component {
this.toggleAuth = this.toggleAuth.bind(this);
this.hideResults = this.hideResults.bind(this);
this.waypointEntered = this.waypointEntered.bind(this);
+
+ this.setApiKey();
+ }
+
+ setApiKey() {
+ if (!this.props.apiKey) return;
+
+ const operation = this.getOperation();
+
+ if (!operation) return;
+
+ try {
+ const firstSecurity = this.operation.getSecurity()[0];
+
+ this.state.formData.auth = { [Object.keys(firstSecurity)[0]]: this.props.apiKey };
+ } catch(e) {
+ console.error('There was a problem setting the api key', e); // eslint-disable-line no-console
+ }
}
onChange(formData) {
@@ -220,6 +238,7 @@ class Doc extends React.Component {
toggleAuth={this.toggleAuth}
onSubmit={this.onSubmit}
authInputRef={el => (this.authInput = el)}
+ apiKey={this.props.apiKey}
/>
);
}
diff --git a/packages/api-explorer/src/PathUrl.jsx b/packages/api-explorer/src/PathUrl.jsx
index a02cc61e8..85b637bd6 100644
--- a/packages/api-explorer/src/PathUrl.jsx
+++ b/packages/api-explorer/src/PathUrl.jsx
@@ -28,6 +28,7 @@ function PathUrl({
toggleAuth,
onSubmit,
oauth,
+ apiKey,
}) {
return (
@@ -44,6 +45,7 @@ function PathUrl({
toggle={toggleAuth}
authInputRef={authInputRef}
oauth={oauth}
+ apiKey={apiKey}
/>
))}