2

I want to host on a private website the documentation of my swagger API using swagger-ui.

The YAML file is hosted on a private GitHub repository. According the this gist, I successfully retrieved the desired file with the curl command line but I'm stuck trying it with 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();

I get an error:

http.js:296 Uncaught TypeError: auth.apply is not a function

Any suggestions?

1 Answer 1

0

Here is the answer: (Note that it doesn't work with YAML file. Only 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,
  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.