如何在Swagger UI上加载托管在私有GitHub存储库中的文件
我想使用如何在Swagger UI上加载托管在私有GitHub存储库中的文件,github,swagger,swagger-ui,Github,Swagger,Swagger Ui,我想使用swagger ui在私人网站上托管我的swaggerAPI文档 YAML文件托管在私有GitHub存储库中。根据这一点,我用curl命令行成功地检索到了所需的文件,但我一直在用swagger ui尝试它: window.swaggerUi = new SwaggerUi({ url: 'https://api.github.com/repos/me/my_repo/contents/api.yaml', authorizations: { 'Authorization'
swagger ui
在私人网站上托管我的swagger
API文档
YAML文件托管在私有GitHub存储库中。根据这一点,我用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();
我得到一个错误:
http.js:296未捕获类型错误:auth.apply不是函数
有什么建议吗?答案如下:(请注意,它不适用于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,
});