Integrating an own component for ApiKeyAuth via Plugin API doesn't work
See original GitHub issueQ | A |
---|---|
Bug or feature request? | Bug (probably) |
Which Swagger/OpenAPI version? | 2.0 |
Which Swagger-UI version? | 3.13.4 |
How did you install Swagger-UI? | via npm/webpack |
Which browser & version? | Safari 11.1 |
Which operating system? | MacOS 10.13.4 |
In our project we use the plugin api to override several components, such as InfoUrl and InfoBasePath which works like expected. If we try the same for the component ApiKeyAuth it doesn’t have any impact to our UI, even if we cancel it out completely:
export const ApiKeyAuthPlugin = () => {
return {
components: {
ApiKeyAuth: () => null
}
}
}
Demonstration API definition
"security": [
{
"api_key": []
}
],
"securityDefinitions": {
"api_key": {
"in": "header",
"name": "x-api-key",
"type": "apiKey",
}
},
Expected Behavior
With the above described plugin, the component should be cleared out which should result in an empty modal in our UI.
Current Behavior
Nothing happens. The UI looks like without a plugin at all.
Context
We need to set a default apiKey for our tryout requests from swagger-ui. So the users can decide whether they want to use the default one or their own. Therefore, we want to display the apiKey as a default in the authorization modal. Additionally this apiKey should even be set as default before the user clicks authorize. As this is not possible with the current swagger-ui, we want to create our own plugin to overwrite the apiKeyAuth component.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
Hi @ChristophWalter!
Try using
apiKeyAuth
instead ofApiKeyAuth
😄 component names are case-sensitive, and not 100% consistent across the project…To quote myself in #4431:
For future reference, you can use the
getComponents
method to see an object with every component’s name as a key, though in a perfect world you wouldn’t have to care about the case.You can do this from within an
onComplete
, like so:@ChristophWalter no problem! Immutable has a very powerful API, for this particular thing you can use
ui.specSelectors.specJson().getIn(["a", "deep", "path"])
to grab a value deeply within your data. Or you could always useui.specSelectors.specJson().toJS()
if you want a plain JS object 😄