0
語境:在1.2規範從當前REST文檔轉換揚鞭至2.0apiKey如揚鞭UI查詢參數2.0
環境:爪哇8,招搖-行家-插件3.0.1,招搖註解(COM .wordnik)
我卡在哪裏:我能夠成功生成REST API文檔。但是,REST API需要一個ApiKey作爲Query參數。在1.2規範,這是使用的index.html
function addApiKeyAuthorization() {
var key = $('#input_apiKey')[0].value;
log("key: " + key);
if(key && key.trim() != "") {
log("added key " + key);
//window.authorizations.add("api_key", new ApiKeyAuthorization("api_key", key, "query"));
window.authorizations.add("apiKey", new ApiKeyAuthorization("apiKey", key, "header"));
}
}
$('#input_apiKey').change(function() {
addApiKeyAuthorization();
});
// if you have an apiKey you would like to pre-populate on the page for demonstration purposes...
var apiKey = "ABCD";
$('#input_apiKey').val(apiKey);
addApiKeyAuthorization();
但是下面的代碼段,用於2.0規範添加,我的搜索導致了YAML文件進行以下更改。
securityDefinitions:
UserSecurity:
type: apiKey
in: header
name:myApiKey
當前的index.html在窗函數如下:
window.onload = function() {
// Build a system
const ui = SwaggerUIBundle({
url: "http://someCoolsite.com/swagger.json",
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
window.ui = ui
}