json_schemer 0.2.20 → 0.2.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +6 -1
- data/Gemfile.lock +5 -5
- data/README.md +24 -0
- data/bin/rake +29 -0
- data/exe/json_schemer +62 -0
- data/lib/json_schemer/format.rb +1 -1
- data/lib/json_schemer/version.rb +1 -1
- data/lib/json_schemer.rb +2 -2
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed760df49bc348a5011d6baf6416462f0069b31a8c1ef99550913d30a8a8a41e
|
4
|
+
data.tar.gz: c271118e1a2f8c26de0aace952e10340642536b44cd3b88f91ea22aa11c9bd0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 737e7a7888a61e8f2807e0307c8a96653943a7b88d27bb2fa4666a806f514f89274643b96a0dd48eb4eb940cfd0fd76d9254827360f2a53808263b66e25fc932
|
7
|
+
data.tar.gz: 522393b56be1b0ad983785b2b4ffe2268b11649336a151934260800b099f4160850c85dec19a44ace008cfbf5c6a208f7c53b8e04bf939ab86c8bdd75d6b873e
|
data/.github/workflows/ci.yml
CHANGED
@@ -23,4 +23,9 @@ jobs:
|
|
23
23
|
with:
|
24
24
|
ruby-version: ${{ matrix.ruby }}
|
25
25
|
bundler-cache: true
|
26
|
-
- run:
|
26
|
+
- run: |
|
27
|
+
mkdir -p tmp/gems
|
28
|
+
gem build json_schemer.gemspec
|
29
|
+
gem install --local --ignore-dependencies --no-document --install-dir tmp/gems json_schemer-*.gem
|
30
|
+
rm json_schemer-*.gem
|
31
|
+
bin/rake test
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
json_schemer (0.2.
|
4
|
+
json_schemer (0.2.21)
|
5
5
|
ecma-re-validator (~> 0.3)
|
6
6
|
hana (~> 1.3)
|
7
7
|
regexp_parser (~> 2.0)
|
@@ -13,9 +13,9 @@ GEM
|
|
13
13
|
ecma-re-validator (0.3.0)
|
14
14
|
regexp_parser (~> 2.0)
|
15
15
|
hana (1.3.7)
|
16
|
-
minitest (5.
|
17
|
-
rake (13.0.
|
18
|
-
regexp_parser (2.
|
16
|
+
minitest (5.15.0)
|
17
|
+
rake (13.0.6)
|
18
|
+
regexp_parser (2.3.1)
|
19
19
|
uri_template (0.7.0)
|
20
20
|
|
21
21
|
PLATFORMS
|
@@ -28,4 +28,4 @@ DEPENDENCIES
|
|
28
28
|
rake (~> 13.0)
|
29
29
|
|
30
30
|
BUNDLED WITH
|
31
|
-
2.
|
31
|
+
2.3.11
|
data/README.md
CHANGED
@@ -114,6 +114,30 @@ JSONSchemer.schema(
|
|
114
114
|
)
|
115
115
|
```
|
116
116
|
|
117
|
+
## CLI
|
118
|
+
|
119
|
+
The `json_schemer` executable takes a JSON schema file as the first argument followed by one or more JSON data files to validate. If there are any validation errors, it outputs them and returns an error code.
|
120
|
+
|
121
|
+
Validation errors are output as single-line JSON objects. The `--errors` option can be used to limit the number of errors returned or prevent output entirely (and fail fast).
|
122
|
+
|
123
|
+
The schema or data can also be read from stdin using `-`.
|
124
|
+
|
125
|
+
```
|
126
|
+
% json_schemer --help
|
127
|
+
Usage:
|
128
|
+
json_schemer [options] <schema> <data>...
|
129
|
+
json_schemer [options] <schema> -
|
130
|
+
json_schemer [options] - <data>...
|
131
|
+
json_schemer -h | --help
|
132
|
+
json_schemer --version
|
133
|
+
|
134
|
+
Options:
|
135
|
+
-e, --errors MAX Maximum number of errors to output
|
136
|
+
Use "0" to validate with no output
|
137
|
+
-h, --help Show help
|
138
|
+
-v, --version Show version
|
139
|
+
```
|
140
|
+
|
117
141
|
## Development
|
118
142
|
|
119
143
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rake' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rake", "rake")
|
data/exe/json_schemer
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'optparse'
|
5
|
+
require 'pathname'
|
6
|
+
require 'json_schemer'
|
7
|
+
|
8
|
+
parser = OptionParser.new('Usage:', 32, ' ')
|
9
|
+
parser.separator(" #{parser.program_name} [options] <schema> <data>...")
|
10
|
+
parser.separator(" #{parser.program_name} [options] <schema> -")
|
11
|
+
parser.separator(" #{parser.program_name} [options] - <data>...")
|
12
|
+
parser.separator(" #{parser.program_name} -h | --help")
|
13
|
+
parser.separator(" #{parser.program_name} --version")
|
14
|
+
parser.separator('')
|
15
|
+
parser.separator('Options:')
|
16
|
+
parser.on('-e', '--errors MAX', Integer, 'Maximum number of errors to output', 'Use "0" to validate with no output')
|
17
|
+
parser.on_tail('-h', '--help', 'Show help')
|
18
|
+
parser.on_tail('-v', '--version', 'Show version')
|
19
|
+
|
20
|
+
options = {}
|
21
|
+
parser.parse!(:into => options)
|
22
|
+
|
23
|
+
if options[:help]
|
24
|
+
$stdout.puts(parser)
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
|
28
|
+
if options[:version]
|
29
|
+
$stdout.puts("#{parser.program_name} #{JSONSchemer::VERSION}")
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
|
33
|
+
if ARGV.size == 0
|
34
|
+
$stderr.puts("#{parser.program_name}: no schema or data")
|
35
|
+
exit(false)
|
36
|
+
end
|
37
|
+
|
38
|
+
if ARGV.size == 1
|
39
|
+
$stderr.puts("#{parser.program_name}: no data")
|
40
|
+
exit(false)
|
41
|
+
end
|
42
|
+
|
43
|
+
if ARGV.count('-') > 1
|
44
|
+
$stderr.puts("#{parser.program_name}: multiple stdin")
|
45
|
+
exit(false)
|
46
|
+
end
|
47
|
+
|
48
|
+
errors = 0
|
49
|
+
schema = ARGF.file.is_a?(File) ? Pathname.new(ARGF.file.path) : ARGF.file.read
|
50
|
+
schemer = JSONSchemer.schema(schema)
|
51
|
+
|
52
|
+
while ARGV.any?
|
53
|
+
data = JSON.parse(ARGF.skip.file.read)
|
54
|
+
schemer.validate(data).each do |error|
|
55
|
+
exit(false) if options[:errors] == 0
|
56
|
+
errors += 1
|
57
|
+
$stdout.puts(JSON.generate(error))
|
58
|
+
exit(false) if options[:errors] == errors
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
exit(errors.zero?)
|
data/lib/json_schemer/format.rb
CHANGED
data/lib/json_schemer/version.rb
CHANGED
data/lib/json_schemer.rb
CHANGED
@@ -46,7 +46,7 @@ module JSONSchemer
|
|
46
46
|
raise InvalidFileURI, 'cannot have a host (use `file:///`)' if uri.host && !uri.host.empty?
|
47
47
|
path = uri.path
|
48
48
|
path = path[1..-1] if path.match?(WINDOWS_URI_PATH_REGEX)
|
49
|
-
JSON.parse(File.read(path))
|
49
|
+
JSON.parse(File.read(URI::DEFAULT_PARSER.unescape(path)))
|
50
50
|
end
|
51
51
|
|
52
52
|
class << self
|
@@ -55,7 +55,7 @@ module JSONSchemer
|
|
55
55
|
when String
|
56
56
|
schema = JSON.parse(schema)
|
57
57
|
when Pathname
|
58
|
-
uri = URI.parse(File.join('file:', schema.realpath))
|
58
|
+
uri = URI.parse(File.join('file:', URI::DEFAULT_PARSER.escape(schema.realpath.to_s)))
|
59
59
|
if options.key?(:ref_resolver)
|
60
60
|
schema = FILE_URI_REF_RESOLVER.call(uri)
|
61
61
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_schemer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Harsha
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,10 +108,11 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '2.0'
|
111
|
-
description:
|
111
|
+
description:
|
112
112
|
email:
|
113
113
|
- davishmcclurg@gmail.com
|
114
|
-
executables:
|
114
|
+
executables:
|
115
|
+
- json_schemer
|
115
116
|
extensions: []
|
116
117
|
extra_rdoc_files: []
|
117
118
|
files:
|
@@ -123,7 +124,9 @@ files:
|
|
123
124
|
- README.md
|
124
125
|
- Rakefile
|
125
126
|
- bin/console
|
127
|
+
- bin/rake
|
126
128
|
- bin/setup
|
129
|
+
- exe/json_schemer
|
127
130
|
- json_schemer.gemspec
|
128
131
|
- lib/json_schemer.rb
|
129
132
|
- lib/json_schemer/cached_ref_resolver.rb
|
@@ -138,7 +141,7 @@ homepage: https://github.com/davishmcclurg/json_schemer
|
|
138
141
|
licenses:
|
139
142
|
- MIT
|
140
143
|
metadata: {}
|
141
|
-
post_install_message:
|
144
|
+
post_install_message:
|
142
145
|
rdoc_options: []
|
143
146
|
require_paths:
|
144
147
|
- lib
|
@@ -153,8 +156,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
156
|
- !ruby/object:Gem::Version
|
154
157
|
version: '0'
|
155
158
|
requirements: []
|
156
|
-
rubygems_version: 3.
|
157
|
-
signing_key:
|
159
|
+
rubygems_version: 3.3.7
|
160
|
+
signing_key:
|
158
161
|
specification_version: 4
|
159
162
|
summary: JSON Schema validator. Supports drafts 4, 6, and 7.
|
160
163
|
test_files: []
|