openapi_first 1.0.0.beta4 → 1.0.0.beta6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +2 -1
  3. data/CHANGELOG.md +13 -0
  4. data/Gemfile +2 -1
  5. data/Gemfile.lock +17 -22
  6. data/Gemfile.rack2 +15 -0
  7. data/README.md +17 -7
  8. data/lib/openapi_first/body_parser.rb +28 -0
  9. data/lib/openapi_first/config.rb +4 -3
  10. data/lib/openapi_first/definition/cookie_parameters.rb +12 -0
  11. data/lib/openapi_first/definition/has_content.rb +37 -0
  12. data/lib/openapi_first/definition/header_parameters.rb +12 -0
  13. data/lib/openapi_first/definition/operation.rb +103 -0
  14. data/lib/openapi_first/definition/parameters.rb +47 -0
  15. data/lib/openapi_first/definition/path_item.rb +23 -0
  16. data/lib/openapi_first/definition/path_parameters.rb +13 -0
  17. data/lib/openapi_first/definition/query_parameters.rb +12 -0
  18. data/lib/openapi_first/definition/request_body.rb +32 -0
  19. data/lib/openapi_first/definition/response.rb +37 -0
  20. data/lib/openapi_first/definition/schema/result.rb +17 -0
  21. data/lib/openapi_first/{schema_validation.rb → definition/schema.rb} +6 -6
  22. data/lib/openapi_first/definition.rb +26 -6
  23. data/lib/openapi_first/error_response.rb +28 -12
  24. data/lib/openapi_first/error_responses/default.rb +58 -0
  25. data/lib/openapi_first/error_responses/json_api.rb +58 -0
  26. data/lib/openapi_first/request_body_validator.rb +18 -22
  27. data/lib/openapi_first/request_validation.rb +68 -58
  28. data/lib/openapi_first/request_validation_error.rb +31 -0
  29. data/lib/openapi_first/response_validation.rb +33 -13
  30. data/lib/openapi_first/response_validator.rb +1 -0
  31. data/lib/openapi_first/router.rb +20 -62
  32. data/lib/openapi_first/version.rb +1 -1
  33. data/lib/openapi_first.rb +2 -13
  34. data/openapi_first.gemspec +8 -5
  35. metadata +44 -57
  36. data/.rspec +0 -3
  37. data/.rubocop.yml +0 -14
  38. data/Rakefile +0 -15
  39. data/benchmarks/Gemfile +0 -16
  40. data/benchmarks/Gemfile.lock +0 -131
  41. data/benchmarks/README.md +0 -29
  42. data/benchmarks/apps/committee_with_hanami_api.ru +0 -26
  43. data/benchmarks/apps/committee_with_response_validation.ru +0 -29
  44. data/benchmarks/apps/committee_with_sinatra.ru +0 -31
  45. data/benchmarks/apps/grape.ru +0 -21
  46. data/benchmarks/apps/hanami_api.ru +0 -21
  47. data/benchmarks/apps/hanami_router.ru +0 -14
  48. data/benchmarks/apps/openapi.yaml +0 -268
  49. data/benchmarks/apps/openapi_first_with_hanami_api.ru +0 -24
  50. data/benchmarks/apps/openapi_first_with_plain_rack.ru +0 -32
  51. data/benchmarks/apps/openapi_first_with_response_validation.ru +0 -25
  52. data/benchmarks/apps/openapi_first_with_sinatra.ru +0 -29
  53. data/benchmarks/apps/roda.ru +0 -27
  54. data/benchmarks/apps/sinatra.ru +0 -26
  55. data/benchmarks/apps/syro.ru +0 -25
  56. data/benchmarks/benchmark-wrk.sh +0 -3
  57. data/benchmarks/benchmarks.rb +0 -48
  58. data/benchmarks/post.lua +0 -3
  59. data/bin/console +0 -15
  60. data/bin/setup +0 -8
  61. data/examples/README.md +0 -13
  62. data/examples/app.rb +0 -18
  63. data/examples/config.ru +0 -7
  64. data/examples/openapi.yaml +0 -29
  65. data/lib/openapi_first/body_parser_middleware.rb +0 -53
  66. data/lib/openapi_first/default_error_response.rb +0 -47
  67. data/lib/openapi_first/operation.rb +0 -142
  68. data/lib/openapi_first/operation_schemas.rb +0 -52
  69. data/lib/openapi_first/string_keyed_hash.rb +0 -20
  70. data/lib/openapi_first/validation_result.rb +0 -15
