Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Swagger UI上加载托管在私有GitHub存储库中的文件_Github_Swagger_Swagger Ui - Fatal编程技术网

如何在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,
  });