Comments (5)
@Jbern16 you're referenced schema doesn't need the wrapping Host
key:
>> schemaWithRefs = {
?> "$id" => "NAME_HERE",
?> "$schema" => "http://json-schema.org/draft-04/schema#",
?> "type" => "object",
?> "description" => "A Host entity has been created or changed",
?> "required" => ["host"],
?> "additionalProperties" => false,
?> "properties" => {
?> "host" => {
?> "description" => "Host",
?> "allOf" => [{"$ref" => "https://my-url-here.com/EDM.json#Host"}],
?> "required" => ["attribute1"]
>> }
>> }
>> }
=> {"$id"=>"NAME_HERE", "$schema"=>"http://json-schema.org/draft-04/schema#", "type"=>"object", "description"=>"A Host entity has been created or changed", "required"=>["host"], "additionalProperties"=>false, "properties"=>{"host"=>{"description"=>"Host", "allOf"=>[{"$ref"=>"https://my-url-here.com/EDM.json#Host"}], "required"=>["attribute1"]}}}
>>
>> refSchema = {
?> "$id" => "#Host",
?> "properties" => { "attribute1" => { "type" => "string" } }
>> }
=> {"$id"=>"#Host", "properties"=>{"attribute1"=>{"type"=>"string"}}}
>>
>> schema = JSONSchemer.schema(schemaWithRefs, ref_resolver: proc { refSchema })
=> #<JSONSchemer::Schema::Draft4:0x00007fe5b932fce8 @root={"$id"=>"NAME_HERE", "$schema"=>"http://json-schema.org/draft-04/schema#", "type"=>"object", "description"=>"A Host entity has been created or changed", "required"=>["host"], "additionalProperties"=>false, "properties"=>{"host"=>{"description"=>"Host", "allOf"=>[{"$ref"=>"https://my-url-here.com/EDM.json#Host"}], "required"=>["attribute1"]}}}, @format=true, @insert_property_defaults=false, @formats=nil, @keywords=nil, @ref_resolver=#<Proc:0x00007fe5b932fdd8@(irb):47>>
>>
>> schema.valid?({ 'host' => { "attribute1" => nil } })
=> false
>> schema.valid?({ 'host' => { "attribute1" => 'x' } })
=> true
from json_schemer.
heh closing, the issue was with the capitalization of Host not matching the data
from json_schemer.
Sorry, re-opening. That doesn't actually seem to solve the issue, it was invalidating for a different reason.
from json_schemer.
Thanks! I’ll try this out. At first glance I don’t think this will work as Host is part of a larger schema and contains pointers to other formats / refs, so don’t think I can just extract that one piece. Maybe I can solve this utilizing a ref resolver.
Thanks again for your help
from json_schemer.
At first glance I don’t think this will work as Host is part of a larger schema and contains pointers to other formats / refs, so don’t think I can just extract that one piece. Maybe I can solve this utilizing a ref resolver.
@Jbern16 ah, I think I misunderstood what you were trying to do. You should be able to make it work by referencing the subschema with a JSON pointer instead of $id
: {"$ref": "http://localhost:8000/ref.json#/Host"}
Using $id
is a little bit tricky and I think it will only work if the $id
is at the top level or under definitions
:
json_schemer/lib/json_schemer/schema/base.rb
Lines 614 to 631 in ec9b051
from json_schemer.
Related Issues (20)
- Number validation with multipleOf: 0.01 is giving false positive errors HOT 1
- Ecma 262 Validation for patterns HOT 1
- URI Escaping Error HOT 3
- tab space in json message validation fails HOT 2
- Type array validation always returning false with extra options
- array not required returns the message: "1 item required; only 0 were given" in the json schema HOT 2
- Add support for Draft 2020-12 HOT 1
- Can the gem put some short and readable validation result? HOT 4
- JSON pointers: "/" and "~" are not escaped HOT 1
- Non-string data keys HOT 10
- Allow for regexp_parser 2.x HOT 2
- InvalidFileURI "cannot have a host" on Windows HOT 4
- JRuby/Windows regex test failure
- Add support for symbolized keys HOT 3
- If, then, else keywords HOT 1
- Validate Only Works When Errors Exist HOT 1
- insert_property_defaults does not work for nested schemas (eg. oneOf) HOT 2
- Add CLI support HOT 1
- Bug: `anyOf` and `oneOf` handle the absence of `type` on subschemas differently HOT 3
- Missing require for stdlib class Set HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json_schemer.