swagger_ui_generator 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +69 -0
  6. data/Rakefile +23 -0
  7. data/lib/generators/swagger_ui_generator/install/install_generator.rb +22 -0
  8. data/lib/generators/swagger_ui_generator/install/templates/public/api-docs.html.erb +73 -0
  9. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/css/highlight.default.css +135 -0
  10. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/css/screen.css +1070 -0
  11. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/backbone-min.js +38 -0
  12. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/handlebars-1.0.0.js +2278 -0
  13. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/highlight.7.3.pack.js +1 -0
  14. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/jquery-1.8.0.min.js +2 -0
  15. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/jquery.ba-bbq.min.js +18 -0
  16. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/jquery.slideto.min.js +1 -0
  17. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/jquery.wiggle.min.js +8 -0
  18. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/shred.bundle.js +2765 -0
  19. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/shred/content.js +193 -0
  20. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/swagger.js +1311 -0
  21. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/underscore-min.js +32 -0
  22. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/swagger-ui.js +2129 -0
  23. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/throbber.gif +0 -0
  24. data/lib/swagger_ui_generator.rb +5 -0
  25. data/lib/swagger_ui_generator/importer.rb +97 -0
  26. data/lib/swagger_ui_generator/version.rb +3 -0
  27. data/swagger_ui_generator.gemspec +28 -0
  28. data/test/lib/generators/swagger_ui_generator/install_generator_test.rb +73 -0
  29. data/test/test_helper.rb +19 -0
  30. data/vendor/swagger-ui/.gitignore +22 -0
  31. data/vendor/swagger-ui/.npmignore +7 -0
  32. data/vendor/swagger-ui/Cakefile +132 -0
  33. data/vendor/swagger-ui/README.md +110 -0
  34. data/vendor/swagger-ui/dist/css/highlight.default.css +135 -0
  35. data/vendor/swagger-ui/dist/css/screen.css +1070 -0
  36. data/vendor/swagger-ui/dist/images/logo_small.png +0 -0
  37. data/vendor/swagger-ui/dist/images/pet_store_api.png +0 -0
  38. data/vendor/swagger-ui/dist/images/throbber.gif +0 -0
  39. data/vendor/swagger-ui/dist/images/wordnik_api.png +0 -0
  40. data/vendor/swagger-ui/dist/index.html +78 -0
  41. data/vendor/swagger-ui/dist/lib/backbone-min.js +38 -0
  42. data/vendor/swagger-ui/dist/lib/handlebars-1.0.0.js +2278 -0
  43. data/vendor/swagger-ui/dist/lib/highlight.7.3.pack.js +1 -0
  44. data/vendor/swagger-ui/dist/lib/jquery-1.8.0.min.js +2 -0
  45. data/vendor/swagger-ui/dist/lib/jquery.ba-bbq.min.js +18 -0
  46. data/vendor/swagger-ui/dist/lib/jquery.slideto.min.js +1 -0
  47. data/vendor/swagger-ui/dist/lib/jquery.wiggle.min.js +8 -0
  48. data/vendor/swagger-ui/dist/lib/shred.bundle.js +2765 -0
  49. data/vendor/swagger-ui/dist/lib/shred/content.js +193 -0
  50. data/vendor/swagger-ui/dist/lib/swagger.js +1311 -0
  51. data/vendor/swagger-ui/dist/lib/underscore-min.js +32 -0
  52. data/vendor/swagger-ui/dist/swagger-ui.js +2129 -0
  53. data/vendor/swagger-ui/dist/swagger-ui.min.js +1 -0
  54. data/vendor/swagger-ui/lib/backbone-min.js +38 -0
  55. data/vendor/swagger-ui/lib/handlebars-1.0.0.js +2278 -0
  56. data/vendor/swagger-ui/lib/highlight.7.3.pack.js +1 -0
  57. data/vendor/swagger-ui/lib/jquery-1.8.0.min.js +2 -0
  58. data/vendor/swagger-ui/lib/jquery.ba-bbq.min.js +18 -0
  59. data/vendor/swagger-ui/lib/jquery.slideto.min.js +1 -0
  60. data/vendor/swagger-ui/lib/jquery.wiggle.min.js +8 -0
  61. data/vendor/swagger-ui/lib/shred.bundle.js +2765 -0
  62. data/vendor/swagger-ui/lib/shred/content.js +193 -0
  63. data/vendor/swagger-ui/lib/swagger.js +1311 -0
  64. data/vendor/swagger-ui/lib/underscore-min.js +32 -0
  65. data/vendor/swagger-ui/package.json +26 -0
  66. data/vendor/swagger-ui/src/main/coffeescript/SwaggerUi.coffee +101 -0
  67. data/vendor/swagger-ui/src/main/coffeescript/view/ContentTypeView.coffee +14 -0
  68. data/vendor/swagger-ui/src/main/coffeescript/view/HeaderView.coffee +37 -0
  69. data/vendor/swagger-ui/src/main/coffeescript/view/MainView.coffee +18 -0
  70. data/vendor/swagger-ui/src/main/coffeescript/view/OperationView.coffee +318 -0
  71. data/vendor/swagger-ui/src/main/coffeescript/view/ParameterContentTypeView.coffee +14 -0
  72. data/vendor/swagger-ui/src/main/coffeescript/view/ParameterView.coffee +57 -0
  73. data/vendor/swagger-ui/src/main/coffeescript/view/ResourceView.coffee +21 -0
  74. data/vendor/swagger-ui/src/main/coffeescript/view/ResponseContentTypeView.coffee +14 -0
  75. data/vendor/swagger-ui/src/main/coffeescript/view/SignatureView.coffee +51 -0
  76. data/vendor/swagger-ui/src/main/coffeescript/view/StatusCodeView.coffee +11 -0
  77. data/vendor/swagger-ui/src/main/html/css/highlight.default.css +135 -0
  78. data/vendor/swagger-ui/src/main/html/css/screen.css +1070 -0
  79. data/vendor/swagger-ui/src/main/html/images/logo_small.png +0 -0
  80. data/vendor/swagger-ui/src/main/html/images/pet_store_api.png +0 -0
  81. data/vendor/swagger-ui/src/main/html/images/throbber.gif +0 -0
  82. data/vendor/swagger-ui/src/main/html/images/wordnik_api.png +0 -0
  83. data/vendor/swagger-ui/src/main/html/index.html +78 -0
  84. data/vendor/swagger-ui/src/main/javascript/doc.js +184 -0
  85. data/vendor/swagger-ui/src/main/less/reset.less +50 -0
  86. data/vendor/swagger-ui/src/main/less/screen.less +67 -0
  87. data/vendor/swagger-ui/src/main/less/specs.less +1004 -0
  88. data/vendor/swagger-ui/src/main/template/content_type.handlebars +10 -0
  89. data/vendor/swagger-ui/src/main/template/main.handlebars +22 -0
  90. data/vendor/swagger-ui/src/main/template/operation.handlebars +85 -0
  91. data/vendor/swagger-ui/src/main/template/param.handlebars +30 -0
  92. data/vendor/swagger-ui/src/main/template/param_list.handlebars +25 -0
  93. data/vendor/swagger-ui/src/main/template/param_readonly.handlebars +15 -0
  94. data/vendor/swagger-ui/src/main/template/param_readonly_required.handlebars +15 -0
  95. data/vendor/swagger-ui/src/main/template/param_required.handlebars +31 -0
  96. data/vendor/swagger-ui/src/main/template/parameter_content_type.handlebars +10 -0
  97. data/vendor/swagger-ui/src/main/template/resource.handlebars +27 -0
  98. data/vendor/swagger-ui/src/main/template/response_content_type.handlebars +10 -0
  99. data/vendor/swagger-ui/src/main/template/signature.handlebars +18 -0
  100. data/vendor/swagger-ui/src/main/template/status_code.handlebars +2 -0
  101. data/vendor/swagger-ui/src/test/spec.html +26 -0
  102. data/vendor/swagger-ui/src/test/swagger-ui-spec.coffee +49 -0
  103. data/vendor/swagger-ui/swagger-ui.json +20 -0
  104. metadata +240 -0
