api-platform / api-platform/core
Swagger UI pre-authorize feature
- 主要語言
- PHP
- 星號
- 2.6k
- 分支
- 980
- 平均合併
- 2 天 5 小時
- 30 天內合併 PR
- 48
描述
**Description**
Allow API Platform configuration to specify an API Key to be pre-filled in Swagger UI.
Swagger UI documentation (https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/) states that a method `preauthorizeApiKey` can be used to set default API KEY / Bearer token.
At the moment, the only way I found to implement this behavior was to override the Swagger UI template, and to override the `javascript` block with the following code :
```
{% block javascript %}
{{ parent() }}
const data = JSON.parse(document.getElementById('swagger-data').innerText);
const apiKey = data.extraConfiguration.apiKey;
let swaggerUiTimeout = window.setTimeout(preAuthorizeSwaggerUi, 100);
function preAuthorizeSwaggerUi() {
if (window.swaggerUI !== undefined) {
window.swaggerUI.preauthorizeApiKey("apiKey", apiKey);
window.clearTimeout(swaggerUiTimeout);
} else {
swaggerUiTimeout = window.setTimeout(preAuthorizeSwaggerUi, 100);
}
}
{% endblock %}
```
It would be interesting to implement a custom event dispatched on the SwaggerUI onComplete method, or to allow this to be configured into the API Platform YML directly.
What do you think ? I can try to prepare a PR if people are interested into this feature.
貢獻指南
評估
這個 Issue 還沒有評估資料。