rack-json_schema 1.5.1 → 1.5.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e1bc0b3aeb691e9f03410743681b3aeb47636727
4
- data.tar.gz: 78f4809fbaa6d7732b5ba700f464be4187ad6263
2
+ SHA256:
3
+ metadata.gz: 70e38b4eab95187d2cea6df66ed016359ee63c41a6d799f0869be1afc98d3f43
4
+ data.tar.gz: 0a3c28a4c87c2f7bc919743ecfa4024c4b95a7f2af1eae69092bb3c8d6c883f8
5
5
  SHA512:
6
- metadata.gz: 82933f6a328ccb1f7809880262f4f2119c19962c6830082ca188b768c995a55701f58f2e6f6d003c2522a3667d43f7eee91237bd844e4ccdc30da52733feb643
7
- data.tar.gz: 694562757728e378acf77e615247bc480f51048b9f649eb4ccc9b503889a1a545d39ad5af3ce860cb485e390186ddcce14853dd55c35a97ccceac606b21da49d
6
+ metadata.gz: dd5955fe62d144704178caba3fbff9dcb890ea27d9f912e40b0008a3defd0a33db38a84eda83b97b3813add8dff77ce9efe5775be00813927c8b95da6ace0976
7
+ data.tar.gz: a4af6c165d5c466da9a1469e3f4e512c56850cdb96563f8a6354e3cd1cb94a62d1655c78e84d385d7956c0addc2a59178d4724a38c2ab968c7e61de8668492a2
@@ -0,0 +1,23 @@
1
+ changelog:
2
+ categories:
3
+ - title: Added
4
+ labels:
5
+ - add
6
+ - title: Changed
7
+ labels:
8
+ - change
9
+ - title: Deprecated
10
+ labels:
11
+ - deprecate
12
+ - title: Fixed
13
+ labels:
14
+ - fix
15
+ - title: Removed
16
+ labels:
17
+ - remove
18
+ - title: Security
19
+ labels:
20
+ - security
21
+ - title: Others
22
+ labels:
23
+ - "*"
@@ -0,0 +1,26 @@
1
+ name: bump-request
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ version:
7
+ description: Version to change to.
8
+ required: true
9
+ type: string
10
+
11
+ jobs:
12
+ run:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: '3.3'
20
+ bundler-cache: true
21
+ - uses: r7kamura/bump-request@v0
22
+ with:
23
+ command: |
24
+ sed -i -r 's/([0-9]+\.[0-9]+\.[0-9]+)/${{ inputs.version }}/' lib/rack/json_schema/version.rb
25
+ bundle install
26
+ version: ${{ inputs.version }}
@@ -0,0 +1,25 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+
9
+ jobs:
10
+ rspec:
11
+ runs-on: ubuntu-latest
12
+ name: Ruby ${{ matrix.ruby }}
13
+ strategy:
14
+ matrix:
15
+ ruby:
16
+ - '3.3'
17
+ steps:
18
+ - uses: actions/checkout@v3
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ bundler-cache: true
24
+ - name: Run the default task
25
+ run: bundle exec rake
@@ -0,0 +1,18 @@
1
+ name: github-label-sync
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ paths:
8
+ - .github/workflows/github-label-sync.yml
9
+ workflow_dispatch:
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: r7kamura/github-label-sync-action@v0
16
+ with:
17
+ source_path: labels-keepachangelog.yml
18
+ source_repository: r7kamura/github-label-presets
@@ -0,0 +1,14 @@
1
+ name: release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*.*.*"
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: softprops/action-gh-release@v1
13
+ with:
14
+ generate_release_notes: true
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.5.2
2
+ - Fix bug on handling empty request body handling (e.g. GET)
3
+
1
4
  ## 1.5.1
2
5
  - Fix error when request body is an Array in JSON
