
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Schemacop validates ruby structures consisting of nested hashes and arrays against schema definitions described by a simple DSL. It is also able to generate JSON Schema compliant JSON output, i.e. for use in conjunction with OpenAPI.
Schemacop is tested with the following ruby versions:
Other ruby versions might work but are not covered by our automated tests.
schema = Schemacop::Schema3.new :hash do
scm :group do
str! :name
end
str! :name
int? :age, minimum: 21
ary! :groups do
list :reference, path: :group
end
end
schema.validate!(
name: 'John Doe',
age: 42,
groups: [
{ name: 'Group 1' },
{ name: 'Group 2' }
]
)
To install the Schemacop gem:
$ gem install schemacop
To install it using bundler
(recommended for any application), add it to your
Gemfile
:
gem 'schemacop', '>= 3.0.0'
The actual schema definition depends on the schema version you're using.
Schemacop 3 supports version 3 and also the legacy version 2 for backwards
compatibility. For version 1, you need to use the 1.x
versions of schemacop.
Using the method as_json
on any V3 schema will produce a JSON schema compliant
to the JSON Schema standard.
Schemacop::Schema3.new :hash do
str! :name
end.as_json
# Will result in
{
type: :object,
properties: {
name: { type: :string }
},
additionalProperties: false,
required: [:name]
}
On the resulting data structure, you can use to_json
to convert it into an
actual JSON string.
Schemacop will throw one of the following checked exceptions:
Schemacop::Exceptions::InvalidSchemaError
This exception is thrown when the given schema definition format is invalid.
Schemacop::Exceptions::ValidationError
This exception is thrown when the given data does not comply with the given schema definition.
To run tests:
Check out the source
Run bundle install
Run bundle exec rake test
to run all tests
Run bundle exec rake test TEST=test/unit/some/file.rb
to run a single test
file
Copyright © 2016 - 2025 Sitrox. See LICENSE
for further details.
FAQs
Unknown package
We found that schemacop demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.