Initial commit

This commit is contained in:
domaindrivendev 2015-01-12 18:06:57 -08:00
parent e4da21b9c5
commit 9b0539a79d
17 changed files with 219 additions and 17 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "swagger-ui"]
path = swagger-ui
url = https://github.com/swagger-api/swagger-ui.git

View File

@ -2,6 +2,8 @@ PATH
remote: .
specs:
swagger_rails (0.0.1)
coffee-rails
haml-rails
rails (~> 4.2.0)
GEM
@ -44,10 +46,32 @@ GEM
tzinfo (~> 1.1)
arel (6.0.0)
builder (3.2.2)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.3.0)
coffee-script-source
execjs
coffee-script-source (1.8.0)
erubis (2.7.0)
execjs (2.2.2)
globalid (0.3.0)
activesupport (>= 4.1.0)
haml (4.1.0.beta.1)
tilt
haml-rails (0.7.0)
actionpack (>= 4.0.1)
activesupport (>= 4.0.1)
haml (>= 3.1, < 5.0)
html2haml (>= 1.0.1)
railties (>= 4.0.1)
hike (1.2.3)
hpricot (0.8.6)
html2haml (1.0.1)
erubis (~> 2.7.0)
haml (>= 4.0.0.rc.1)
hpricot (~> 0.8.6)
ruby_parser (~> 3.1.1)
i18n (0.7.0)
json (1.8.2)
loofah (2.0.1)
@ -88,6 +112,9 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
ruby_parser (3.1.3)
sexp_processor (~> 4.1)
sexp_processor (4.4.4)
sprockets (2.12.3)
hike (~> 1.2)
multi_json (~> 1.0)

View File

@ -11,3 +11,15 @@
// about supported directives.
//
//= require_tree .
//= require swagger-ui/lib/shred.bundle.js
//= require swagger-ui/lib/jquery-1.8.0.min.js
//= require swagger-ui/lib/jquery.slideto.min.js
//= require swagger-ui/lib/jquery.wiggle.min.js
//= require swagger-ui/lib/jquery.ba-bbq.min.js
//= require swagger-ui/lib/handlebars-1.0.0.js
//= require swagger-ui/lib/underscore-min.js
//= require swagger-ui/lib/backbone-min.js
//= require swagger-ui/lib/swagger.js
//= require swagger-ui/lib/swagger-client.js
//= require swagger-ui/swagger-ui.min.js
//= require swagger-ui/lib/highlight.7.3.pack.js

View File

@ -12,4 +12,6 @@
*
*= require_tree .
*= require_self
*= require swagger-ui/reset.css
*= require swagger-ui/screen.css
*/

View File

@ -0,0 +1,14 @@
module SwaggerRails
class SwaggerDocsController < ApplicationController
def show
render file: swagger_file_path_for(params[:api_version]), layout: false
end
private
def swagger_file_path_for(api_version)
File.join(Rails.root, 'config', 'swagger', "#{api_version}.json")
end
end
end

View File

@ -0,0 +1,8 @@
module SwaggerRails
class SwaggerUiController < ApplicationController
def show
@discovery_url = request.path.gsub('/ui', '/docs/v1')
end
end
end

View File

@ -1,14 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>SwaggerRails</title>
<%= stylesheet_link_tag "swagger_rails/application", media: "all" %>
<%= javascript_include_tag "swagger_rails/application" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
%html
%head
%title SwaggerRails
%link{ href: '//fonts.googleapis.com/css?family=Droid+Sans:400,700', rel: 'stylesheet', type: 'text/css' }
=stylesheet_link_tag "swagger_rails/application"
=javascript_include_tag "swagger_rails/application"
=csrf_meta_tags
%body.swagger-section
=yield

View File

@ -0,0 +1,30 @@
#header
.swagger-ui-wrap
%a#logo{ href: 'http://swagger.io'} swagger
%form#api_selector
.input
%input#input_baseUrl{ name: 'baseUrl' }
.input
%input#input_apiKey{ name: 'apiKey' }
.input
%a#input_apiKey{ name: 'apiKey' }
#message-bar.swagger-ui-wrap
#swagger-ui-container.swagger-ui-wrap{ data: { discovery_url: @discovery_url } }
:coffeescript
window.swaggerUi = new SwaggerUi(
url: $('#swagger-ui-container').data('discoveryUrl')
dom_id: 'swagger-ui-container'
onComplete: (swaggerApi, swaggerUi) ->
log('Loaded SwaggerUi')
$('pre code').each (i, e) ->
hljs.highlighBlock(e)
onFailure: (data) ->
log('Unable to load Swagger UI')
docExpansion: 'none'
sorter: 'alpha'
)
window.swaggerUi.load()

View File

@ -1,2 +1,5 @@
SwaggerRails::Engine.routes.draw do
get '/ui', to: 'swagger_ui#show'
get '/docs/:api_version', to: 'swagger_docs#show'
end

View File

@ -1,3 +1,6 @@
require 'haml-rails'
require 'coffee-rails'
module SwaggerRails
class Engine < ::Rails::Engine
isolate_namespace SwaggerRails

View File

@ -0,0 +1,98 @@
{
"swagger": "2.0",
"info": {
"version": "0.0.0",
"title": "Dummy app for testing swagger_rails"
},
"paths": {
"/events": {
"post": {
"tags": [
"events"
],
"description": "Create a new Event",
"parameters": [
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/CreateEventBody"
}
}
],
"responses": {
"200": {
"description": "Ok"
}
}
}
}
},
"definitions": {
"CreateEventBody": {
"properties": {
"name": {
"type": "string"
},
"date_time": {
"type": "string",
"format": "date-time"
},
"repeat": {
"$ref": "#/definitions/EventRepeatOptions"
},
"notification": {
"$ref": "#/definitions/EventNotificationOptions"
}
}
},
"EventRepeatOptions": {
"properties": {
"frequency": {
"type": "string",
"enum": [
"daily"
]
},
"ending_on": {
"type": "string",
"format": "date-time"
}
}
},
"EventNotificationOptions": {
"properties": {
"intervals": {
"type": "array",
"items": {
"type": "integer",
"format": "int32"
}
},
"targets": {
"type": "array",
"items": {
"$ref": "#/definitions/NotificationTarget"
}
}
}
},
"NotificationTarget": {
"properties": {
"type": {
"type": "string",
"enum": [
"sms",
"email"
]
},
"phone": {
"type": "string"
},
"email": {
"type": "string"
}
}
}
}
}

View File

@ -9,12 +9,14 @@ Gem::Specification.new do |s|
s.version = SwaggerRails::VERSION
s.authors = ["domaindrivendev"]
s.email = ["domaindrivendev@gmail.com"]
s.homepage = "TODO"
s.summary = "TODO: Summary of SwaggerRails."
s.description = "TODO: Description of SwaggerRails."
s.homepage = "https://github.com/domaindrivendev/swagger-rails"
s.summary = "Seamlessly adds a Swagger to Rails-based API's"
s.description = "Seamlessly adds a Swagger to Rails-based API's"
s.license = "MIT"
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
s.add_dependency "rails", "~> 4.2.0"
s.add_dependency 'haml-rails'
s.add_dependency 'coffee-rails'
end

1
vendor/assets/javascripts/swagger-ui/lib vendored Symbolic link
View File

@ -0,0 +1 @@
../../../../swagger-ui/dist/lib

View File

@ -0,0 +1 @@
../../../../swagger-ui/dist/swagger-ui.min.js

View File

@ -0,0 +1 @@
../../../../swagger-ui/dist/css/reset.css

View File

@ -0,0 +1 @@
../../../../swagger-ui/dist/css/screen.css