rswag-specs 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbf70bfdf1bb5ead3794e4d64a1afb85e00864701ec0cf42416a063b522fe489
|
4
|
+
data.tar.gz: ff39363f981f9a868e5afc47a00d87fbc629cda498118b024131318696e5e734
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e21b1bc504582ad44c5df4f24465a3751136ccd2e9114a95bc1aca95cc69b7a6110017c18faf3f2d854bdd596bf0612a56cb40803543c0a078143bc204083f37
|
7
|
+
data.tar.gz: bf21e075a70eb3e3a8712b8ee081aad9358cfe6472d258bacca82565b7d32426023e1c779a8b3e00b5c3496629357749d26daa6713bdfdd3a461cb72b601c773
|
@@ -13,8 +13,8 @@ RSpec.configure do |config|
|
|
13
13
|
# document below. You can override this behavior by adding a swagger_doc tag to the
|
14
14
|
# the root example_group in your specs, e.g. describe '...', swagger_doc: 'v2/swagger.json'
|
15
15
|
config.swagger_docs = {
|
16
|
-
'v1/swagger.
|
17
|
-
|
16
|
+
'v1/swagger.yaml' => {
|
17
|
+
openapi: '3.0.1',
|
18
18
|
info: {
|
19
19
|
title: 'API V1',
|
20
20
|
version: 'v1'
|
@@ -22,4 +22,10 @@ RSpec.configure do |config|
|
|
22
22
|
paths: {}
|
23
23
|
}
|
24
24
|
}
|
25
|
+
|
26
|
+
# Specify the format of the output Swagger file when running 'rswag:specs:swaggerize'.
|
27
|
+
# The swagger_docs configuration option has the filename including format in
|
28
|
+
# the key, this may want to be changed to avoid putting yaml in json files.
|
29
|
+
# Defaults to json. Accepts ':json' and ':yaml'.
|
30
|
+
config.swagger_format = :yaml
|
25
31
|
end
|
data/lib/rswag/specs.rb
CHANGED
@@ -31,6 +31,14 @@ module Rswag
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def swagger_format
|
35
|
+
@swagger_format ||= begin
|
36
|
+
@rspec_config.swagger_format = :json if @rspec_config.swagger_format.nil? || @rspec_config.swagger_format.empty?
|
37
|
+
raise ConfigurationError, "Unknown swagger_format '#{@rspec_config.swagger_format}'" unless [:json, :yaml].include?(@rspec_config.swagger_format)
|
38
|
+
@rspec_config.swagger_format
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
34
42
|
def get_swagger_doc(name)
|
35
43
|
return swagger_docs.values.first if name.nil?
|
36
44
|
raise ConfigurationError, "Unknown swagger_doc '#{name}'" unless swagger_docs[name]
|
@@ -37,7 +37,7 @@ module Rswag
|
|
37
37
|
FileUtils.mkdir_p dirname unless File.exists?(dirname)
|
38
38
|
|
39
39
|
File.open(file_path, 'w') do |file|
|
40
|
-
file.write(
|
40
|
+
file.write(pretty_generate(doc))
|
41
41
|
end
|
42
42
|
|
43
43
|
@output.puts "Swagger doc generated at #{file_path}"
|
@@ -46,6 +46,20 @@ module Rswag
|
|
46
46
|
|
47
47
|
private
|
48
48
|
|
49
|
+
def pretty_generate(doc)
|
50
|
+
if @config.swagger_format == :yaml
|
51
|
+
clean_doc = yaml_prepare(doc)
|
52
|
+
YAML.dump(clean_doc)
|
53
|
+
else # config errors are thrown in 'def swagger_format', no throw needed here
|
54
|
+
JSON.pretty_generate(doc)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def yaml_prepare(doc)
|
59
|
+
json_doc = JSON.pretty_generate(doc)
|
60
|
+
clean_doc = JSON.parse(json_doc)
|
61
|
+
end
|
62
|
+
|
49
63
|
def metadata_to_swagger(metadata)
|
50
64
|
response_code = metadata[:response][:code]
|
51
65
|
response = metadata[:response].reject { |k,v| k == :code }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rswag-specs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richie Morris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
113
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.7.
|
114
|
+
rubygems_version: 2.7.8
|
115
115
|
signing_key:
|
116
116
|
specification_version: 4
|
117
117
|
summary: A Swagger-based DSL for rspec-rails & accompanying rake task for generating
|