我希望使用swagger
在私人网站上托管我的swagger-ui
API文档。
YAML文件托管在私有GitHub存储库中。根据这个gist,我使用curl
命令行成功检索了所需的文件,但我在swagger-ui
尝试使用window.swaggerUi = new SwaggerUi({
url: 'https://api.github.com/repos/me/my_repo/contents/api.yaml',
authorizations: {
'Authorization': 'token 0123456789',
'Accept': 'application/vnd.github.v3.raw'
},
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(swaggerApi, swaggerUi){
if(typeof initOAuth == "function") {
initOAuth({
clientId: "your-client-id",
clientSecret: "your-client-secret-if-required",
realm: "your-realms",
appName: "your-app-name",
scopeSeparator: ",",
additionalQueryStringParams: {}
});
}
if(window.SwaggerTranslator) {
window.SwaggerTranslator.translate();
}
},
onFailure: function(data) {
log("Unable to Load SwaggerUI");
},
docExpansion: "none",
jsonEditor: false,
defaultModelRendering: 'schema',
showRequestHeaders: false
});
window.swaggerUi.load();
:
self.tableView.reloadData()
self.tableView.layoutIfNeeded()
self.tableViewHeightConstraint.constant = self.tableView.contentSize.height
我收到错误:
http.js:296未捕获TypeError:auth.apply不是函数
有什么建议吗?
答案 0 :(得分:0)
以下是答案:(请注意,它不适用于YAML文件。仅限JSON。)
// spec: content,
window.swaggerUi = new SwaggerUi({
url: 'https://api.github.com/repos/me/my_repo/contents/api.json',
authorizations: {
'Accept': new window.SwaggerClient.ApiKeyAuthorization("Accept", "application/vnd.github.v3.raw", "header"),
'Authorization': new window.SwaggerClient.ApiKeyAuthorization("Authorization", "token 0123456789", "header"),
},
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(swaggerApi, swaggerUi){
if(typeof initOAuth == "function") {
initOAuth({
clientId: "your-client-id",
clientSecret: "your-client-secret-if-required",
realm: "your-realms",
appName: "your-app-name",
scopeSeparator: ",",
additionalQueryStringParams: {}
});
}
if(window.SwaggerTranslator) {
window.SwaggerTranslator.translate();
}
},
onFailure: function(data) {
log("Unable to Load SwaggerUI : ", data);
},
docExpansion: "none",
jsonEditor: false,
defaultModelRendering: 'schema',
showRequestHeaders: false,
});