rack-json_schema 1.5.1 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/release.yml +23 -0
- data/.github/workflows/bump-request.yml +26 -0
- data/.github/workflows/ci.yml +25 -0
- data/.github/workflows/github-label-sync.yml +18 -0
- data/.github/workflows/release.yml +14 -0
- data/CHANGELOG.md +3 -0
- data/README.md +7 -4
- data/lib/rack/json_schema/base_request_handler.rb +2 -2
- data/lib/rack/json_schema/docs.rb +2 -2
- data/lib/rack/json_schema/request_validation.rb +5 -7
- data/lib/rack/json_schema/version.rb +1 -1
- data/rack-json_schema.gemspec +3 -3
- data/spec/rack/spec/docs_spec.rb +4 -4
- data/spec/rack/spec/mock_spec.rb +3 -3
- data/spec/rack/spec/schema_provider_spec.rb +3 -3
- data/spec/rack/spec_spec.rb +7 -7
- data/spec/spec_helper.rb +0 -1
- metadata +14 -12
- data/.travis.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 70e38b4eab95187d2cea6df66ed016359ee63c41a6d799f0869be1afc98d3f43
|
4
|
+
data.tar.gz: 0a3c28a4c87c2f7bc919743ecfa4024c4b95a7f2af1eae69092bb3c8d6c883f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd5955fe62d144704178caba3fbff9dcb890ea27d9f912e40b0008a3defd0a33db38a84eda83b97b3813add8dff77ce9efe5775be00813927c8b95da6ace0976
|
7
|
+
data.tar.gz: a4af6c165d5c466da9a1469e3f4e512c56850cdb96563f8a6354e3cd1cb94a62d1655c78e84d385d7956c0addc2a59178d4724a38c2ab968c7e61de8668492a2
|
data/.github/release.yml
ADDED
@@ -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
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
# Rack::JsonSchema
|
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
|
63
|
+
Validates response and raises errors below.
|
61
64
|
|
62
|
-
* Rack::JsonSchema::
|
63
|
-
* Rack::JsonSchema::
|
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(**
|
7
|
-
new(**
|
6
|
+
def self.call(*args, **kwargs)
|
7
|
+
new(*args, **kwargs).call
|
8
8
|
end
|
9
9
|
|
10
10
|
# @param env [Hash] Rack env
|
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
data/rack-json_schema.gemspec
CHANGED
@@ -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.
|
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", "
|
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"
|
data/spec/rack/spec/docs_spec.rb
CHANGED
@@ -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.
|
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.
|
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.
|
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.
|
100
|
+
expect(response.body).not_to eq("dummy")
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
data/spec/rack/spec/mock_spec.rb
CHANGED
@@ -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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
89
|
+
expect(response.body).to eq("dummy")
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
data/spec/rack/spec_spec.rb
CHANGED
@@ -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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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
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.
|
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:
|
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.
|
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.
|
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
|
-
|
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