swagger_rails 1.0.0.pre.beta → 1.0.0.pre.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/swagger_rails/swagger_ui_controller.rb +1 -1
- data/lib/generators/swagger_rails/install/install_generator.rb +1 -1
- data/lib/generators/swagger_rails/install/templates/swagger_rails.rb +7 -4
- data/lib/swagger_rails.rb +20 -11
- data/lib/swagger_rails/engine.rb +1 -1
- data/lib/swagger_rails/rspec/dsl.rb +10 -2
- data/lib/swagger_rails/rspec/formatter.rb +18 -9
- data/lib/swagger_rails/test_visitor.rb +5 -3
- data/lib/swagger_rails/version.rb +1 -1
- data/lib/tasks/swagger_rails_tasks.rake +2 -1
- metadata +8 -11
- data/lib/generators/swagger_rails/install/templates/swagger.json +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92af79c8cb42efd72ea5b79b5b8f0979d9bc0bfa
|
4
|
+
data.tar.gz: 04b02dc891f0bc7843d8b02c442fcff10e0bb8f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab65f619c9007bcb3d6e6b45c1c205f3fa8f47f1a60a0a4d82fdb9059f720591bf54b830afab08c57ff1434bfeb2d9e11aab47d4c0f2a7eec9b3636d3f7b4093
|
7
|
+
data.tar.gz: ca6014484ff29a056c1c2f009580843e5a665872e33094c549bdfa02fd53d6701e4f7c2a124678210b552ab447964a9f58848a5409a57314e26bc7ca083e13eb
|
@@ -1,13 +1,16 @@
|
|
1
1
|
SwaggerRails.configure do |c|
|
2
2
|
|
3
|
-
# Define your swagger documents and provide global metadata
|
4
|
-
#
|
5
|
-
c.swagger_doc 'v1/swagger.json'
|
3
|
+
# Define your swagger documents and provide any global metadata here
|
4
|
+
# (Individual operations are generated from your spec/test files)
|
5
|
+
c.swagger_doc 'v1/swagger.json',
|
6
6
|
{
|
7
|
+
swagger: '2.0',
|
7
8
|
info: {
|
8
9
|
title: 'API V1',
|
9
10
|
version: 'v1'
|
10
11
|
}
|
11
12
|
}
|
12
|
-
|
13
|
+
|
14
|
+
# Specify a location to output generated swagger files
|
15
|
+
c.swagger_dir File.expand_path('../../../swagger', __FILE__)
|
13
16
|
end
|
data/lib/swagger_rails.rb
CHANGED
@@ -2,23 +2,32 @@ require "swagger_rails/engine"
|
|
2
2
|
|
3
3
|
module SwaggerRails
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
class Configuration
|
6
|
+
attr_reader :swagger_docs, :swagger_dir_string
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@swagger_docs = {}
|
10
|
+
@swagger_dir_string = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def swagger_doc(path, doc)
|
14
|
+
@swagger_docs[path] = doc
|
15
|
+
end
|
16
|
+
|
17
|
+
def swagger_dir(dir_string)
|
18
|
+
@swagger_dir_string = dir_string
|
19
|
+
end
|
7
20
|
end
|
8
21
|
|
9
22
|
class << self
|
10
|
-
|
23
|
+
attr_reader :config
|
11
24
|
|
12
|
-
def
|
13
|
-
|
25
|
+
def configure
|
26
|
+
yield config
|
14
27
|
end
|
15
28
|
|
16
|
-
def
|
17
|
-
|
18
|
-
@@swagger_docs.map do |path, factory|
|
19
|
-
[ path, factory.call.merge(swagger: '2.0') ]
|
20
|
-
end
|
21
|
-
]
|
29
|
+
def config
|
30
|
+
@config ||= Configuration.new
|
22
31
|
end
|
23
32
|
end
|
24
33
|
end
|
data/lib/swagger_rails/engine.rb
CHANGED
@@ -6,7 +6,7 @@ module SwaggerRails
|
|
6
6
|
isolate_namespace SwaggerRails
|
7
7
|
|
8
8
|
initializer 'swagger_rails.initialize' do |app|
|
9
|
-
middleware.use SwaggerDocs,
|
9
|
+
middleware.use SwaggerDocs, SwaggerRails.config.swagger_dir_string
|
10
10
|
middleware.use SwaggerUi, "#{root}/bower_components/swagger-ui/dist"
|
11
11
|
end
|
12
12
|
end
|
@@ -49,12 +49,20 @@ module SwaggerRails
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def run_test!
|
52
|
+
if metadata.has_key?(:swagger_doc)
|
53
|
+
swagger_doc = SwaggerRails.config.swagger_docs[metadata[:swagger_doc]]
|
54
|
+
else
|
55
|
+
swagger_doc = SwaggerRails.config.swagger_docs.values.first
|
56
|
+
end
|
57
|
+
|
58
|
+
test_visitor = SwaggerRails::TestVisitor.new(swagger_doc)
|
59
|
+
|
52
60
|
before do |example|
|
53
|
-
|
61
|
+
test_visitor.submit_request!(self, example.metadata)
|
54
62
|
end
|
55
63
|
|
56
64
|
it "returns a #{metadata[:response_code]} status" do |example|
|
57
|
-
|
65
|
+
test_visitor.assert_response!(self, example.metadata)
|
58
66
|
end
|
59
67
|
end
|
60
68
|
end
|
@@ -9,9 +9,10 @@ module SwaggerRails
|
|
9
9
|
:example_group_finished,
|
10
10
|
:stop
|
11
11
|
|
12
|
-
def initialize(output)
|
12
|
+
def initialize(output, config=SwaggerRails.config)
|
13
13
|
@output = output
|
14
|
-
@swagger_docs =
|
14
|
+
@swagger_docs = config.swagger_docs
|
15
|
+
@swagger_dir_string = config.swagger_dir_string
|
15
16
|
|
16
17
|
@output.puts 'Generating Swagger Docs ...'
|
17
18
|
end
|
@@ -20,14 +21,14 @@ module SwaggerRails
|
|
20
21
|
metadata = notification.group.metadata
|
21
22
|
return unless metadata.has_key?(:response_code)
|
22
23
|
|
24
|
+
swagger_doc = @swagger_docs[metadata[:swagger_doc]] || @swagger_docs.values.first
|
23
25
|
swagger_data = swagger_data_from(metadata)
|
24
|
-
swagger_doc = @swagger_docs[metadata[:docs_path]] || @swagger_docs.values.first
|
25
26
|
swagger_doc.deep_merge!(swagger_data)
|
26
27
|
end
|
27
28
|
|
28
29
|
def stop(notification)
|
29
30
|
@swagger_docs.each do |path, doc|
|
30
|
-
file_path = File.join(
|
31
|
+
file_path = File.join(@swagger_dir_string, path)
|
31
32
|
|
32
33
|
File.open(file_path, 'w') do |file|
|
33
34
|
file.write(JSON.pretty_generate(doc))
|
@@ -50,11 +51,19 @@ module SwaggerRails
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def operation_from(metadata)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
{
|
55
|
+
tags: [ find_root_of(metadata)[:description] ] ,
|
56
|
+
summary: metadata[:summary],
|
57
|
+
consumes: metadata[:consumes],
|
58
|
+
produces: metadata[:produces],
|
59
|
+
parameters: metadata[:parameters],
|
60
|
+
responses: { metadata[:response_code] => metadata[:response] }
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def find_root_of(metadata)
|
65
|
+
parent = metadata[:parent_example_group]
|
66
|
+
parent.nil? ? metadata : find_root_of(parent)
|
58
67
|
end
|
59
68
|
end
|
60
69
|
end
|
@@ -1,8 +1,9 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
1
|
module SwaggerRails
|
4
2
|
class TestVisitor
|
5
|
-
|
3
|
+
|
4
|
+
def initialize(swagger_doc)
|
5
|
+
@swagger_doc = swagger_doc
|
6
|
+
end
|
6
7
|
|
7
8
|
def submit_request!(test, metadata)
|
8
9
|
params_data = params_data_for(test, metadata[:parameters])
|
@@ -35,6 +36,7 @@ module SwaggerRails
|
|
35
36
|
path_params_data.each do |param_data|
|
36
37
|
path.sub!("\{#{param_data[:name]}\}", param_data[:value].to_s)
|
37
38
|
end
|
39
|
+
path.prepend(@swagger_doc[:basePath] || '')
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
@@ -4,9 +4,10 @@
|
|
4
4
|
# end
|
5
5
|
|
6
6
|
require 'rspec/core/rake_task'
|
7
|
+
require 'swagger_rails'
|
7
8
|
|
8
9
|
desc 'Generate Swagger JSON files from integration specs'
|
9
10
|
RSpec::Core::RakeTask.new('swaggerize') do |t|
|
10
|
-
t.pattern = 'spec/integration/**/*_spec.rb'
|
11
|
+
t.pattern = 'spec/requests/**/*_spec.rb, spec/api/**/*_spec.rb, spec/integration/**/*_spec.rb'
|
11
12
|
t.rspec_opts = [ '--format SwaggerRails::RSpec::Formatter', '--dry-run' ]
|
12
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.
|
4
|
+
version: 1.0.0.pre.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- domaindrivendev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -44,12 +44,10 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '3.0'
|
47
|
-
description: Use the provided DSL to
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
Best of all, it requires minimal coding and maintenance, allowing you to focus on
|
52
|
-
building an awesome API!
|
47
|
+
description: Use the provided DSL to describe and test API operations in your spec
|
48
|
+
files. Then, you can easily generate corresponding swagger.json files and serve
|
49
|
+
them up with an embedded version of swagger-ui. Best of all, it requires minimal
|
50
|
+
coding and maintenance, allowing you to focus on building an awesome API!
|
53
51
|
email:
|
54
52
|
- domaindrivendev@gmail.com
|
55
53
|
executables: []
|
@@ -112,7 +110,6 @@ files:
|
|
112
110
|
- lib/generators/swagger_rails/custom_ui/files/index.html.erb
|
113
111
|
- lib/generators/swagger_rails/install/USAGE
|
114
112
|
- lib/generators/swagger_rails/install/install_generator.rb
|
115
|
-
- lib/generators/swagger_rails/install/templates/swagger.json
|
116
113
|
- lib/generators/swagger_rails/install/templates/swagger_rails.rb
|
117
114
|
- lib/swagger_rails.rb
|
118
115
|
- lib/swagger_rails/engine.rb
|
@@ -146,7 +143,7 @@ rubyforge_project:
|
|
146
143
|
rubygems_version: 2.4.8
|
147
144
|
signing_key:
|
148
145
|
specification_version: 4
|
149
|
-
summary:
|
150
|
-
|
146
|
+
summary: Generate API documentation, including a slick discovery/playground UI, directly
|
147
|
+
from your rspec integration specs
|
151
148
|
test_files: []
|
152
149
|
has_rdoc:
|
@@ -1,45 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"swagger": "2.0",
|
3
|
-
"info": {
|
4
|
-
"version": "0.0.0",
|
5
|
-
"title": "[Enter a description for your API here]",
|
6
|
-
"description": "The docs below are powered by the default swagger.json that gets installed with swagger_rails. You'll need to update it to describe your API. See here for the complete swagger spec - https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md"
|
7
|
-
},
|
8
|
-
"paths": {
|
9
|
-
"/a/sample/resource": {
|
10
|
-
"post": {
|
11
|
-
"tags": [
|
12
|
-
"a/sample/resource"
|
13
|
-
],
|
14
|
-
"description": "Create a new sample resource",
|
15
|
-
"parameters": [
|
16
|
-
{
|
17
|
-
"name": "body",
|
18
|
-
"in": "body",
|
19
|
-
"schema": {
|
20
|
-
"$ref": "#/definitions/CreateSampleResource"
|
21
|
-
}
|
22
|
-
}
|
23
|
-
],
|
24
|
-
"responses": {
|
25
|
-
"200": {
|
26
|
-
"description": "Ok"
|
27
|
-
}
|
28
|
-
}
|
29
|
-
}
|
30
|
-
}
|
31
|
-
},
|
32
|
-
"definitions": {
|
33
|
-
"CreateSampleResource": {
|
34
|
-
"properties": {
|
35
|
-
"name": {
|
36
|
-
"type": "string"
|
37
|
-
},
|
38
|
-
"date_time": {
|
39
|
-
"type": "string",
|
40
|
-
"format": "date-time"
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
44
|
-
}
|
45
|
-
}
|