Comments (3)
My understanding of the json schema specification is that referencing external file has to be done with a complete URL/URI (http://...). So by default, all your schemas "should" be served by your http server.
Now, because just like you i wanted to reference local files, I added a way to do so.
It has to be in the form: file://..., please note it has to be the full path, non relative one. for example:
"$ref": "file:///usr/something/data/json/schemas/bson_object_id.json#properties/_id"
Please note this is an "experimental" feature.
PS: Please label your issues as questions when they are not proper bugs/issues.
from gojsonschema.
Hey @sigu-399, thanks for you reply.
I see, the specification is vague regarding to $ref
. I find relative paths useful, in case we have a project with many schemas which can be deployed in different environments (test, development, staging, production etc) with different absolute paths, but always with the same relative path.
PS: Please label your issues as questions when they are not proper bugs/issues.
I'm sorry for using issues as questions. Unfortunately I can't label issues, this feature is only available for project maintainers.
My bson_object_id.json
accepts _id
as a string _id: '52b8b007cbdb04659d0009e5'
or as an object _id: { '$oid': '52b8b007cbdb04659d0009e5' }
, as type
accepts a string or an array. The "problem" is in case of object
, because I would like to define a specific object
which only accepts/requires $oid
as a property/member. So I created an array of types as follows:
/data/json/schemas/bson_object_id.json
{
"type": "object",
"properties": {
"_id": {
"type": [ { "type": "string" },
{ "type": "object",
"additionalProperties" : false,
"properties": {
"$oid": {
"type": "string"
}
},
"required": [ "$oid" ]
}
]
}
}
}
When I try to validate I get type must be of type string/array of strings
. Do you have a suggestion how to define this kind of complex types?
PS: I know that the JSON schema still draft and it is vague. So, the implementations of JSON schema can diverge. In this case I'm trying to reuse (and measure how difficult it could be to adapt schemas, create Pull Requests etc) my schemas definitions which work with json-schema-ruby.
from gojsonschema.
This is in my opinion a strange way to write a schema given your needs.
I based my work on this http://json-schema.org/latest/json-schema-validation.html#anchor79 for the type keyword.
You could also use the OneOf keyword.
from gojsonschema.
Related Issues (20)
- About nesting json
- Validation should fail if required key is Go Zero Value for the corresponding type
- gojsonschema.NewGoLoader() returns NOTHING
- validation mishandles anyOf
- Load schema from string HOT 1
- The validate cannot find unknow fields
- Retry on "Could not read schema from HTTP, response status is 503 Service Temporarily Unavailable" HOT 2
- Validate return err on golang 1.19 HOT 1
- A DOS vulnerability exists in parameter validity check. HOT 2
- can we create json schema from json data HOT 1
- Using Frogbot to scan this repository
- Get all properties under a section
- Wrong validation result for nested objects HOT 2
- Usage of gojsonschema in prominent open-source or large-scale projects?
- Validation errors with integers
- Error "Must be a multiple of 0.01" for Value=2000000.13
- Hostname format false positives
- Support `errorMessage` so as to customise validation errors
- major api improvement HOT 2
- invalid character '{{character}}' looking for beginning of value
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 gojsonschema.