@@ -2,14 +2,17 @@
2
2
 
3
3
  require 'rack'
4
4
  require 'multi_json'
5
- require 'hanami/router'
6
- require_relative 'body_parser_middleware'
5
+ require 'mustermann'
6
+ require_relative 'body_parser'
7
7
 
8
8
  module OpenapiFirst
9
9
  class Router
10
10
  # The unconverted path parameters before they are converted to the types defined in the API description
11
11
  RAW_PATH_PARAMS = 'openapi.raw_path_params'
12
12
 
13
+ NOT_FOUND = Rack::Response.new('Not Found', 404).finish.freeze
14
+ METHOD_NOT_ALLOWED = Rack::Response.new('Method Not Allowed', 405).finish.freeze
15
+
13
16
  def initialize(
14
17
  app,
15
18
  options
@@ -17,25 +20,32 @@ module OpenapiFirst
17
20
  @app = app
18
21
  @raise = options.fetch(:raise_error, false)
19
22
  @not_found = options.fetch(:not_found, :halt)
23
+ @error_response_class = options.fetch(:error_response, Config.default_options.error_response)
20
24
  spec = options.fetch(:spec)
21
25
  raise "You have to pass spec: when initializing #{self.class}" unless spec
22
26
 
23
- spec = OpenapiFirst.load(spec) unless spec.is_a?(Definition)
24
-
25
- @filepath = spec.filepath
26
- @router = build_router(spec.operations)
27
+ @definition = spec.is_a?(Definition) ? spec : OpenapiFirst.load(spec)
28
+ @filepath = @definition.filepath
27
29
  end
28
30
 
29
31
  def call(env)
30
32
  env[OPERATION] = nil
31
- response = call_router(env)
32
- if env[OPERATION].nil?
33
- raise_error(env) if @raise
33
+ request = Rack::Request.new(env)
34
+ path_item, path_params = @definition.find_path_item_and_params(request.path)
35
+ operation = path_item&.find_operation(request.request_method.downcase)
34
36
 
37
+ env[OPERATION] = operation
38
+ env[RAW_PATH_PARAMS] = path_params
39
+
40
+ if operation.nil?
41
+ raise_error(env) if @raise
35
42
  return @app.call(env) if @not_found == :continue
36
43
  end
37
44
 
38
- response
45
+ return NOT_FOUND unless path_item
46
+ return METHOD_NOT_ALLOWED unless operation
47
+
48
+ @app.call(env)
39
49
  end
40
50
 
41
51
  ORIGINAL_PATH = 'openapi_first.path_info'
@@ -54,57 +64,5 @@ module OpenapiFirst
54
64
  }' in API description #{@filepath}"
55
65
  raise NotFoundError, msg
56
66
  end
