rspec-autoswagger 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +16 -1
- data/lib/rspec/autoswagger/doc_part.rb +2 -2
- data/lib/rspec/autoswagger/doc_parts.rb +14 -5
- data/lib/rspec/autoswagger/parts/definition.rb +5 -8
- data/lib/rspec/autoswagger/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 302ecdd5721c0173610c7abc72cd969207e8a1c23e4c7197198e25981c5ad1e3
|
4
|
+
data.tar.gz: e93566f8824054de7f903f3756b26ae8cc192526237ce43dbe4cc9fda01045ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d11145237110fabf1892972efbf1ab7902825de094f55f1418d8a8d8bdc330c0b33359e9ef04877acc2eb83d293ea6570de422effc5db0601990c3e77e59cb4
|
7
|
+
data.tar.gz: e910706c4e656eb280ae13a19852dcafae51bdf8a02fe28ccda2b803dd59c6c63c3e565fea92ca18f8309a041898925c25f4d1f2e124908a8d76fb54dea874d6
|
data/README.md
CHANGED
@@ -22,7 +22,22 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
```
|
26
|
+
# spec/requests/book_spec.rb
|
27
|
+
describe "Books" do
|
28
|
+
describe "POST /books", autoswagger: true do
|
29
|
+
let(:description) { 'Create New Book' }
|
30
|
+
it "create a new book" do
|
31
|
+
post "/books", name: "little bear", type: 1
|
32
|
+
expect(response.status).to eq 200
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
```
|
39
|
+
AUTOSWAGGER=1 bundle exec rspec
|
40
|
+
```
|
26
41
|
|
27
42
|
## Development
|
28
43
|
|
@@ -22,8 +22,8 @@ module Rspec
|
|
22
22
|
path.generate_hash
|
23
23
|
end
|
24
24
|
|
25
|
-
def create_definition
|
26
|
-
definition = Parts::Definition.new(rspec_core_obj.response.body, response_name)
|
25
|
+
def create_definition(output_path = nil)
|
26
|
+
definition = Parts::Definition.new(rspec_core_obj.response.body, response_name, output_path)
|
27
27
|
definition.generate_definitions
|
28
28
|
end
|
29
29
|
end
|
@@ -1,8 +1,13 @@
|
|
1
1
|
require 'rspec/autoswagger/doc_part'
|
2
|
-
module Rspec
|
2
|
+
module Rspec
|
3
|
+
module Autoswagger
|
3
4
|
class DocParts
|
4
5
|
|
5
6
|
attr_reader :specification, :info, :paths, :definitions
|
7
|
+
attr_accessor :output_path
|
8
|
+
|
9
|
+
DEFAULT_OUTPUT_PATH = './tmp'
|
10
|
+
|
6
11
|
def initialize
|
7
12
|
@info = Parts::Info.generate_hash
|
8
13
|
@paths = {}
|
@@ -10,6 +15,10 @@ module Rspec module Autoswagger
|
|
10
15
|
@specification = {}
|
11
16
|
end
|
12
17
|
|
18
|
+
def output_path
|
19
|
+
@output_path || DEFAULT_OUTPUT_PATH
|
20
|
+
end
|
21
|
+
|
13
22
|
def add(rspec_core_obj, example)
|
14
23
|
doc_part = DocPart.new(rspec_core_obj, example)
|
15
24
|
path, param_definitions = doc_part.create_path
|
@@ -18,7 +27,7 @@ module Rspec module Autoswagger
|
|
18
27
|
else
|
19
28
|
paths.merge!(path)
|
20
29
|
end
|
21
|
-
definitions.merge!(doc_part.create_definition)
|
30
|
+
definitions.merge!(doc_part.create_definition(output_path))
|
22
31
|
definitions.merge!(param_definitions) unless param_definitions.empty?
|
23
32
|
end
|
24
33
|
|
@@ -32,10 +41,10 @@ module Rspec module Autoswagger
|
|
32
41
|
|
33
42
|
def to_yaml
|
34
43
|
aggregate if specification.empty?
|
35
|
-
|
36
|
-
|
37
|
-
YAML.dump(specification, File.open(Rails.root.to_s + '/tmp/swagger.yml', 'w'))
|
44
|
+
FileUtils::mkdir_p(output_path)
|
45
|
+
YAML.dump(specification, File.open(output_path + '/swagger.yml', 'w'))
|
38
46
|
end
|
47
|
+
|
39
48
|
end
|
40
49
|
end
|
41
50
|
end
|
@@ -4,17 +4,14 @@ module Rspec
|
|
4
4
|
module Autoswagger
|
5
5
|
module Parts
|
6
6
|
class Definition
|
7
|
-
attr_reader :json, :response_name
|
8
7
|
|
9
|
-
|
8
|
+
attr_reader :json, :response_name, :output_path
|
9
|
+
DEFAULT_OUTPUT_PATH = './tmp'
|
10
10
|
|
11
|
-
def initialize(json, response_name)
|
11
|
+
def initialize(json, response_name, output_path)
|
12
12
|
@json = json
|
13
13
|
@response_name = response_name
|
14
|
-
|
15
|
-
|
16
|
-
def tmp_file_path
|
17
|
-
DEFAULT_PATH
|
14
|
+
@output_path = output_path
|
18
15
|
end
|
19
16
|
|
20
17
|
def generate_model_definitions
|
@@ -39,7 +36,7 @@ module Rspec
|
|
39
36
|
def generate_hash_and_file
|
40
37
|
@definition_hash ||= SwaggerModel::SwaggerV2.create_from_json(
|
41
38
|
json_string: json,
|
42
|
-
|
39
|
+
output_path: (output_path || DEFAULT_OUTPUT_PATH),
|
43
40
|
response_name: response_name
|
44
41
|
)
|
45
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-autoswagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joooee0000
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: swagger_model
|