Comments (4)
yes. you can do that. for example consider following file "component.json"
{
"name": "DBInsert",
"ports": {
"input" : {
"schema": {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier for a product",
"type": "integer"
},
"name": {
"description": "Name of the product",
"type": "string"
},
"price": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
}
},
"required": ["id", "name", "price"]
}
},
"output": {
"schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/product.schema.json",
"title": "Product",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
"productId": {
"description": "The unique identifier for a product",
"type": "integer"
}
},
"required": [ "productId" ]
}
}
}
}
there are two jsonschemas embedded in above json. one for input
and another for output
to load jsonschemas:
inschema, err := jsonschema.Compile("component.json#/ports/input")
if err!=nil {
panic(err)
}
outschema, err := jsonschema.Compile("component.json#/ports/output")
if err!=nil {
panic(err)
}
i.e, you can specify jsonpointer after the filename separated by #
from jsonschema.
Thanks for the reply. That is pretty close to what I need.
I'm looking at something like this (YAML instead of JSON for readability only):
schema_property_a:
...
schema_property_b:
...
sub_documents:
- schema_property_a:
...
schema_property_b:
...
sub_documents:
- ... etc
I looked a little closer at the code and see that jsonschema.Compile("file.json#/schema_property_a")
followed by jsonschema.Compile("file.json#/schema_property_b")
will internally result in a single resource
with two Schema
objects in a map by ref.
I'll need to traverse down the document into a potentially large number subdocument. I could just recursively build the refs until I hit an invalid reference but that seems terribly inefficient. If I had access to resource.doc
and maybe Compiler.compile()
, I could just traverse the data structure and create Schema objects from data I know to be JSON-Schema..
from jsonschema.
yes. resources are cached in compiler for reuse.
for your json document, resource.doc
will be of type map[string]interface{}
. so even if you have access to this field, you still need to parse the map recursively to find potential schema documents.
only difference will be you have avoiding parsing json document into map[string][interface{}]
why can't you simply parse json doucment into map[string][interface{}]
. traverse it recursively to find potential schemas and find jsonpointer's to them
from jsonschema.
I guess I could do something like that. Initialization performance is not critical anyway. Thanks for the info :)
from jsonschema.
Related Issues (20)
- Error when loading valid draft7 json schema HOT 2
- Validating json with json-schema HOT 4
- Draft2020 accepts invalid email address. HOT 5
- Support for $defs and definition keyword in Schema object. HOT 3
- ReadOnly and WriteOnly are getting ignored HOT 7
- i18n support
- Detailed output missing info
- Compiling a subresource with an extension validates the subresource against the root extension schema. HOT 6
- unexpected validation error which LSP is fine with HOT 10
- Provide CLI binaries with release HOT 2
- Link in README for YAML playground example is broken HOT 1
- Issue with custom Regex Library HOT 10
- `Compiler.AddResource` for adding pre-compiled schemas HOT 5
- Feature: Adding Context to Validate Method HOT 2
- implementing json.Marshaler interface HOT 9
- Create JSONSchema from Compile()'s result HOT 2
- Wrong unevaluatedProperties validation errors HOT 6
- compiler.go bug in 171
- Invalid JSON schema does not error out HOT 2
- [bug] Not reading from stdin HOT 2
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 jsonschema.