57
-
58
- def call_router(env)
59
- # Changing and restoring PATH_INFO is needed, because Hanami::Router does not respect existing script_path
60
- env[ORIGINAL_PATH] = env[Rack::PATH_INFO]
61
- env[Rack::PATH_INFO] = Rack::Request.new(env).path
62
- @router.call(env)
63
- rescue BodyParsingError => e
64
- handle_body_parsing_error(e)
65
- ensure
66
- env[Rack::PATH_INFO] = env.delete(ORIGINAL_PATH) if env[ORIGINAL_PATH]
67
- end
68
-
69
- def handle_body_parsing_error(_exception)
70
- message = 'Failed to parse body as application/json'
71
- raise RequestInvalidError, message if @raise
72
-
73
- error = {
74
- status: 400,
75
- title: message
76
- }
77
-
78
- ErrorResponse::Default.new(**error).finish
79
- end
80
-
81
- def build_router(operations)
82
- router = Hanami::Router.new.tap do |r|
83
- operations.each do |operation|
84
- normalized_path = operation.path.gsub('{', ':').gsub('}', '')
85
- r.public_send(
86
- operation.method,
87
- normalized_path,
88
- to: build_route(operation)
89
- )
90
- end
91
- end
92
- raise_error = @raise
93
- Rack::Builder.app do
94
- use(BodyParserMiddleware, raise_error:)
95
- run router
96
- end
97
- end
98
-
99
- def build_route(operation)
100
- lambda do |env|
101
- env[OPERATION] = operation
102
- path_info = env.delete(ORIGINAL_PATH)
103
- env[REQUEST_BODY] = env.delete(ROUTER_PARSED_BODY) if env.key?(ROUTER_PARSED_BODY)
104
- env[RAW_PATH_PARAMS] = env['router.params']
105
- env[Rack::PATH_INFO] = path_info
106
- @app.call(env)
107
- end
108
- end
109
67
  end
110
68
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiFirst
4
- VERSION = '1.0.0.beta4'
4
+ VERSION = '1.0.0.beta6'
5
5
  end
data/lib/openapi_first.rb CHANGED
@@ -11,7 +11,8 @@ require_relative 'openapi_first/router'
11
11
  require_relative 'openapi_first/request_validation'
12
12
  require_relative 'openapi_first/response_validator'
13
13
  require_relative 'openapi_first/response_validation'
14
- require_relative 'openapi_first/default_error_response'
14
+ require_relative 'openapi_first/error_responses/default'
15
+ require_relative 'openapi_first/error_responses/json_api'
15
16
 
16
17
  module OpenapiFirst
17
18
  # The OpenAPI operation for the current request
@@ -35,18 +36,6 @@ module OpenapiFirst
35
36
  # The parsed request body
36
37
  REQUEST_BODY = 'openapi.parsed_request_body'
37
38
 
38
- class << self
39
- # Throws an error in the middle of the request validation to stop validation and send a response.
40
- def error!(status, location = nil, title: nil, validation_result: nil)
41
- throw :error, {
42
- status:,
43
- location:,
44
- title: title || validation_result&.output&.fetch('error') || Rack::Utils::HTTP_STATUS_CODES[status],
45
- validation_result:
46
- }
47
- end
48
- end
49
-
50
39
  def self.load(spec_path, only: nil)
51
40
  resolved = Dir.chdir(File.dirname(spec_path)) do
52
41
  content = YAML.load_file(File.basename(spec_path))
@@ -26,19 +26,22 @@ Gem::Specification.new do |spec|
26
26
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
27
  `git ls-files -z`
28
28
  .split("\x0")
29
- .reject { |f| f.match(%r{^(test|spec|features)/}) }
30
- .reject { |f| %w[Dockerfile Jenkinsfile .tool-versions].include?(f) }
29
+ .reject { |f| f.match(%r{^(test|spec|features|benchmarks|examples|bin)/}) }
30
+ .reject do |f|
31
+ %w[Dockerfile Jenkinsfile .tool-versions CODEOWNERS .rspec .rubocop.yml .tool-versions
32
+ Rakefile].include?(f)
33
+ end
31
34
  end
32
35
  spec.bindir = 'exe'
33
36
  spec.require_paths = ['lib']
34
37
 
35
38
  spec.required_ruby_version = '>= 3.1.1'
36
39
 
37
- spec.add_runtime_dependency 'hanami-router', '~> 2.0.0'
38
40
  spec.add_runtime_dependency 'json_refs', '~> 0.1', '>= 0.1.7'
39
41
  spec.add_runtime_dependency 'json_schemer', '~> 2.0.0'
40
- spec.add_runtime_dependency 'multi_json', '~> 1.14'
41
- spec.add_runtime_dependency 'openapi_parameters', '~> 0.2.2'
42
+ spec.add_runtime_dependency 'multi_json', '~> 1.15'
43
+ spec.add_runtime_dependency 'mustermann-contrib', '~> 3.0.0'
44
+ spec.add_runtime_dependency 'openapi_parameters', '>= 0.3.2', '< 2.0'
42
45
  spec.add_runtime_dependency 'rack', '>= 2.2', '< 4.0'
