rust_json_schema 0.3.0-aarch64-linux-musl
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.standard.yml +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +24 -0
- data/lib/rust_json_schema/3.0/rust_json_schema.so +0 -0
- data/lib/rust_json_schema/3.1/rust_json_schema.so +0 -0
- data/lib/rust_json_schema/3.2/rust_json_schema.so +0 -0
- data/lib/rust_json_schema/3.3/rust_json_schema.so +0 -0
- data/lib/rust_json_schema/version.rb +5 -0
- data/lib/rust_json_schema.rb +21 -0
- data/sig/rust_json_schema.rbs +4 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 692035aaa205794b3ba351ae5cacc56be9c075db8cdade886eefdc724c59a522
|
4
|
+
data.tar.gz: e4022f6ba311200cdb44f2c856414c97489f3c3ca5cc1b1af6ed3a5fb09dc44b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 354cbea0d00b85e5ea371b79e88b17bc1bb37edd1078b0219aed53ee5ffd2ef126eb7bf64e427a5224e089c780bf33eb730b8f4efa55a3432519deb2351ec8bb
|
7
|
+
data.tar.gz: 47fb3ebe8db3348bbe7996ee904fa2ccf0cb481c9450d90c00c0739857614bd4034138b9eed569e18f58ad6d7324658eeae838d949159db56c4f91272b240265
|
data/.rspec
ADDED
data/.standard.yml
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Taylor Thurlow
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# `rust_json_schema`
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rust_json_schema.svg)](https://rubygems.org/gems/rust_json_schema)
|
4
|
+
|
5
|
+
`rust_json_schema` is a Ruby wrapper gem for Rust's [jsonschema-rs crate](https://github.com/Stranger6667/jsonschema-rs).
|
6
|
+
|
7
|
+
> [!IMPORTANT]
|
8
|
+
> This gem is built with `json_schema` crate version `0.19.1`, and therefore does not support any features for any potential future versions of the crate. I will review and accept PRs if you would like to work on adding support for newer versions of the crate. I generally am trying to keep things up to date but I am not cutting new releases for each new patch version of the crate.
|
9
|
+
|
10
|
+
The minimum Ruby version required by this gem is 3.0, due to the runtime Rust libraries that make the extensions possible (and easy).
|
11
|
+
|
12
|
+
This gem ships with precompiled binaries for Linux and macOS. Check the available gems on [Rubygems](https://rubygems.org/gems/rust_json_schema). Precompiled binaries do not exist for non-standard rubies like JRuby or TruffleRuby, nor do they exist for Windows. I will review and accept PRs if you would like to work on adding these build targets.
|
13
|
+
|
14
|
+
[rusty_json_schema](https://github.com/driv3r/rusty_json_schema) is a direct source of inspiration. Now that [bundler has explicit support for rust-backed Ruby gems](https://bundler.io/blog/2023/01/31/rust-gem-skeleton.html) as of early 2023, the Rust library code is a lot simpler that it previously needed to be, largely thanks to [magnus crate](https://github.com/matsadler/magnus) and the [rb-sys gem](https://github.com/oxidize-rb/rb-sys/tree/main/gem), and by extension, the [oxidize-rb team](https://github.com/oxidize-rb).
|
15
|
+
|
16
|
+
## Warning
|
17
|
+
|
18
|
+
My experience with Rust is limited, but this gem does have tests, and it is deployed in production. Please confirm that the gem is working as expected before using it in any production-critical situation. If you are using this gem in a production environment, and have any comments or feedback, I would love to hear about it.
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
Install the gem and add to the application's Gemfile by executing:
|
23
|
+
|
24
|
+
$ bundle add rust_json_schema
|
25
|
+
|
26
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
27
|
+
|
28
|
+
$ gem install rust_json_schema
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
schema = <<~JSON
|
34
|
+
{
|
35
|
+
"properties": {
|
36
|
+
"foo": { "type": "string" },
|
37
|
+
"bar": { "type": "integer" },
|
38
|
+
"baz": {}
|
39
|
+
},
|
40
|
+
"required": ["foo", "baz"]
|
41
|
+
}
|
42
|
+
JSON
|
43
|
+
|
44
|
+
validator = RustJSONSchema::Validator.new(schema, draft: :draft7)
|
45
|
+
|
46
|
+
errors = validator.validate('{ "foo": 1, "bar": "wadus" }')
|
47
|
+
# => [
|
48
|
+
# 'path "/bar": "wadus" is not of type "number"',
|
49
|
+
# 'path "/foo": 1 is not of type "string"',
|
50
|
+
# 'path "/": "baz" is a required property'
|
51
|
+
# ]
|
52
|
+
```
|
53
|
+
|
54
|
+
### Options
|
55
|
+
|
56
|
+
- `:draft` - Select the JSON schema draft number to use. Valid options are `draft4`, `draft6`, `draft7`, `draft201909`, and `draft202012`. Supported drafts are entirely determined by the `jsonschema` crate. The default draft is also determined by the crate. If new versions of the crate support additional draft versions, a code change in this gem will be required. I'm open to PRs to solve this problem - I don't know enough Rust to tell if it's easily done. _Both `draft201909` and `draft202012` are reported to have "some keywords not implemented", so use them at your own risk._
|
57
|
+
|
58
|
+
Any additional options provided by the `jsonschema` crate are options I do not understand or may not make sense to implement in a wrapper library such as this.
|
59
|
+
|
60
|
+
`RustJSONSchema::Validator#options` is provided and will return a Hash containing configuration options from the underlying Rust library. While I make an effort for them to look similar, or identical, to the options passed into the `Validator` initializer, the initializer arguments and the returned Hash should not be considered one-to-one. It exists as a way to confirm the configuration of the underlying schema validator instance.
|
61
|
+
|
62
|
+
### Errors
|
63
|
+
|
64
|
+
- All errors are subclasses of `RustJSONSchema::Error`.
|
65
|
+
- Calling `RustJSONSchema::Validator#new`, `#validate` or `#valid?` with a string which is not valid JSON will raise `RustJSONSchema::JSONParseError`.
|
66
|
+
- Calling `RustJSONSchema::Validator#new` with an invalid schema will raise `RustJSONSchema::SchemaParseError`.
|
67
|
+
- Calling `RustJSONSchema::Validator#new` with an invalid draft version value will raise `RustJSONSchema::InvalidOptionsError`.
|
68
|
+
|
69
|
+
## Development
|
70
|
+
|
71
|
+
The rust extension is located at `ext/rust_json_schema`, and can be compiled using the `rake-compiler` tasks, usually `bin/rake compile`. Don't attempt to `cargo build` the extension separately, that typically doesn't work. View other rake tasks with `bin/rake --tasks`.
|
72
|
+
|
73
|
+
You can run the tests with `bin/rspec`, but ensure any changes to the rust extension are compiled first.
|
74
|
+
|
75
|
+
To release a new version, update the version number in `version.rb`, tag the new commit with the version number, and push the tag to GitHub. The gem will be built and pushed to Rubygems automatically. This will also automatically build the platform-specific binaries and attach them to the release.
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
Bug reports and pull requests are welcome.
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require "standard/rake"
|
9
|
+
|
10
|
+
require "rb_sys/extensiontask"
|
11
|
+
|
12
|
+
task build: :compile
|
13
|
+
|
14
|
+
rubies = ["3.3.0", "3.2.0", "3.1.0", "3.0.0"]
|
15
|
+
ENV["RUBY_CC_VERSION"] ||= rubies.join(":")
|
16
|
+
|
17
|
+
spec = Bundler::GemHelper.gemspec
|
18
|
+
RbSys::ExtensionTask.new("rust_json_schema", spec) do |ext|
|
19
|
+
ext.lib_dir = "lib/rust_json_schema"
|
20
|
+
|
21
|
+
ext.cross_compile = true
|
22
|
+
end
|
23
|
+
|
24
|
+
task default: %i[compile spec standard]
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "rust_json_schema/version"
|
4
|
+
|
5
|
+
module RustJSONSchema
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
class JSONParseError < Error; end
|
9
|
+
|
10
|
+
class SchemaParseError < Error; end
|
11
|
+
|
12
|
+
class InvalidOptionsError < Error; end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Tries to require the extension for the given Ruby version first
|
16
|
+
begin
|
17
|
+
RUBY_VERSION =~ /(\d+\.\d+)/
|
18
|
+
require "rust_json_schema/#{Regexp.last_match(1)}/rust_json_schema"
|
19
|
+
rescue LoadError
|
20
|
+
require_relative "rust_json_schema/rust_json_schema"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rust_json_schema
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: aarch64-linux-musl
|
6
|
+
authors:
|
7
|
+
- Taylor Thurlow
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-09-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake-compiler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake-compiler-dock
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Ruby wrapper for jsonschema-rs
|
42
|
+
email:
|
43
|
+
- thurlow@hey.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".rspec"
|
49
|
+
- ".standard.yml"
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/rust_json_schema.rb
|
54
|
+
- lib/rust_json_schema/3.0/rust_json_schema.so
|
55
|
+
- lib/rust_json_schema/3.1/rust_json_schema.so
|
56
|
+
- lib/rust_json_schema/3.2/rust_json_schema.so
|
57
|
+
- lib/rust_json_schema/3.3/rust_json_schema.so
|
58
|
+
- lib/rust_json_schema/version.rb
|
59
|
+
- sig/rust_json_schema.rbs
|
60
|
+
homepage: https://github.com/taylorthurlow/rust_json_schema-rb
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata:
|
64
|
+
homepage_uri: https://github.com/taylorthurlow/rust_json_schema-rb
|
65
|
+
source_code_uri: https://github.com/taylorthurlow/rust_json_schema-rb
|
66
|
+
changelog_uri: https://github.com/taylorthurlow/rust_json_schema-rb/releases
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
- - "<"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 3.4.dev
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 3.3.11
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 3.3.22
|
87
|
+
requirements: []
|
88
|
+
rubygems_version: 3.4.4
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Ruby wrapper for jsonschema-rs
|
92
|
+
test_files: []
|