@@ -0,0 +1,5 @@
1
+ require "swagger_ui_generator/version"
2
+
3
+ module SwaggerUiGenerator
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,97 @@
1
+ require 'fileutils'
2
+ require 'nokogiri'
3
+
4
+ module SwaggerUiGenerator
5
+ class Importer
6
+ def import
7
+ cleanup
8
+ ensure_directory_structure
9
+ copy_dependencies
10
+ generate_template
11
+ end
12
+
13
+ def cleanup
14
+ FileUtils.rm_rf Dir[destination_path("**/*")]
15
+ end
16
+
17
+ def ensure_directory_structure
18
+ FileUtils.mkdir_p destination_path("public/swagger")
19
+ end
20
+
21
+ def copy_dependencies
22
+ generate_script_with_custom_throbber_path
23
+
24
+ %w( lib css ).each do |dir|
25
+ src = source_path("#{ dir }/*")
26
+ dst = destination_path("public/swagger/#{ dir }")
27
+
28
+ FileUtils.mkdir_p dst
29
+ FileUtils.cp_r Dir[src], dst
30
+ end
31
+
32
+ FileUtils.cp source_path("images/throbber.gif"), destination_path("public/swagger")
33
+ end
34
+
35
+ def generate_script_with_custom_throbber_path
36
+ script = IO.read(source_path('swagger-ui.js')).gsub(%r{'images/throbber.gif'}, "'/swagger/throbber.gif'")
37
+ File.open(destination_path("public/swagger/swagger-ui.js"), 'w') do |js|
38
+ js.write script
39
+ end
40
+ end
41
+
42
+ def generate_template
43
+ ui_doc.at('title').content = "__@title__"
44
+
45
+ script_el = ui_doc.at('script:not([src])')
46
+ script = script_el.content.split(/\n/).map do |line|
47
+ if line =~ /url:\s*"http/
48
+ ' url: window.location.protocol + "//" + window.location.host + "__@api_spec_path__",'
49
+ else
50
+ line
51
+ end
52
+ end
53
+ script_el.native_content = script.join("\n")
54
+
55
+ (ui_doc / 'script[src]').each do |el|
56
+ el['src'] = "/swagger/#{ el['src'] }"
57
+ end
58
+
59
+ (ui_doc / 'link[rel="stylesheet"]').each do |el|
60
+ el['href'] = "/swagger/#{ el['href'] }" if el['href'].start_with? 'css'
61
+ end
62
+
63
+ ui_doc.at('a#logo').remove
64
+ (ui_doc / 'form#api_selector .icon-btn').each { |el| el.remove }
65
+
66
+ File.open(destination_path("public/api-docs.html.erb"), 'w') do |out|
67
+ out.write ui_doc.to_xhtml(indent:2, indent_text:" ").gsub(/__(.*)__/, '<%= \1 %>')
68
+ end
69
+ end
70
+
71
+ def source_path(path)
72
+ source_base.join(path)
73
+ end
74
+
75
+ def destination_path(path)
76
+ destination_base.join(path)
77
+ end
78
+
79
+ private
80
+
81
+ def ui_doc
82
+ @ui_doc ||= Nokogiri::HTML(IO.read(source_path("index.html")).gsub("\r\n", "\n"))
83
+ end
84
+
85
+ def source_base
86
+ @src ||= relative_path("../../../vendor/swagger-ui/dist")
87
+ end
88
+
89
+ def destination_base
90
+ @dst ||= relative_path("../../generators/swagger_ui_generator/install/templates")
91
+ end
92
+
93
+ def relative_path(path)
94
+ Pathname.new(File.expand_path(path, __FILE__))
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,3 @@
1
+ module SwaggerUiGenerator
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'swagger_ui_generator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "swagger_ui_generator"
8
+ spec.version = SwaggerUiGenerator::VERSION
9
+ spec.authors = ["Solomon White"]
10
+ spec.email = ["rubysolo@gmail.com"]
11
+ spec.summary = %q{Swagger UI Generator}
12
+ spec.description = %q{Rails generator to build Swagger UI API doc viewer}
13
+ spec.homepage = "http://github.com/rubysolo/swagger_ui_generator"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "pry-nav"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rails", ">= 3.1"
25
+
26
+ spec.add_runtime_dependency "railties", ">= 3.1"
27
+ spec.add_runtime_dependency "nokogiri"
28
+ end
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+ require 'generators/swagger_ui_generator/install/install_generator'
3
+ require 'nokogiri'
4
+
5
+ class InstallGeneratorTest < Rails::Generators::TestCase
6
+ tests SwaggerUiGenerator::Generators::InstallGenerator
7
+ destination Rails.root
8
+
9
+ setup :prepare_destination
10
+
11
+ test "generates swagger ui app" do
12
+ run_generator
13
+
14
+ assert_file "public/swagger/swagger-ui.js"
15
+ assert_file "public/api-docs.html", %r{/swagger/swagger-ui.js}
16
+
17
+ css_files = %w(
18
+ highlight.default.css
19
+ screen.css
20
+ )
21
+
22
+ css_files.each do |css|
23
+ assert_file "public/swagger/css/#{ css }"
24
+ assert_file "public/api-docs.html", %r{/swagger/css/#{ css }}
25
+ end
26
+
27
+ js_files = %w(
28
+ shred.bundle.js
29
+ jquery-1.8.0.min.js
30
+ jquery.slideto.min.js
31
+ jquery.wiggle.min.js
32
+ jquery.ba-bbq.min.js
33
+ handlebars-1.0.0.js
34
+ underscore-min.js
35
+ backbone-min.js
36
+ swagger.js
37
+ highlight.7.3.pack.js
38
+ )
39
+
40
+ js_files.each do |js|
41
+ assert_file "public/swagger/lib/#{ js }"
42
+ assert_file "public/api-docs.html", %r{/swagger/lib/#{ js }}
43
+ end
44
+ end
45
+
46
+ test "uses default location for @api_spec_path" do
47
+ run_generator
48
+ assert_file "public/api-docs.html", %r{window\.location\.host \+ "/swagger/api-docs.json"}
49
+ end
50
+
51
+ test "uses custom location for @api_spec_path" do
52
+ run_generator %w(--api-spec-path /api/v2/docs.json)
53
+ assert_file "public/api-docs.html", %r{window\.location\.host \+ "/api/v2/docs.json"}
54
+ end
55
+
56
+ test "does not modify font stylesheet" do
57
+ run_generator
58
+ assert_file "public/api-docs.html" do |html|
59
+ doc = Nokogiri::HTML(html)
60
+ css_hrefs = (doc / 'link[rel="stylesheet"]').map { |el| el['href'] }
61
+ font_href = css_hrefs.reject { |href| href.start_with? '/swagger' }.first
62
+
63
+ assert font_href
64
+ assert_equal 'https://fonts.googleapis.com/css?family=Droid+Sans:400,700', font_href
65
+ end
66
+ end
67
+
68
+ test 'imports the throbber gif and modifies the path appropriately' do
69
+ run_generator
70
+ assert_file "public/swagger/throbber.gif"
71
+ assert_file "public/swagger/swagger-ui.js", %r{'/swagger/throbber.gif'}
72
+ end
73
+ end
@@ -0,0 +1,19 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require 'test/unit'
5
+ require 'rails/all'
6
+ require 'rails/generators'
7
+ require 'rails/generators/test_case'
8
+
9
+ class TestApp < Rails::Application
10
+ config.root = File.dirname(__FILE__)
11
+ end
12
+ Rails.application = TestApp
13
+
14
+ module Rails
15
+ def self.root
16
+ @root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'rails'))
17
+ end
18
+ end
19
+ Rails.application.config.root = Rails.root
@@ -0,0 +1,22 @@
1
+ wordnik*.zip
2
+ .DS_STORE
3
+ *.ipr
4
+ *.iml
5
+ *.iws
6
+ lib/*.jar
7
+ META-INF/
8
+ web/
9
+ index
10
+ lib/*.zip
11
+ dk/
12
+ index_dict
13
+ logs
14
+ src/main/java/com/wordnik/env/Version.scala
15
+ lib/*.pom
16
+ version.properties
17
+ reports/*
18
+ .sass-cache
19
+ swagger-ui.sublime-workspace
20
+ .idea
21
+ .project
22
+ node_modules/*
@@ -0,0 +1,7 @@
1
+ *.sublime-*
2
+ example.html
3
+ *.tgz
4
+ .classpath
5
+ .project
6
+ .npmignore
7
+ node_modules
@@ -0,0 +1,132 @@
1
+ fs = require 'fs'
2
+ path = require 'path'
3
+ {exec} = require 'child_process'
4
+ less = require 'less'
5
+
6
+ sourceFiles = [
7
+ 'SwaggerUi'
8
+ 'view/HeaderView'
9
+ 'view/MainView'
10
+ 'view/ResourceView'
11
+ 'view/OperationView'
12
+ 'view/StatusCodeView'
13
+ 'view/ParameterView'
14
+ 'view/SignatureView'
15
+ 'view/ContentTypeView'
16
+ 'view/ResponseContentTypeView'
17
+ 'view/ParameterContentTypeView'
18
+ ]
19
+
20
+
21
+ task 'clean', 'Removes distribution', ->
22
+ console.log 'Clearing dist...'
23
+ exec 'rm -rf dist'
24
+
25
+ task 'dist', 'Build a distribution', ->
26
+ console.log "Build distribution in ./dist"
27
+ fs.mkdirSync('dist') if not path.existsSync('dist')
28
+ fs.mkdirSync('dist/lib') if not path.existsSync('dist/lib')
29
+
30
+ appContents = new Array remaining = sourceFiles.length
31
+ for file, index in sourceFiles then do (file, index) ->
32
+ console.log " : Reading src/main/coffeescript/#{file}.coffee"
33
+ fs.readFile "src/main/coffeescript/#{file}.coffee", 'utf8', (err, fileContents) ->
34
+ throw err if err
35
+ appContents[index] = fileContents
36
+ precompileTemplates() if --remaining is 0
37
+
38
+ precompileTemplates= ->
39
+ console.log ' : Precompiling templates...'
40
+ templateFiles = fs.readdirSync('src/main/template')
41
+ templateContents = new Array remaining = templateFiles.length
42
+ for file, index in templateFiles then do (file, index) ->
43
+ console.log " : Compiling src/main/template/#{file}"
44
+ exec "handlebars src/main/template/#{file} -f dist/_#{file}.js", (err, stdout, stderr) ->
45
+ throw err if err
46
+ fs.readFile 'dist/_' + file + '.js', 'utf8', (err, fileContents) ->
47
+ throw err if err
48
+ templateContents[index] = fileContents
49
+ fs.unlink 'dist/_' + file + '.js'
50
+ if --remaining is 0
51
+ templateContents.push '\n\n'
52
+ fs.writeFile 'dist/_swagger-ui-templates.js', templateContents.join('\n\n'), 'utf8', (err) ->
53
+ throw err if err
54
+ build()
55
+
56
+
57
+ build = ->
58
+ console.log ' : Collecting Coffeescript source...'
59
+
60
+ appContents.push '\n\n'
61
+ fs.writeFile 'dist/_swagger-ui.coffee', appContents.join('\n\n'), 'utf8', (err) ->
62
+ throw err if err
63
+ console.log ' : Compiling...'
64
+ exec 'coffee --compile dist/_swagger-ui.coffee', (err, stdout, stderr) ->
65
+ throw err if err
66
+ fs.unlink 'dist/_swagger-ui.coffee'
67
+ console.log ' : Combining with javascript...'
68
+ exec 'cat src/main/javascript/doc.js dist/_swagger-ui-templates.js dist/_swagger-ui.js > dist/swagger-ui.js', (err, stdout, stderr) ->
69
+ throw err if err
70
+ fs.unlink 'dist/_swagger-ui.js'
71
+ fs.unlink 'dist/_swagger-ui-templates.js'
72
+ console.log ' : Minifying all...'
73
+ exec 'java -jar "./bin/yuicompressor-2.4.7.jar" --type js -o ' + 'dist/swagger-ui.min.js ' + 'dist/swagger-ui.js', (err, stdout, stderr) ->
74
+ throw err if err
75
+ lessc()
76
+
77
+ lessc = ->
78
+ # Someone who knows CoffeeScript should make this more Coffee-licious
79
+ console.log ' : Compiling LESS...'
80
+
81
+ less.render fs.readFileSync("src/main/less/screen.less", 'utf8'), (err, css) ->
82
+ console.log err
83
+ fs.writeFileSync("src/main/html/css/screen.css", css)
84
+ pack()
85
+
86
+ pack = ->
87
+ console.log ' : Packaging...'
88
+ exec 'cp -r lib dist'
89
+ console.log ' : Copied swagger-ui libs'
90
+ exec 'cp -r node_modules/swagger-client/lib/swagger.js dist/lib'
91
+ console.log ' : Copied swagger dependencies'
92
+ exec 'cp -r src/main/html/* dist'
93
+ console.log ' : Copied html dependencies'
94
+ console.log ' !'
95
+
96
+ task 'spec', "Run the test suite", ->
97
+ exec "open spec.html", (err, stdout, stderr) ->
98
+ throw err if err
99
+
100
+ task 'watch', 'Watch source files for changes and autocompile', ->
101
+ # Function which watches all files in the passed directory
102
+ watchFiles = (dir) ->
103
+ files = fs.readdirSync(dir)
104
+ for file, index in files then do (file, index) ->
105
+ console.log " : " + dir + "/#{file}"
106
+ fs.watchFile dir + "/#{file}", (curr, prev) ->
107
+ if +curr.mtime isnt +prev.mtime
108
+ invoke 'dist'
109
+
110
+ notify "Watching source files for changes..."
111
+
112
+ # Watch specific source files
113
+ for file, index in sourceFiles then do (file, index) ->
114
+ console.log " : " + "src/main/coffeescript/#{file}.coffee"
115
+ fs.watchFile "src/main/coffeescript/#{file}.coffee", (curr, prev) ->
116
+ if +curr.mtime isnt +prev.mtime
117
+ invoke 'dist'
118
+
119
+ # watch all files in these folders
120
+ watchFiles("src/main/template")
121
+ watchFiles("src/main/javascript")
122
+ watchFiles("src/main/html")
123
+ watchFiles("src/main/less")
124
+ watchFiles("src/test")
125
+
126
+ notify = (message) ->
127
+ return unless message?
128
+ console.log message
129
+ # options =
130
+ # title: 'CoffeeScript'
131
+ # image: 'bin/CoffeeScript.png'
132
+ # try require('growl') message, options
@@ -0,0 +1,110 @@
1
+ Swagger UI
2
+ ==========
3
+
4
+ Swagger UI is part of [Swagger](http://swagger.wordnik.com/) project. The Swagger project allows you to produce, visualize and consume your OWN RESTful services. No proxy or 3rd party services required. Do it your own way.
5
+
6
+ Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically
7
+ generate beautiful documentation and sandbox from a [Swagger-compliant](https://github.com/wordnik/swagger-core/wiki) API. Because Swagger UI has no dependencies, you can host it in any server environment, or on your local machine.
8
+
9
+ How to Use It
10
+ -------------
11
+
12
+ ### Download
13
+ You can use the swagger-ui code AS-IS! No need to build or recompile--just clone this repo and use the pre-built files in the `dist` folder. If you like swagger-ui as-is, stop here.
14
+
15
+ ### Build
16
+ You can rebuild swagger-ui on your own to tweak it or just so you can say you did. To do so, follow these steps:
17
+
18
+ 1. install [handlebars](http://handlebarsjs.com/)
19
+ 2. install java
20
+ 3. npm install
21
+ 4. npm run-script build
22
+ 5. You should see the distribution under the dist folder. Open ./dist/index.html to launch Swagger UI in a browser
23
+
24
+ ### Use
25
+ Once you open the Swagger UI, it will load the [Swagger Petstore](http://petstore.swagger.wordnik.com/api/api-docs) service and show its APIs. You can enter your own server url and click explore to view the API.
26
+
27
+ ### Customize
28
+ You may choose to customize Swagger UI for your organization. Here is an overview of whats in its various directories:
29
+
30
+ - dist: Contains a distribution which you can deploy on a server or load from your local machine.
31
+ - bin: Contains files used by swagger-ui for its build/test. These are not required by the distribution.
32
+ - lib: Contains javascript dependencies which swagger-ui depends on
33
+ - node_modules: Contains node modules which swagger-ui uses for its development.
34
+ - src
35
+ - src/main/coffeescript: main code in CoffeeScript
36
+ - src/main/templates: [handlebars](http://handlebarsjs.com/) templates used to render swagger-ui
37
+ - src/main/html: the html files, some images and css
38
+ - src/main/javascript: some legacy javascript referenced by CoffeeScript code
39
+
40
+ ### SwaggerUi
41
+ To use swagger-ui you should take a look at the [source of swagger-ui html page](https://github.com/wordnik/swagger-ui/tree/master/src/main/html) and customize it. This basically requires you to instantiate a SwaggerUi object and call load() on it as below:
42
+
43
+ ```javascript
44
+ window.swaggerUi = new SwaggerUi({
45
+ url:"http://petstore.swagger.wordnik.com/api/api-docs",
46
+ dom_id:"swagger-ui-container"
47
+ });
48
+
49
+ window.swaggerUi.load();
50
+ ```
51
+ * *url* parameter should point to a resource listing url as per [Swagger Spec](https://github.com/wordnik/swagger-core/wiki)
52
+ * *dom_id parameter* is the the id of a dom element inside which SwaggerUi will put the user interface for swagger
53
+ * *booleanValues* SwaggerUI renders boolean data types as a dropdown. By default it provides a 'true' and 'false' string as the possible choices. You can use this parameter to change the values in dropdown to be something else, for example 0 and 1 by setting booleanValues to new Array(0, 1)
54
+ * *docExpansion* controls how the API listing is displayed. It can be set to 'none' (default), 'list' (shows operations for each resource), or 'full' (fully expanded: shows operations and their details)
55
+ * *onComplete* is a callback function parameter which can be passed to be notified of when SwaggerUI has completed rendering successfully.
56
+ * *onFailure* is a callback function parameter which can be passed to be notified of when SwaggerUI encountered a failure was unable to render.
57
+ * All other parameters are explained in greater detail below
58
+
59
+
60
+ ### HTTP Methods and API Invocation
61
+ swagger-ui supports invocation of all HTTP methods APIs including GET, PUT, POST, DELETE, PATCH, OPTIONS. These are handled in the [swagger-js](https://github.com/wordnik/swagger-js) project, please see there for specifics on their usage.
62
+
63
+
64
+ ### Header Parameters
65
+ Header params are supported through a pluggable mechanism in [swagger-js](https://github.com/wordnik/swagger-js). You can see the [index.html](https://github.com/wordnik/swagger-ui/blob/master/dist/index.html) for a sample of how to dynamically set headers:
66
+
67
+ ```js
68
+ // add a new ApiKeyAuthorization when the api-key changes in the ui.
69
+ $('#input_apiKey').change(function() {
70
+ var key = $('#input_apiKey')[0].value;
71
+ if(key && key.trim() != "") {
72
+ window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "header"));
73
+ }
74
+ })
75
+ ```
76
+
77
+ This will add header `api_key` with value `key` on every call to the server. You can substitute `query` to send the values as a query param.
78
+
79
+ ### Custom Header Parameters - (For Basic auth etc)
80
+ If you have some header parameters which you need to send with every request, use the headers as below:
81
+
82
+ ```js
83
+ window.authorizations.add("key", new ApiKeyAuthorization("Authorization", "XXXX", "header"));
84
+ ```
85
+
86
+ Note! You can pass multiple header params on a single request, just use unique names for them (`key` is used in the above example).
87
+
88
+ How to Improve It
89
+ -----------------
90
+
91
+ Create your own fork of [wordnik/swagger-ui](https://github.com/wordnik/swagger-ui)
92
+
93
+ To share your changes, [submit a pull request](https://github.com/wordnik/swagger-ui/pull/new/master).
94
+
95
+ Since the javascript files are compiled from coffeescript, please submit changes in the *.coffee files! We have to reject changes only in the .js files as they will be lost on each build of the ui.
96
+
97
+ License
98
+ -------
99
+
100
+ Copyright 2011-2013 Wordnik, Inc.
101
+
102
+ Licensed under the Apache License, Version 2.0 (the "License");
103
+ you may not use this file except in compliance with the License.
104
+ You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
105
+
106
+ Unless required by applicable law or agreed to in writing, software
107
+ distributed under the License is distributed on an "AS IS" BASIS,
108
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
109
+ See the License for the specific language governing permissions and
110
+ limitations under the License.