43
46
  spec.metadata = {
44
47
  'rubygems_mfa_required' => 'true'
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_first
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta4
4
+ version: 1.0.0.beta6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Haller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-25 00:00:00.000000000 Z
11
+ date: 2023-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: hanami-router
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 2.0.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 2.0.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: json_refs
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -64,28 +50,48 @@ dependencies:
64
50
  requirements:
65
51
  - - "~>"
66
52
  - !ruby/object:Gem::Version
67
- version: '1.14'
53
+ version: '1.15'
68
54
  type: :runtime
69
55
  prerelease: false
70
56
  version_requirements: !ruby/object:Gem::Requirement
71
57
  requirements:
72
58
  - - "~>"
73
59
  - !ruby/object:Gem::Version
74
- version: '1.14'
60
+ version: '1.15'
75
61
  - !ruby/object:Gem::Dependency
76
- name: openapi_parameters
62
+ name: mustermann-contrib
77
63
  requirement: !ruby/object:Gem::Requirement
78
64
  requirements:
79
65
  - - "~>"
80
66
  - !ruby/object:Gem::Version
81
- version: 0.2.2
67
+ version: 3.0.0
82
68
  type: :runtime
83
69
  prerelease: false
84
70
  version_requirements: !ruby/object:Gem::Requirement
85
71
  requirements:
86
72
  - - "~>"
87
73
  - !ruby/object:Gem::Version
88
- version: 0.2.2
74
+ version: 3.0.0
75
+ - !ruby/object:Gem::Dependency
76
+ name: openapi_parameters
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 0.3.2
82
+ - - "<"
83
+ - !ruby/object:Gem::Version
84
+ version: '2.0'
85
+ type: :runtime
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 0.3.2
92
+ - - "<"
93
+ - !ruby/object:Gem::Version
94
+ version: '2.0'
89
95
  - !ruby/object:Gem::Dependency
90
96
  name: rack
91
97
  requirement: !ruby/object:Gem::Requirement
@@ -116,59 +122,40 @@ files:
116
122
  - ".github/CODEOWNERS"
117
123
  - ".github/workflows/ruby.yml"
118
124
  - ".gitignore"
119
- - ".rspec"
120
- - ".rubocop.yml"
121
125
  - CHANGELOG.md
122
126
  - Gemfile
123
127
  - Gemfile.lock
128
+ - Gemfile.rack2
124
129
  - LICENSE.txt
125
130
  - README.md
126
- - Rakefile
127
- - benchmarks/Gemfile
128
- - benchmarks/Gemfile.lock
129
- - benchmarks/README.md
130
- - benchmarks/apps/committee_with_hanami_api.ru
131
- - benchmarks/apps/committee_with_response_validation.ru
132
- - benchmarks/apps/committee_with_sinatra.ru
133
- - benchmarks/apps/grape.ru
134
- - benchmarks/apps/hanami_api.ru
135
- - benchmarks/apps/hanami_router.ru
136
- - benchmarks/apps/openapi.yaml
137
- - benchmarks/apps/openapi_first_with_hanami_api.ru
138
- - benchmarks/apps/openapi_first_with_plain_rack.ru
139
- - benchmarks/apps/openapi_first_with_response_validation.ru
140
- - benchmarks/apps/openapi_first_with_sinatra.ru
141
- - benchmarks/apps/roda.ru
142
- - benchmarks/apps/sinatra.ru
143
- - benchmarks/apps/syro.ru
144
- - benchmarks/benchmark-wrk.sh
145
- - benchmarks/benchmarks.rb
146
- - benchmarks/post.lua
147
- - bin/console
148
- - bin/setup
149
- - examples/README.md
150
- - examples/app.rb
151
- - examples/config.ru
152
- - examples/openapi.yaml
153
131
  - lib/openapi_first.rb
154
- - lib/openapi_first/body_parser_middleware.rb
132
+ - lib/openapi_first/body_parser.rb
155
133
  - lib/openapi_first/config.rb
156
- - lib/openapi_first/default_error_response.rb
157
134
  - lib/openapi_first/definition.rb
135
+ - lib/openapi_first/definition/cookie_parameters.rb
136
+ - lib/openapi_first/definition/has_content.rb
137
+ - lib/openapi_first/definition/header_parameters.rb
138
+ - lib/openapi_first/definition/operation.rb
139
+ - lib/openapi_first/definition/parameters.rb
140
+ - lib/openapi_first/definition/path_item.rb
141
+ - lib/openapi_first/definition/path_parameters.rb
142
+ - lib/openapi_first/definition/query_parameters.rb
143
+ - lib/openapi_first/definition/request_body.rb
144
+ - lib/openapi_first/definition/response.rb
145
+ - lib/openapi_first/definition/schema.rb
146
+ - lib/openapi_first/definition/schema/result.rb
158
147
  - lib/openapi_first/error_response.rb
148
+ - lib/openapi_first/error_responses/default.rb
149
+ - lib/openapi_first/error_responses/json_api.rb
159
150
  - lib/openapi_first/errors.rb
160
- - lib/openapi_first/operation.rb
161
- - lib/openapi_first/operation_schemas.rb
162
151
  - lib/openapi_first/plugins.rb
163
152
  - lib/openapi_first/request_body_validator.rb
164
153
  - lib/openapi_first/request_validation.rb
154
+ - lib/openapi_first/request_validation_error.rb
165
155
  - lib/openapi_first/response_validation.rb
166
156
  - lib/openapi_first/response_validator.rb
167
157
  - lib/openapi_first/router.rb
168
- - lib/openapi_first/schema_validation.rb
169
- - lib/openapi_first/string_keyed_hash.rb
170
158
  - lib/openapi_first/use_router.rb
171
- - lib/openapi_first/validation_result.rb
172
159
  - lib/openapi_first/version.rb
173
160
  - openapi_first.gemspec
174
161
  homepage: https://github.com/ahx/openapi_first
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,14 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 3.1.1
3
- NewCops: enable
4
- SuggestExtensions: false
5
- Style/Documentation:
6
- Enabled: false
7
- Style/ExponentialNotation:
8
- Enabled: true
9
- Metrics/BlockLength:
10
- Exclude:
11
- - "spec/**/*.rb"
12
- - "*.gemspec"
13
- Metrics/MethodLength:
14
- Max: 20
data/Rakefile DELETED
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
- require 'rubocop/rake_task'
6
-
7
- RuboCop::RakeTask.new
8
-
9
- task :version do
10
- puts Gem::Specification.load('openapi_first.gemspec').version
11
- end
12
-
13
- RSpec::Core::RakeTask.new(:spec)
14
-
15
- task default: %i[spec rubocop]
data/benchmarks/Gemfile DELETED
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gem 'benchmark-ips'
6
- gem 'benchmark-memory'
7
- gem 'committee'
8
- gem 'grape'
9
- gem 'hanami-api'
10
- gem 'hanami-router'
11
- gem 'multi_json'
12
- gem 'openapi_first', path: '../'
13
- gem 'puma'
14
- gem 'roda'
15
- gem 'sinatra'
16
- gem 'syro'
@@ -1,131 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- openapi_first (1.0.0.beta3)
5
- hanami-router (~> 2.0.0)
6
- json_refs (~> 0.1, >= 0.1.7)
7
- json_schemer (~> 2.0.0)
8
- multi_json (~> 1.14)
9
- openapi_parameters (~> 0.2.2)
10
- rack (>= 2.2, < 4.0)
11
-
12
- GEM
13
- remote: https://rubygems.org/
14
- specs:
15
- activesupport (7.0.8)
16
- concurrent-ruby (~> 1.0, >= 1.0.2)
17
- i18n (>= 1.6, < 2)
18
- minitest (>= 5.1)
19
- tzinfo (~> 2.0)
20
- benchmark-ips (2.12.0)
21
- benchmark-memory (0.2.0)
22
- memory_profiler (~> 1)
23
- builder (3.2.4)
24
- committee (5.0.0)
25
- json_schema (~> 0.14, >= 0.14.3)
26
- openapi_parser (~> 1.0)
27
- rack (>= 1.5)
28
- concurrent-ruby (1.2.2)
29
- dry-core (1.0.0)
30
- concurrent-ruby (~> 1.0)
31
- zeitwerk (~> 2.6)
32
- dry-inflector (1.0.0)
33
- dry-logic (1.5.0)
34
- concurrent-ruby (~> 1.0)
35
- dry-core (~> 1.0, < 2)
36
- zeitwerk (~> 2.6)
37
- dry-types (1.7.1)
38
- concurrent-ruby (~> 1.0)
39
- dry-core (~> 1.0)
40
- dry-inflector (~> 1.0)
41
- dry-logic (~> 1.4)
42
- zeitwerk (~> 2.6)
43
- grape (1.7.1)
44
- activesupport
45
- builder
46
- dry-types (>= 1.1)
47
- mustermann-grape (~> 1.0.0)
48
- rack (>= 1.3.0, < 3)
49
- rack-accept
50
- hana (1.3.7)
51
- hanami-api (0.3.0)
52
- hanami-router (~> 2.0)
53
- hanami-router (2.0.2)
54
- mustermann (~> 3.0)
55
- mustermann-contrib (~> 3.0)
56
- rack (~> 2.0)
57
- hansi (0.2.1)
58
- i18n (1.14.1)
59
- concurrent-ruby (~> 1.0)
60
- json_refs (0.1.8)
61
- hana
62
- json_schema (0.21.0)
63
- json_schemer (2.0.0)
64
- hana (~> 1.3)
65
- regexp_parser (~> 2.0)
66
- simpleidn (~> 0.2)
67
- memory_profiler (1.0.1)
68
- minitest (5.20.0)
69
- multi_json (1.15.0)
70
- mustermann (3.0.0)
71
- ruby2_keywords (~> 0.0.1)
72
- mustermann-contrib (3.0.0)
73
- hansi (~> 0.2.0)
74
- mustermann (= 3.0.0)
75
- mustermann-grape (1.0.2)
76
- mustermann (>= 1.0.0)
77
- nio4r (2.5.9)
78
- openapi_parameters (0.2.2)
79
- rack (>= 2.2)
80
- zeitwerk (~> 2.6)
81
- openapi_parser (1.0.0)
82
- puma (6.3.1)
83
- nio4r (~> 2.0)
84
- rack (2.2.8)
85
- rack-accept (0.4.5)
86
- rack (>= 0.4)
87
- rack-protection (3.0.6)
88
- rack
89
- regexp_parser (2.8.1)
90
- roda (3.68.0)
91
- rack
92
- ruby2_keywords (0.0.5)
93
- seg (1.2.0)
94
- simpleidn (0.2.1)
95
- unf (~> 0.1.4)
96
- sinatra (3.0.6)
97
- mustermann (~> 3.0)
98
- rack (~> 2.2, >= 2.2.4)
99
- rack-protection (= 3.0.6)
100
- tilt (~> 2.0)
101
- syro (3.2.1)
102
- rack (>= 1.6.0)
103
- seg
104
- tilt (2.1.0)
105
- tzinfo (2.0.6)
106
- concurrent-ruby (~> 1.0)
107
- unf (0.1.4)
108
- unf_ext
109
- unf_ext (0.0.8.2)
110
- zeitwerk (2.6.11)
111
-
112
- PLATFORMS
113
- arm64-darwin-21
114
- x86_64-linux
115
-
116
- DEPENDENCIES
117
- benchmark-ips
118
- benchmark-memory
119
- committee
120
- grape
121
- hanami-api
122
- hanami-router
123
- multi_json
124
- openapi_first!
125
- puma
126
- roda
127
- sinatra
128
- syro
129
-
130
- BUNDLED WITH
131
- 2.3.10
data/benchmarks/README.md DELETED
@@ -1,29 +0,0 @@
1
- # How to run these bechmarks
2
-
3
- ## Setup
4
-
5
- ```bash
6
- cd benchmarks
7
- bundle install
8
- ```
9
-
10
- ## Run Ruby benchmarks
11
-
12
- This compares ips and memory usage for all apps defined in /apps
13
-
14
- ```bash
15
- bundle exec ruby benchmarks.rb
16
- ```
17
-
18
- ## Run benchmark using [wrk](https://github.com/wg/wrk)
19
-
20
- 1. Start the example app
21
- Example: openapi_first
22
- ```bash
23
- bundle exec puma apps/openapi_first_with_response_validation.ru
24
- ```
25
-
26
- 2. Run wrk
27
- ```bash
28
- ./benchmark-wrk.sh
29
- ```
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'multi_json'
4
- require 'committee'
5
- require 'hanami/api'
6
-
7
- app = Class.new(Hanami::API) do
8
- get '/hello/:id' do
9
- json(hello: 'world', id: params.fetch(:id))
10
- end
11
-
12
- get '/hello' do
13
- json([{ hello: 'world' }])
14
- end
15
-
16
- post '/hello' do
17
- status 201
18
- json(hello: 'world')
19
- end
20
- end.new
21
-
22
- use Committee::Middleware::RequestValidation,
23
- schema_path: File.absolute_path('./openapi.yaml', __dir__),
24
- parse_response_by_content_type: true
25
-
26
- run app
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'multi_json'
4
- require 'committee'
5
- require 'hanami/api'
6
-
7
- app = Class.new(Hanami::API) do
8
- get '/hello/:id' do
9
- json(hello: 'world', id: params.fetch(:id))
10
- end
11
-
12
- get '/hello' do
13
- json([{ hello: 'world' }])
14
- end
15
-
16
- post '/hello' do
17
- status 201
18
- json(hello: 'world')
19
- end
20
- end.new
21
-
22
- use Committee::Middleware::RequestValidation,
23
- schema_path: File.absolute_path('./openapi.yaml', __dir__),
24
- parse_response_by_content_type: true
25
-
26
- use Committee::Middleware::ResponseValidation,
27
- schema_path: File.absolute_path('./openapi.yaml', __dir__)
28
-
29
- run app
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'multi_json'
4
- require 'committee'
5
- require 'sinatra'
6
-
7
- class SinatraWithCommiteeExample < Sinatra::Base
8
- set :environment, :production
9
-
10
- get '/hello/:id' do
11
- content_type :json
12
- MultiJson.dump(hello: 'world', id: params.fetch('id'))
13
- end
14
-
15
- get '/hello' do
16
- content_type :json
17
- MultiJson.dump([{ hello: 'world' }])
18
- end
19
-
20
- post '/hello' do
21
- content_type :json
22
- status 201
23
- MultiJson.dump(hello: 'world')
24
- end
25
- end
26
-
27
- use Committee::Middleware::RequestValidation,
28
- schema_path: File.absolute_path('./openapi.yaml', __dir__),
29
- parse_response_by_content_type: true
30
-
31
- run SinatraWithCommiteeExample
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'grape'
4
-
5
- class GrapeExample < Grape::API
6
- format :json
7
-
8
- get :hello do
9
- [{ hello: 'world' }]
10
- end
11
-
12
- post :hello do
13
- { hello: 'world' }
14
- end
15
-
16
- get 'hello/:id' do
17
- { hello: 'world', id: params[:id] }
18
- end
19
- end
20
-
21
- run GrapeExample
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'multi_json'
4
- require 'hanami/api'
5
-
6
- app = Class.new(Hanami::API) do
7
- get '/hello/:id' do
8
- json(hello: 'world', id: params.fetch(:id))
9
- end
10
-
11
- get '/hello' do
12
- json([{ hello: 'world' }])
13
- end
14
-
15
- post '/hello' do
16
- status 201
17
- json(hello: 'world')
18
- end
19
- end.new
20
-
21
- run app