rspec-openapi 0.1.0 → 0.18.4
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/.github/dependabot.yml +8 -0
- data/.github/release.yaml +24 -0
- data/.github/workflows/codeql-analysis.yml +39 -0
- data/.github/workflows/rubocop.yml +35 -0
- data/.github/workflows/test.yml +46 -0
- data/.rspec +2 -1
- data/.rubocop.yml +25 -0
- data/.rubocop_todo.yml +52 -0
- data/.simplecov_spawn.rb +16 -0
- data/CHANGELOG.md +287 -0
- data/Gemfile +28 -2
- data/README.md +267 -28
- data/Rakefile +8 -4
- data/bin/console +4 -3
- data/lib/rspec/openapi/components_updater.rb +98 -0
- data/lib/rspec/openapi/default_schema.rb +14 -2
- data/lib/rspec/openapi/extractors/hanami.rb +110 -0
- data/lib/rspec/openapi/extractors/rack.rb +31 -0
- data/lib/rspec/openapi/extractors/rails.rb +66 -0
- data/lib/rspec/openapi/extractors.rb +5 -0
- data/lib/rspec/openapi/hash_helper.rb +43 -0
- data/lib/rspec/openapi/key_transformer.rb +25 -0
- data/lib/rspec/openapi/minitest_hooks.rb +50 -0
- data/lib/rspec/openapi/record.rb +13 -3
- data/lib/rspec/openapi/record_builder.rb +65 -21
- data/lib/rspec/openapi/result_recorder.rb +63 -0
- data/lib/rspec/openapi/rspec_hooks.rb +21 -0
- data/lib/rspec/openapi/schema_builder.rb +166 -41
- data/lib/rspec/openapi/schema_cleaner.rb +129 -0
- data/lib/rspec/openapi/schema_file.rb +25 -3
- data/lib/rspec/openapi/schema_merger.rb +91 -21
- data/lib/rspec/openapi/schema_sorter.rb +35 -0
- data/lib/rspec/openapi/shared_hooks.rb +15 -0
- data/lib/rspec/openapi/version.rb +3 -1
- data/lib/rspec/openapi.rb +88 -2
- data/rspec-openapi.gemspec +19 -11
- data/scripts/rspec +11 -0
- data/scripts/rspec_with_simplecov +48 -0
- data/test.png +0 -0
- metadata +69 -15
- data/.travis.yml +0 -6
- data/lib/rspec/openapi/hooks.rb +0 -24
data/lib/rspec/openapi.rb
CHANGED
|
@@ -1,10 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rspec/openapi/version'
|
|
2
|
-
require 'rspec/openapi/
|
|
4
|
+
require 'rspec/openapi/components_updater'
|
|
5
|
+
require 'rspec/openapi/default_schema'
|
|
6
|
+
require 'rspec/openapi/record_builder'
|
|
7
|
+
require 'rspec/openapi/result_recorder'
|
|
8
|
+
require 'rspec/openapi/schema_builder'
|
|
9
|
+
require 'rspec/openapi/schema_file'
|
|
10
|
+
require 'rspec/openapi/schema_merger'
|
|
11
|
+
require 'rspec/openapi/schema_cleaner'
|
|
12
|
+
require 'rspec/openapi/schema_sorter'
|
|
13
|
+
require 'rspec/openapi/key_transformer'
|
|
14
|
+
require 'rspec/openapi/shared_hooks'
|
|
15
|
+
require 'rspec/openapi/extractors'
|
|
16
|
+
require 'rspec/openapi/extractors/rack'
|
|
3
17
|
|
|
4
18
|
module RSpec::OpenAPI
|
|
19
|
+
class Config
|
|
20
|
+
class << self
|
|
21
|
+
attr_accessor :debug_enabled
|
|
22
|
+
|
|
23
|
+
def load_environment_settings
|
|
24
|
+
@debug_enabled = ['', '1', 'true'].include?(ENV['DEBUG']&.downcase)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
5
29
|
@path = 'doc/openapi.yaml'
|
|
30
|
+
@title = File.basename(Dir.pwd)
|
|
31
|
+
@comment = nil
|
|
32
|
+
@enable_example = true
|
|
33
|
+
@description_builder = ->(example) { example.description }
|
|
34
|
+
@summary_builder = ->(example) { example.metadata[:summary] }
|
|
35
|
+
@tags_builder = ->(example) { example.metadata[:tags] }
|
|
36
|
+
@info = {}
|
|
37
|
+
@application_version = '1.0.0'
|
|
38
|
+
@request_headers = []
|
|
39
|
+
@servers = []
|
|
40
|
+
@security_schemes = []
|
|
41
|
+
@example_types = %i[request]
|
|
42
|
+
@response_headers = []
|
|
43
|
+
@path_records = Hash.new { |h, k| h[k] = [] }
|
|
44
|
+
@ignored_path_params = %i[controller action format]
|
|
45
|
+
@ignored_paths = []
|
|
46
|
+
@post_process_hook = nil
|
|
47
|
+
|
|
48
|
+
# This is the configuraion override file name we look for within each path.
|
|
49
|
+
@config_filename = 'rspec_openapi.rb'
|
|
6
50
|
|
|
7
51
|
class << self
|
|
8
|
-
attr_accessor :path
|
|
52
|
+
attr_accessor :path,
|
|
53
|
+
:title,
|
|
54
|
+
:comment,
|
|
55
|
+
:enable_example,
|
|
56
|
+
:description_builder,
|
|
57
|
+
:summary_builder,
|
|
58
|
+
:tags_builder,
|
|
59
|
+
:info,
|
|
60
|
+
:application_version,
|
|
61
|
+
:request_headers,
|
|
62
|
+
:servers,
|
|
63
|
+
:security_schemes,
|
|
64
|
+
:example_types,
|
|
65
|
+
:response_headers,
|
|
66
|
+
:path_records,
|
|
67
|
+
:ignored_paths,
|
|
68
|
+
:ignored_path_params,
|
|
69
|
+
:post_process_hook
|
|
70
|
+
|
|
71
|
+
attr_reader :config_filename
|
|
9
72
|
end
|
|
10
73
|
end
|
|
74
|
+
|
|
75
|
+
if ENV['OPENAPI']
|
|
76
|
+
RSpec::OpenAPI::Config.load_environment_settings
|
|
77
|
+
|
|
78
|
+
begin
|
|
79
|
+
require 'hanami'
|
|
80
|
+
rescue LoadError
|
|
81
|
+
warn 'Hanami not detected' if RSpec::OpenAPI::Config.debug_enabled
|
|
82
|
+
else
|
|
83
|
+
require 'rspec/openapi/extractors/hanami'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
begin
|
|
87
|
+
require 'rails'
|
|
88
|
+
rescue LoadError
|
|
89
|
+
warn 'Rails not detected' if RSpec::OpenAPI::Config.debug_enabled
|
|
90
|
+
else
|
|
91
|
+
require 'rspec/openapi/extractors/rails'
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
require 'rspec/openapi/minitest_hooks' if Object.const_defined?('Minitest')
|
|
96
|
+
require 'rspec/openapi/rspec_hooks' if ENV['OPENAPI'] && Object.const_defined?('RSpec')
|
data/rspec-openapi.gemspec
CHANGED
|
@@ -1,27 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'lib/rspec/openapi/version'
|
|
2
4
|
|
|
3
5
|
Gem::Specification.new do |spec|
|
|
4
6
|
spec.name = 'rspec-openapi'
|
|
5
7
|
spec.version = RSpec::OpenAPI::VERSION
|
|
6
|
-
spec.authors = ['Takashi Kokubun']
|
|
7
|
-
spec.email = ['takashikkbn@gmail.com']
|
|
8
|
+
spec.authors = ['Takashi Kokubun', 'TATSUNO Yasuhiro']
|
|
9
|
+
spec.email = ['takashikkbn@gmail.com', 'ytatsuno.jp@gmail.com']
|
|
8
10
|
|
|
9
|
-
spec.summary =
|
|
10
|
-
spec.description =
|
|
11
|
-
spec.homepage = 'https://github.com/
|
|
11
|
+
spec.summary = 'Generate OpenAPI schema from RSpec request specs'
|
|
12
|
+
spec.description = 'Generate OpenAPI from RSpec request specs'
|
|
13
|
+
spec.homepage = 'https://github.com/exoego/rspec-openapi'
|
|
12
14
|
spec.license = 'MIT'
|
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
|
|
14
16
|
|
|
15
|
-
spec.metadata
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
spec.metadata = {
|
|
18
|
+
'homepage_uri' => 'https://github.com/exoego/rspec-openapi',
|
|
19
|
+
'source_code_uri' => 'https://github.com/exoego/rspec-openapi',
|
|
20
|
+
'changelog_uri' => "https://github.com/exoego/rspec-openapi/releases/tag/v#{RSpec::OpenAPI::VERSION}",
|
|
21
|
+
'rubygems_mfa_required' => 'true',
|
|
22
|
+
}
|
|
18
23
|
|
|
19
|
-
spec.files
|
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
20
25
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
21
26
|
end
|
|
22
27
|
spec.bindir = 'exe'
|
|
23
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
24
29
|
spec.require_paths = ['lib']
|
|
25
30
|
|
|
26
|
-
spec.add_dependency '
|
|
31
|
+
spec.add_dependency 'actionpack', '>= 5.2.0'
|
|
32
|
+
spec.add_dependency 'rails-dom-testing'
|
|
33
|
+
spec.add_dependency 'rspec-core'
|
|
34
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
27
35
|
end
|
data/scripts/rspec
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# (The MIT License)
|
|
5
|
+
# Copyright (c) 2012 Chad Humphries, David Chelimsky, Myron Marston
|
|
6
|
+
# Copyright (c) 2009 Chad Humphries, David Chelimsky
|
|
7
|
+
# Copyright (c) 2006 David Chelimsky, The RSpec Development Team
|
|
8
|
+
# Copyright (c) 2005 Steven Baker
|
|
9
|
+
|
|
10
|
+
require 'rspec/core'
|
|
11
|
+
RSpec::Core::Runner.invoke
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# (The MIT License)
|
|
5
|
+
# Copyright (c) 2012 Chad Humphries, David Chelimsky, Myron Marston
|
|
6
|
+
# Copyright (c) 2009 Chad Humphries, David Chelimsky
|
|
7
|
+
# Copyright (c) 2006 David Chelimsky, The RSpec Development Team
|
|
8
|
+
# Copyright (c) 2005 Steven Baker
|
|
9
|
+
|
|
10
|
+
# Turn on verbose to make sure we not generating any ruby warning
|
|
11
|
+
$VERBOSE = true
|
|
12
|
+
|
|
13
|
+
# So our "did they run the rspec command?" detection logic thinks
|
|
14
|
+
# that we run `rspec`.
|
|
15
|
+
$0 = 'rspec'
|
|
16
|
+
|
|
17
|
+
# This is necessary for when `--standalone` is being used.
|
|
18
|
+
$LOAD_PATH.unshift File.expand_path '../bundle', __dir__
|
|
19
|
+
|
|
20
|
+
# For the travis build we put the bundle directory up a directory
|
|
21
|
+
# so it can be shared among the repos for faster bundle installs.
|
|
22
|
+
$LOAD_PATH.unshift File.expand_path '../../bundle', __dir__
|
|
23
|
+
|
|
24
|
+
require 'bundler/setup'
|
|
25
|
+
|
|
26
|
+
# To use simplecov while running rspec-core's test suite, we must
|
|
27
|
+
# load simplecov _before_ loading any of rspec-core's files.
|
|
28
|
+
# So, this executable exists purely as a wrapper script that
|
|
29
|
+
# first loads simplecov, and then loads rspec.
|
|
30
|
+
begin
|
|
31
|
+
# Simplecov emits some ruby warnings when loaded, so silence them.
|
|
32
|
+
old_verbose = $VERBOSE
|
|
33
|
+
$VERBOSE = false
|
|
34
|
+
|
|
35
|
+
unless (ENV.fetch('COVERAGE', nil) && ENV['COVERAGE'].empty?) || RUBY_VERSION < '1.9.3'
|
|
36
|
+
require 'simplecov'
|
|
37
|
+
|
|
38
|
+
SimpleCov.start do
|
|
39
|
+
enable_coverage :branch
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
rescue LoadError
|
|
43
|
+
# simplecov is not available
|
|
44
|
+
ensure
|
|
45
|
+
$VERBOSE = old_verbose
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
load File.expand_path('rspec', __dir__)
|
data/test.png
ADDED
|
Binary file
|
metadata
CHANGED
|
@@ -1,17 +1,46 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rspec-openapi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.18.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Takashi Kokubun
|
|
8
|
-
|
|
8
|
+
- TATSUNO Yasuhiro
|
|
9
|
+
autorequire:
|
|
9
10
|
bindir: exe
|
|
10
11
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
+
date: 2025-02-06 00:00:00.000000000 Z
|
|
12
13
|
dependencies:
|
|
13
14
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
15
|
+
name: actionpack
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
requirements:
|
|
18
|
+
- - ">="
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: 5.2.0
|
|
21
|
+
type: :runtime
|
|
22
|
+
prerelease: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: 5.2.0
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: rails-dom-testing
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
type: :runtime
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
42
|
+
- !ruby/object:Gem::Dependency
|
|
43
|
+
name: rspec-core
|
|
15
44
|
requirement: !ruby/object:Gem::Requirement
|
|
16
45
|
requirements:
|
|
17
46
|
- - ">="
|
|
@@ -24,16 +53,24 @@ dependencies:
|
|
|
24
53
|
- - ">="
|
|
25
54
|
- !ruby/object:Gem::Version
|
|
26
55
|
version: '0'
|
|
27
|
-
description: Generate OpenAPI
|
|
56
|
+
description: Generate OpenAPI from RSpec request specs
|
|
28
57
|
email:
|
|
29
58
|
- takashikkbn@gmail.com
|
|
59
|
+
- ytatsuno.jp@gmail.com
|
|
30
60
|
executables: []
|
|
31
61
|
extensions: []
|
|
32
62
|
extra_rdoc_files: []
|
|
33
63
|
files:
|
|
64
|
+
- ".github/dependabot.yml"
|
|
65
|
+
- ".github/release.yaml"
|
|
66
|
+
- ".github/workflows/codeql-analysis.yml"
|
|
67
|
+
- ".github/workflows/rubocop.yml"
|
|
68
|
+
- ".github/workflows/test.yml"
|
|
34
69
|
- ".gitignore"
|
|
35
70
|
- ".rspec"
|
|
36
|
-
- ".
|
|
71
|
+
- ".rubocop.yml"
|
|
72
|
+
- ".rubocop_todo.yml"
|
|
73
|
+
- ".simplecov_spawn.rb"
|
|
37
74
|
- CHANGELOG.md
|
|
38
75
|
- Gemfile
|
|
39
76
|
- LICENSE.txt
|
|
@@ -42,22 +79,39 @@ files:
|
|
|
42
79
|
- bin/console
|
|
43
80
|
- bin/setup
|
|
44
81
|
- lib/rspec/openapi.rb
|
|
82
|
+
- lib/rspec/openapi/components_updater.rb
|
|
45
83
|
- lib/rspec/openapi/default_schema.rb
|
|
46
|
-
- lib/rspec/openapi/
|
|
84
|
+
- lib/rspec/openapi/extractors.rb
|
|
85
|
+
- lib/rspec/openapi/extractors/hanami.rb
|
|
86
|
+
- lib/rspec/openapi/extractors/rack.rb
|
|
87
|
+
- lib/rspec/openapi/extractors/rails.rb
|
|
88
|
+
- lib/rspec/openapi/hash_helper.rb
|
|
89
|
+
- lib/rspec/openapi/key_transformer.rb
|
|
90
|
+
- lib/rspec/openapi/minitest_hooks.rb
|
|
47
91
|
- lib/rspec/openapi/record.rb
|
|
48
92
|
- lib/rspec/openapi/record_builder.rb
|
|
93
|
+
- lib/rspec/openapi/result_recorder.rb
|
|
94
|
+
- lib/rspec/openapi/rspec_hooks.rb
|
|
49
95
|
- lib/rspec/openapi/schema_builder.rb
|
|
96
|
+
- lib/rspec/openapi/schema_cleaner.rb
|
|
50
97
|
- lib/rspec/openapi/schema_file.rb
|
|
51
98
|
- lib/rspec/openapi/schema_merger.rb
|
|
99
|
+
- lib/rspec/openapi/schema_sorter.rb
|
|
100
|
+
- lib/rspec/openapi/shared_hooks.rb
|
|
52
101
|
- lib/rspec/openapi/version.rb
|
|
53
102
|
- rspec-openapi.gemspec
|
|
54
|
-
|
|
103
|
+
- scripts/rspec
|
|
104
|
+
- scripts/rspec_with_simplecov
|
|
105
|
+
- test.png
|
|
106
|
+
homepage: https://github.com/exoego/rspec-openapi
|
|
55
107
|
licenses:
|
|
56
108
|
- MIT
|
|
57
109
|
metadata:
|
|
58
|
-
homepage_uri: https://github.com/
|
|
59
|
-
source_code_uri: https://github.com/
|
|
60
|
-
|
|
110
|
+
homepage_uri: https://github.com/exoego/rspec-openapi
|
|
111
|
+
source_code_uri: https://github.com/exoego/rspec-openapi
|
|
112
|
+
changelog_uri: https://github.com/exoego/rspec-openapi/releases/tag/v0.18.4
|
|
113
|
+
rubygems_mfa_required: 'true'
|
|
114
|
+
post_install_message:
|
|
61
115
|
rdoc_options: []
|
|
62
116
|
require_paths:
|
|
63
117
|
- lib
|
|
@@ -65,15 +119,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
65
119
|
requirements:
|
|
66
120
|
- - ">="
|
|
67
121
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: 2.
|
|
122
|
+
version: 2.7.0
|
|
69
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
124
|
requirements:
|
|
71
125
|
- - ">="
|
|
72
126
|
- !ruby/object:Gem::Version
|
|
73
127
|
version: '0'
|
|
74
128
|
requirements: []
|
|
75
|
-
rubygems_version: 3.
|
|
76
|
-
signing_key:
|
|
129
|
+
rubygems_version: 3.4.6
|
|
130
|
+
signing_key:
|
|
77
131
|
specification_version: 4
|
|
78
|
-
summary: Generate OpenAPI
|
|
132
|
+
summary: Generate OpenAPI schema from RSpec request specs
|
|
79
133
|
test_files: []
|
data/.travis.yml
DELETED
data/lib/rspec/openapi/hooks.rb
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
require 'rspec'
|
|
2
|
-
require 'rspec/openapi/default_schema'
|
|
3
|
-
require 'rspec/openapi/record_builder'
|
|
4
|
-
require 'rspec/openapi/schema_builder'
|
|
5
|
-
require 'rspec/openapi/schema_file'
|
|
6
|
-
require 'rspec/openapi/schema_merger'
|
|
7
|
-
|
|
8
|
-
records = []
|
|
9
|
-
|
|
10
|
-
RSpec.configuration.after(:each) do |example|
|
|
11
|
-
if example.metadata[:type] == :request && example.metadata[:openapi] != false && request && response
|
|
12
|
-
records << RSpec::OpenAPI::RecordBuilder.build(self, example: example)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
RSpec.configuration.after(:suite) do
|
|
17
|
-
title = File.basename(Dir.pwd)
|
|
18
|
-
RSpec::OpenAPI::SchemaFile.new(RSpec::OpenAPI.path).edit do |spec|
|
|
19
|
-
RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::DefaultSchema.build(title))
|
|
20
|
-
records.each do |record|
|
|
21
|
-
RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::SchemaBuilder.build(record))
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|