3
6
 
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- # Rack::JsonSchema [![Build Status](https://travis-ci.org/r7kamura/rack-json_schema.svg?branch=master)](https://travis-ci.org/r7kamura/rack-json_schema)
1
+ # Rack::JsonSchema
2
+
3
+ [![CI](https://github.com/r7kamura/rack-json_schema/actions/workflows/ci.yml/badge.svg)](https://github.com/r7kamura/rack-json_schema/actions/workflows/ci.yml)
4
+
2
5
  [JSON Schema](http://json-schema.org/) based Rack middlewares.
3
6
 
4
7
  * [Rack::JsonSchema::RequestValidation](#rackjsonschemarequestvalidation)
@@ -57,10 +60,10 @@ $ curl http://localhost:8080/apps -H "Content-Type: application/json" -d '{"name
57
60
  ```
58
61
 
59
62
  ### Rack::JsonSchema::ResponseValidation
60
- Validates request and raises errors below.
63
+ Validates response and raises errors below.
61
64
 
62
- * Rack::JsonSchema::RequestValidation::InvalidResponseContentType
63
- * Rack::JsonSchema::RequestValidation::InvalidResponseType
65
+ * Rack::JsonSchema::ResponseValidation::InvalidResponseContentType
66
+ * Rack::JsonSchema::ResponseValidation::InvalidResponseType
64
67
 
65
68
  ```sh
66
69
  $ curl http://localhost:8080/apps
@@ -3,8 +3,8 @@ module Rack
3
3
  # Base class for providing some utility methods to handle Rack env and JSON Schema
4
4
  class BaseRequestHandler
5
5
  # Utility wrapper method
6
- def self.call(**args)
7
- new(**args).call
6
+ def self.call(*args, **kwargs)
7
+ new(*args, **kwargs).call
8
8
  end
9
9
 
10
10
  # @param env [Hash] Rack env
@@ -34,8 +34,8 @@ module Rack
34
34
  end
35
35
 
36
36
  class DocumentGenerator
37
- def self.call(*args)
38
- new(*args).call
37
+ def self.call(*args, **kwargs)
38
+ new(*args, **kwargs).call
39
39
  end
40
40
 
41
41
  # @param app [Object] Rack application
@@ -55,12 +55,10 @@ module Rack
55
55
  case
56
56
  when content_type_json? && has_body? && !has_valid_json?
57
57
  raise InvalidJson
58
+ when content_type_json? && has_schema? && !has_hash_request_body?
59
+ raise InvalidParameter, "Invalid request. Request body must be an Object in JSON."
58
60
  when content_type_json? && has_schema? && !has_valid_parameter?
59
- if has_hash_request_body?
60
- raise InvalidParameter, "Invalid request.\n#{schema_validation_error_message}"
61
- else
62
- raise InvalidParameter, "Invalid request. Request body must be an Object in JSON."
63
- end
61
+ raise InvalidParameter, "Invalid request.\n#{schema_validation_error_message}"
64
62
  end
65
63
  end
66
64
  elsif !ignore_missing_path?
@@ -71,7 +69,7 @@ module Rack
71
69
  private
72
70
 
73
71
  def has_hash_request_body?
74
- parsed_body.is_a?(Hash)
72
+ parameters_from_body.is_a?(Hash)
75
73
  end
76
74
 
77
75
  def has_valid_json?
@@ -83,7 +81,7 @@ module Rack
83
81
 
84
82
  # @return [true, false] True if request parameters are all valid
85
83
  def has_valid_parameter?
86
- parsed_body.is_a?(Hash) && schema_validation_result[0]
84
+ !!schema_validation_result[0]
87
85
  end
88
86
 
89
87
  # @return [true, false] True if any schema is defined for the current action
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module JsonSchema
3
- VERSION = "1.5.1"
3
+ VERSION = "1.5.3"
4
4
  end
5
5
  end
@@ -18,14 +18,14 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "erubis"
21
- spec.add_dependency "jdoc", ">= 0.1.4"
21
+ spec.add_dependency "jdoc", ">= 0.4.4"
22
22
  spec.add_dependency "json_schema", "~> 0.2"
23
23
  spec.add_dependency "rack"
24
- spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "bundler", ">= 1.5"
25
25
  spec.add_development_dependency "pry"
26
26
  spec.add_development_dependency "rack-test"
27
27
  spec.add_development_dependency "rake"
28
- spec.add_development_dependency "rspec", "2.14.1"
28
+ spec.add_development_dependency "rspec", ">= 2.14.1"
29
29
  spec.add_development_dependency "rspec-console"
30
30
  spec.add_development_dependency "rspec-json_matcher"
31
31
  spec.add_development_dependency "shotgun"
@@ -60,7 +60,7 @@ describe Rack::JsonSchema::Docs do
60
60
 
61
61
  it "generates API documentation and returns it to request to GET /docs" do
62
62
  should == 200
63
- response.body.should include("Example API")
63
+ expect(response.body).to include("Example API")
64
64
  end
65
65
  end
66
66
 
@@ -75,7 +75,7 @@ describe Rack::JsonSchema::Docs do
75
75
 
76
76
  it "responds to specified path" do
77
77
  should == 200
78
- response.body.should_not == "dummy"
78
+ expect(response.body).not_to eq("dummy")
79
79
  end
80
80
  end
81
81
 
@@ -86,7 +86,7 @@ describe Rack::JsonSchema::Docs do
86
86
 
87
87
  it "delegates request to inner app" do
88
88
  should == 200
89
- response.body.should == "dummy"
89
+ expect(response.body).to eq("dummy")
90
90
  end
91
91
  end
92
92
 
@@ -97,7 +97,7 @@ describe Rack::JsonSchema::Docs do
97
97
 
98
98
  it "also accepts GET /docs.md" do
99
99
  should == 200
100
- response.body.should_not == "dummy"
100
+ expect(response.body).not_to eq("dummy")
101
101
  end
102
102
  end
103
103
  end
@@ -56,7 +56,7 @@ describe Rack::JsonSchema::Mock do
56
56
 
57
57
  it "returns Array dummy response" do
58
58
  should == 200
59
- response.body.should be_json_as(
59
+ expect(response.body).to be_json_as(
60
60
  [
61
61
  {
62
62
  id: schema["definitions"]["app"]["definitions"]["id"]["example"],
@@ -78,7 +78,7 @@ describe Rack::JsonSchema::Mock do
78
78
 
79
79
  it "returns dummy response" do
80
80
  should == 200
81
- response.body.should be_json_as(
81
+ expect(response.body).to be_json_as(
82
82
  {
83
83
  id: schema["definitions"]["app"]["definitions"]["id"]["example"],
84
84
  name: schema["definitions"]["app"]["definitions"]["name"]["example"],
@@ -116,7 +116,7 @@ describe Rack::JsonSchema::Mock do
116
116
 
117
117
  it "returns example_not_found error" do
118
118
  should == 500
119
- response.body.should be_json_as(
119
+ expect(response.body).to be_json_as(
120
120
  id: "example_not_found",
121
121
  message: "No example found for #/definitions/app/id",
122
122
  )
@@ -60,7 +60,7 @@ describe Rack::JsonSchema::SchemaProvider do
60
60
 
61
61
  it "returns JSON Schema to request to GET /schema" do
62
62
  should == 200
63
- response.body.should include("app")
63
+ expect(response.body).to include("app")
64
64
  end
65
65
  end
66
66
 
@@ -75,7 +75,7 @@ describe Rack::JsonSchema::SchemaProvider do
75
75
 
76
76
  it "responds to specified path" do
77
77
  should == 200
78
- response.body.should_not == "dummy"
78
+ expect(response.body).not_to eq("dummy")
79
79
  end
80
80
  end
81
81
 
@@ -86,7 +86,7 @@ describe Rack::JsonSchema::SchemaProvider do
86
86
 
87
87
  it "delegates request to inner app" do
88
88
  should == 200
89
- response.body.should == "dummy"
89
+ expect(response.body).to eq("dummy")
90
90
  end
91
91
  end
92
92
  end
@@ -114,7 +114,7 @@ describe Rack::JsonSchema do
114
114
 
115
115
  it "returns link_not_found error" do
116
116
  should == 404
117
- response.body.should be_json_as(
117
+ expect(response.body).to be_json_as(
118
118
  id: "link_not_found",
119
119
  message: "Could not find the link definition for request path #{path}.",
120
120
  )
@@ -138,7 +138,7 @@ describe Rack::JsonSchema do
138
138
 
139
139
  it "returns invalid_content_type error" do
140
140
  should == 400
141
- response.body.should be_json_as(
141
+ expect(response.body).to be_json_as(
142
142
  id: "invalid_content_type",
143
143
  message: "Invalid content type",
144
144
  )
@@ -181,7 +181,7 @@ describe Rack::JsonSchema do
181
181
 
182
182
  it "returns invalid_parameter error" do
183
183
  should == 400
184
- response.body.should be_json_as(
184
+ expect(response.body).to be_json_as(
185
185
  id: "invalid_parameter",
186
186
  message: String,
187
187
  )
@@ -216,7 +216,7 @@ describe Rack::JsonSchema do
216
216
 
217
217
  it "returns invalid_parameter error" do
218
218
  should == 400
219
- response.body.should be_json_as(
219
+ expect(response.body).to be_json_as(
220
220
  id: "invalid_json",
221
221
  message: "Request body wasn't valid JSON",
222
222
  )
@@ -255,7 +255,7 @@ describe Rack::JsonSchema do
255
255
  context "when mediaType is not specified" do
256
256
  it "returns invalid_response_content_type error" do
257
257
  should == 500
258
- response.body.should be_json_as(
258
+ expect(response.body).to be_json_as(
259
259
  id: "invalid_response_content_type",
260
260
  message: "Response Content-Type wasn't for JSON",
261
261
  )
@@ -270,7 +270,7 @@ describe Rack::JsonSchema do
270
270
 
271
271
  it "returns invalid_response_type error" do
272
272
  should == 500
273
- response.body.should be_json_as(
273
+ expect(response.body).to be_json_as(
274
274
  id: "invalid_response_type",
275
275
  message: String,
276
276
  )
@@ -284,7 +284,7 @@ describe Rack::JsonSchema do
284
284
 
285
285
  it "returns invalid_response_type error" do
286
286
  should == 500
287
- response.body.should be_json_as(
287
+ expect(response.body).to be_json_as(
288
288
  id: "invalid_response_type",
289
289
  message: String,
290
290
  )
data/spec/spec_helper.rb CHANGED
@@ -4,7 +4,6 @@ require "rack/test"
4
4
  require "rspec/json_matcher"
5
5
 
6
6
  RSpec.configure do |config|
7
- config.treat_symbols_as_metadata_keys_with_true_values = true
8
7
  config.run_all_when_everything_filtered = true
9
8
  config.filter_run :focus
10
9
  config.include RSpec::JsonMatcher
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2024-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.4
33
+ version: 0.4.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.1.4
40
+ version: 0.4.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: json_schema
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -70,14 +70,14 @@ dependencies:
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.5'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.5'
83
83
  - !ruby/object:Gem::Dependency
@@ -126,14 +126,14 @@ dependencies:
126
126
  name: rspec
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: 2.14.1
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: 2.14.1
139
139
  - !ruby/object:Gem::Dependency
@@ -186,8 +186,12 @@ executables:
186
186
  extensions: []
187
187
  extra_rdoc_files: []
188
188
  files:
189
+ - ".github/release.yml"
190
+ - ".github/workflows/bump-request.yml"
191
+ - ".github/workflows/ci.yml"
192
+ - ".github/workflows/github-label-sync.yml"
193
+ - ".github/workflows/release.yml"
189
194
  - ".gitignore"
190
- - ".travis.yml"
191
195
  - CHANGELOG.md
192
196
  - Gemfile
193
197
  - LICENSE.txt
@@ -233,8 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
237
  - !ruby/object:Gem::Version
234
238
  version: '0'
235
239
  requirements: []
236
- rubyforge_project:
237
- rubygems_version: 2.4.5
240
+ rubygems_version: 3.5.3
238
241
  signing_key:
239
242
  specification_version: 4
240
243
  summary: JSON Schema based Rack middlewares
@@ -245,4 +248,3 @@ test_files:
245
248
  - spec/rack/spec/schema_provider_spec.rb
246
249
  - spec/rack/spec_spec.rb
247
250
  - spec/spec_helper.rb
248
- has_rdoc:
data/.travis.yml DELETED
@@ -1,3 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0