Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle openapi 3.0 format, use new swagger-ui #114

Merged
merged 7 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Cowboy Swagger Example
# Cowboy Swagger OpenAPI 3.0.0 Example

To try this example, you need GNU `rebar3` , `git` and `Erlang` in your PATH.

Expand Down
3 changes: 1 addition & 2 deletions example/config/sys.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
, { cowboy_swagger
, [ {static_files, "priv/swagger"}
, { global_spec
, #{ swagger => "2.0"
, #{ openapi => "3.0.0"
, info => #{title => "Example API"}
, basePath => ""
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion example/src/example.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, example,
[
{description, "Cowboy Swagger Basic Example."},
{description, "Cowboy Swagger OpenAPI 3.0.0 Basic Example."},
{vsn, "0.1"},
{applications,
[kernel,
Expand Down
13 changes: 12 additions & 1 deletion example/src/example_description_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,18 @@ trails() ->
#{get =>
#{tags => ["example"],
description => "Retrives trails's server description",
produces => ["text/plain"]
responses => #{
<<"200">> => #{
description => <<"Retrives trails's server description 200 OK">>,
content => #{
'text/plain' =>
#{schema => #{
type => string
}
}
}
}
}
}
},
[trails:trail("/description", example_description_handler, [], Metadata)].
Expand Down
20 changes: 17 additions & 3 deletions example/src/example_echo_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,32 @@ trails() ->
#{get =>
#{tags => ["echo"],
description => "Gets echo var from the server",
produces => ["text/plain"]
responses => #{
<<"200">> => #{
description => <<"Gets echo var from the server 200 OK">>,
content => #{
'text/plain' =>
#{schema => #{
type => string
}
}
}
}
}
},
put =>
#{tags => ["echo"],
description => "Sets echo var in the server",
produces => ["text/plain"],
parameters => [
#{name => <<"echo">>,
description => <<"Echo message">>,
in => <<"path">>,
required => false,
type => <<"string">>}
schema =>
#{type => string,
example => <<"Hello, World!">>
}
}
]
}
},
Expand Down
1 change: 0 additions & 1 deletion priv/swagger/css/print.css

This file was deleted.

1 change: 0 additions & 1 deletion priv/swagger/css/reset.css

This file was deleted.

1 change: 0 additions & 1 deletion priv/swagger/css/screen.css

This file was deleted.

1 change: 0 additions & 1 deletion priv/swagger/css/style.css

This file was deleted.

Empty file removed priv/swagger/css/typography.css
Empty file.
Binary file added priv/swagger/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added priv/swagger/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed priv/swagger/fonts/DroidSans-Bold.ttf
Binary file not shown.
Binary file removed priv/swagger/fonts/DroidSans.ttf
Binary file not shown.
Binary file removed priv/swagger/images/collapse.gif
Binary file not shown.
Binary file removed priv/swagger/images/expand.gif
Binary file not shown.
Binary file removed priv/swagger/images/explorer_icons.png
Binary file not shown.
Binary file removed priv/swagger/images/favicon-16x16.png
Binary file not shown.
Binary file removed priv/swagger/images/favicon-32x32.png
Binary file not shown.
Binary file removed priv/swagger/images/favicon.ico
Binary file not shown.
Binary file removed priv/swagger/images/logo_small.png
Binary file not shown.
Binary file removed priv/swagger/images/pet_store_api.png
Binary file not shown.
Binary file removed priv/swagger/images/throbber.gif
Binary file not shown.
Binary file removed priv/swagger/images/wordnik_api.png
Binary file not shown.
150 changes: 55 additions & 95 deletions priv/swagger/index.html
Original file line number Diff line number Diff line change
@@ -1,106 +1,66 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" />
<link href='css/typography.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
<link href='css/print.css' media='print' rel='stylesheet' type='text/css'/>

<script src='lib/object-assign-pollyfill.js' type='text/javascript'></script>
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='lib/handlebars-4.0.5.js' type='text/javascript'></script>
<script src='lib/lodash.min.js' type='text/javascript'></script>
<script src='lib/backbone-min.js' type='text/javascript'></script>
<script src='swagger-ui.min.js' type='text/javascript'></script>
<script src='lib/highlight.9.1.0.pack.js' type='text/javascript'></script>
<script src='lib/highlight.9.1.0.pack_extended.js' type='text/javascript'></script>
<script src='lib/jsoneditor.min.js' type='text/javascript'></script>
<script src='lib/marked.js' type='text/javascript'></script>
<script src='lib/swagger-oauth.js' type='text/javascript'></script>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}

<!-- Some basic translations -->
<!-- <script src='lang/translator.js' type='text/javascript'></script> -->
<!-- <script src='lang/ru.js' type='text/javascript'></script> -->
<!-- <script src='lang/en.js' type='text/javascript'></script> -->
*,
*:before,
*:after
{
box-sizing: inherit;
}

<script type="text/javascript">
$(function () {
var url = window.location.search.match(/url=([^&]+)/);
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
} else {
url = "/api-docs/swagger.json";
body
{
margin:0;
background: #fafafa;
}
</style>
</head>

hljs.configure({
highlightSizeThreshold: 5000
});
<body>
<div id="swagger-ui"></div>

// Pre load translate...
if(window.SwaggerTranslator) {
window.SwaggerTranslator.translate();
<script src="./swagger-ui-bundle.js"> </script>
<script src="./swagger-ui-standalone-preset.js"> </script>
<script>
window.onload = function() {
let url = window.location.search.match(/url=([^&]+)/);
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
} else {
url = window.location.origin + "/api-docs/swagger.json";
}
window.swaggerUi = new SwaggerUi({
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: url,
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();
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
// End Swagger UI call region

function log() {
if ('console' in window) {
console.log.apply(console, arguments);
}
}
});
window.ui = ui
}
</script>
</head>

<body class="swagger-section">
<div id='header'>
<div class="swagger-ui-wrap">
<a id="logo" href="http://swagger.io"><img class="logo__img" alt="swagger" height="30" width="30" src="images/logo_small.png" /><span class="logo__title">swagger</span></a>
<form id='api_selector'>
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
<div id='auth_container'></div>
<div class='input'><a id="explore" class="header__btn" href="#" data-sw-translate>Explore</a></div>
</form>
</div>
</div>

<div id="message-bar" class="swagger-ui-wrap" data-sw-translate>&nbsp;</div>
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
</body>
</body>
</html>
53 changes: 0 additions & 53 deletions priv/swagger/lang/ca.js

This file was deleted.

56 changes: 0 additions & 56 deletions priv/swagger/lang/el.js

This file was deleted.

Loading