cancel
Showing results for 
Search instead for 
Did you mean: 

Creating SwaggerUI with pre existing swagger.json document

SOLVED
Highlighted
New Contributor

Creating SwaggerUI with pre existing swagger.json document

I have already created a swagger.json from an open-source library since my API doesn't support creating one due to HAPI-link and libraries. Now what I do is copy the JSON and load into an online Swagger-editor to verify and view the UI but is there any way by which I can feed the swagger JSON and create a SwaggerUI?

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Staff

Re: Creating SwaggerUI with pre existing swagger.json document

Allow your swagger.json file to be servable as static asset via your HAPI.js server. Let's say your server runs on https://pre-existing-swagger.com/ and your swagger.json file is accesible on https://pre-existing-swagger.com/static/swagger.json. Then create a following HTML file called api.html and again make it servable as static asset via your HAPI.js server. Now when you access https://pre-existing-swagger.com/static/api.html, SwaggerUI will render the swagger.json file.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Api</title>
<link rel="stylesheet" href="//unpkg.com/swagger-ui-dist@3.26.0/swagger-ui.css" />
<script src="//unpkg.com/swagger-ui-dist@3.26.0/swagger-ui-bundle.js"></script>
</head>
<body>
<div id="root" class="swagger-ui" />
<script>
const ui = SwaggerUIBundle({
url: 'https://pre-existing-swagger.com/static/swagger.json',
dom_id: '#root'
});
</script>
</body>
</html>

 

Vladimír Gorej

View solution in original post

Highlighted
New Contributor

Re: Creating SwaggerUI with pre existing swagger.json document

Yep, @char0n did exactly the same but hosted in an s3 bucket and then used Cloudfront. Also, another approach that we did was to use the swagger macro in confluence and load directly from the s3 bucket. Both worked like a charm. 

View solution in original post

2 REPLIES 2
Highlighted
Staff

Re: Creating SwaggerUI with pre existing swagger.json document

Allow your swagger.json file to be servable as static asset via your HAPI.js server. Let's say your server runs on https://pre-existing-swagger.com/ and your swagger.json file is accesible on https://pre-existing-swagger.com/static/swagger.json. Then create a following HTML file called api.html and again make it servable as static asset via your HAPI.js server. Now when you access https://pre-existing-swagger.com/static/api.html, SwaggerUI will render the swagger.json file.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Api</title>
<link rel="stylesheet" href="//unpkg.com/swagger-ui-dist@3.26.0/swagger-ui.css" />
<script src="//unpkg.com/swagger-ui-dist@3.26.0/swagger-ui-bundle.js"></script>
</head>
<body>
<div id="root" class="swagger-ui" />
<script>
const ui = SwaggerUIBundle({
url: 'https://pre-existing-swagger.com/static/swagger.json',
dom_id: '#root'
});
</script>
</body>
</html>

 

Vladimír Gorej

View solution in original post

Highlighted
New Contributor

Re: Creating SwaggerUI with pre existing swagger.json document

Yep, @char0n did exactly the same but hosted in an s3 bucket and then used Cloudfront. Also, another approach that we did was to use the swagger macro in confluence and load directly from the s3 bucket. Both worked like a charm. 

View solution in original post

New Here?
Join us and watch the welcome video:
Top Kudoed Authors