Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable swagger UI in AWS

I created the serverless application using .Net core and hosted in AWS. I am able to create swagger.json by publishing API documentation under API gateway.

I am looking for the documentation to create swagger UI for those APIs. Is any possibility to view the swagger UI in AWS itself.

like image 811
Shoba Avatar asked Sep 10 '18 12:09

Shoba


People also ask

How do I access Swagger AWS?

Navigate to S3 in AWS console and create a bucket with some name like swagger-bucket . Under the properties tab, enable Static website hosting and make a note of the link provided. In the Index Document, enter the name of the document as index.

How do I integrate Swagger with AWS API gateway?

Select Amazon API Gateway Integration from the list of integrations. Enter integration parameters: Name – A display name for this integration. AWS Region – Select the AWS region where you want to publish your API or that contains the existing API you want to publish to.


2 Answers

I do not think AWS built a swagger UI in one of their services. At least, I am not aware of it.

However, it is possible to easily create a swagger visualization using S3.
There is an article on Medium which explains this well. [1]

Basically, what you need to script is:

  • Creation of an S3 bucket with static website hosting
  • Downloading the static swagger UI resources from GitHub
  • Syncing the resources to the S3 bucket
  • Downloading the swagger.json from API Gateway [2]
  • Uploading the swagger.json to S3
  • Modify index.html to point at your swagger.json

These steps are laid out in detail in the Medium article. [1]

References

[1] https://medium.com/nirman-tech-blog/swagger-ui-for-aws-api-gateway-endpoints-a667f25f5a4b
[2] https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-export-api.html

like image 72
Martin Löper Avatar answered Nov 01 '22 15:11

Martin Löper


You can easily host self-contained swagger-UI web site in S3.

Here is an example: https://iris-fhir-server.s3.amazonaws.com/swagger-ui.html

Github: https://github.com/intersystems-community/Swagger-IRIS-FHIR

It's essentially your OpenAPI yaml or json files plus single HTML page like:

<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Swagger UI</title>
    <link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@3/swagger-ui.css" >
    <style>
      html
      {
        box-sizing: border-box;
        overflow: -moz-scrollbars-vertical;
        overflow-y: scroll;
      }    
      *,
      *:before,
      *:after
      {
        box-sizing: inherit;
      }

      body
      {
        margin:0;
        background: #fafafa;
      }
      .errors-wrapper {
         display: none !IMPORTANT;
      }
    </style>
  </head>    
  <body>
    <div id="swagger-ui"></div>    
    <script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js"> </script>
    <script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js"> </script>    <script>
    window.onload = function() {          
      // Begin Swagger UI call region
      const ui = SwaggerUIBundle({
        "dom_id": "#swagger-ui",
        deepLinking: true,
        presets: [
          SwaggerUIBundle.presets.apis,
          SwaggerUIStandalonePreset
        ],
        plugins: [
          SwaggerUIBundle.plugins.DownloadUrl
        ],
        layout: "StandaloneLayout",
        validatorUrl: "https://validator.swagger.io/validator",
        //url: "https://iris-fhir-server.s3.amazonaws.com/openapi/Patient.yml",
        urls: [
          {url: "https://iris-fhir-server.s3.amazonaws.com/openapi/Organization.yml", name: "Organization"},
          {url: "https://iris-fhir-server.s3.amazonaws.com/openapi/Patient.yml", name: "Patient"},
          {url: "https://iris-fhir-server.s3.amazonaws.com/openapi/Practitioner.yml", name: "Practitioner"},
          {url: "https://iris-fhir-server.s3.amazonaws.com/openapi/Condition.yml", name: "Condition"},
          {url: "https://iris-fhir-server.s3.amazonaws.com/openapi/Medication.yml", name: "Medication"},
          {url: "https://iris-fhir-server.s3.amazonaws.com/openapi/Observation.yml", name: "Observation"}              
        ],
        "urls.primaryName": "Patient"
      })
      window.ui = ui
    }
  </script>
  </body>
</html>
like image 40
Anton Avatar answered Nov 01 '22 16:11

Anton