Giter Club home page Giter Club logo

Comments (4)

santhosh-tekuri avatar santhosh-tekuri commented on May 15, 2024

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.

kleijnweb avatar kleijnweb commented on May 15, 2024

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.

santhosh-tekuri avatar santhosh-tekuri commented on May 15, 2024

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.

kleijnweb avatar kleijnweb commented on May 15, 2024

I guess I could do something like that. Initialization performance is not critical anyway. Thanks for the info :)

from jsonschema.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.