Given the following basic example of a text element which references a para element and the para element itself references the para element.
I'm wondering if I'm correctly representing this in JSON Schema?
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="text">
<xs:complexType>
<xs:sequence>
<xs:element ref="para"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="para">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="para"/>
</xs:choice>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:element>
</xs:schema>
I think that it has to be done with this style { "$ref": "#/definitions/diskDevice" },
http://json-schema.org/example2.html.
Is this correct?
{
"id": "http://some.site.somewhere/entry-schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "text",
"type": "object",
"properties": {
"$ref": "#/definitions/para"
},
"definitions": {"para": {
"required": true,
"type": "object",
"properties": {
"id": {
"type": "string",
"required": true
},
"$ref": "#/definitions/para"
}
}
}
}
Thanks
That form of referencing is correct. It is not the only way to organise things, but it is the way I would recommend.
You do have a bug in your schema, though - you have "$ref" directly inside "properties". You are presumably not defining a property called "$ref" in your data, so is this meant to be inside another property declaration?
Related
I am using angular6-json-schema-form library for the first time and created a example.json file with schema and data section
How to reference the angular6-json-schema-form library referenced draft version of core meta schema definations from example.json
"schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://someurl/example.json",
"type": "object",
"properties": {
"id": {
"type": "number"
},
"formName": {
"type": "string",
"maxlength": "$ref": "http://json-schema.org/draft-07/schema/definitions/nonNegativeInteger
}
}
},
"data": {
"id": "1",
"formName": "Application Form"
}
I am using avro maven plugin to generate java code for avro .avsc schema file, I have one common schema which is getting used at multiple places as separate record, when i give different namespace at each place, it is able to generate java code, but generated code is in different folders although code for both classes are same
Is there any way to generate only single class for common reference like above schenario... Here is my avsc
{
"namespace": "exmaple.avro",
"type": "record",
"name": "TopRecord",
"fields": [{
"name": "id",
"type": "string"
},
{
"name": "amount",
"type": "double"
},
{
"name": "AC",
"type": {
"type": "record",
"name": "AC_SCHEMA",
"fields": [{
"name": "id",
"type": "string"
},
{
"name": "amount",
"type": "double"
},
{
"name": "InnerCommon",
"type": {
"type": "record",
"name": "InnerSchema",
"fields": [{
"name": "id",
"type": "string"
}]
}
}
]
}
}, {
"name": "BC",
"type": {
"type": "record",
"name": "BC_SCHEMA",
"fields": [{
"name": "id",
"type": "string"
},
{
"name": "amount",
"type": "double"
},
{
"name": "InnerCommon",
"type": {
"type": "record",
"name": "InnerSchema",
"fields": [{
"name": "id",
"type": "string"
}]
}
}
]
}
}
]
}
If i give different namespaces for InnerCommon schema at both placed, it is able to generate code but with classes in 2 folders which have same code :(
Here is working avsc with namespace
{
"namespace": "exmaple.avro",
"type": "record",
"name": "TopRecord",
"fields": [{
"name": "id",
"type": "string"
},
{
"name": "amount",
"type": "double"
},
{
"name": "AC",
"type": {
"type": "record",
"name": "AC_SCHEMA",
"fields": [{
"name": "id",
"type": "string"
},
{
"name": "amount",
"type": "double"
},
{
"name": "InnerCommon",
"type": {
"type": "record",
"name": "InnerSchema",
"namespace": "inner1",
"fields": [{
"name": "id",
"type": "string"
}]
}
}
]
}
}, {
"name": "BC",
"type": {
"type": "record",
"name": "BC_SCHEMA",
"fields": [{
"name": "id",
"type": "string"
},
{
"name": "amount",
"type": "double"
},
{
"name": "InnerCommon",
"type": {
"type": "record",
"name": "InnerSchema",
"namespace": "inner2",
"fields": [{
"name": "id",
"type": "string"
}]
}
}
]
}
}
]
}
Here is the generated folder structure
Is there any way i can put all common generated stuff in single folder and have same namespace to remove duplication?
EDIT 1:
I need to register it to schema registry and check for evolution, i was wondering if there is any way to tell plugin not to override generated code and put only one class
You can move the common to definitions to their own avsc files, and then import the common files in your pom.xml spec for the avro-maven-plugin:
<plugins>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${avro.schema.dir}</sourceDirectory>
<imports>
<import>${my.common.dir}/my_common_type_1.avsc</import>
<import>${my.common.dir}/my_common_type_2.avsc</import>
</imports>
</configuration>
</execution>
</executions>
</plugin>
I am using Apache Solr 7.4. I am trying to use curl/postman to define some portions of my schema.
I was able to define field type and fields successfully, when I try to define a copy-field I am getting an error :
"copyField dest :'text' is not an explicit field and doesn't match a dynamicField
Here's my field type definition :
"add-field-type": {
"name": "text",
"class": "solr.TextField",
"positionIncrementGap": "100",
"indexAnalyzer": {
"charFilters": [{
"class": "solr.MappingCharFilterFactory",
"mapping": "mapping-ISOLatin1Accent.txt"
}],
"tokenizer": {
"class": "solr.KeywordTokenizerFactory"
},
"filters": [{
"class": "solr.LowerCaseFilterFactory"
},
{
"class": "solr.StopFilterFactory",
"ignoreCase": "true",
"words": "stopwords.txt"
},
{
"class": "solr.RemoveDuplicatesTokenFilterFactory"
}
]
},
"queryAnalyzer": {
"charFilters": [{
"class": "solr.MappingCharFilterFactory",
"mapping": "mapping-ISOLatin1Accent.txt"
}],
"tokenizer": {
"class": "solr.KeywordTokenizerFactory"
},
"filters": [{
"class": "solr.LowerCaseFilterFactory"
},
{
"class": "solr.StopFilterFactory",
"ignoreCase": "true",
"words": "stopwords.txt"
},
{
"class": "solr.LowerCaseFilterFactory"
},
{
"class": "solr.RemoveDuplicatesTokenFilterFactory"
}
]
}
}
I also added a dynamic field :
"add-dynamic-field":{
"name":"*_txt1",
"type":"text",
"stored":true,
"indexed":true
}
Here's my field :
"add-field": [{
"name": "path",
"type": "string",
"indexed": "true",
"stored": "false"
}
Its successful upto this. Now I am trying to add a copy field as below :
"add-copy-field":
{
"source":"path",
"dest": "text"
}
And this is where it is failing. Stuck at this, any help is appreciated. Thanks!
Your destination for copy field are wrong.
“dest”: “text”
You don’t have any field with “text” name, only field type with “text” name.
Make sure you have all the source and destination fields before making the copy fields.
For example if you want to copy two source fields to the destination field. Make sure all of those fields exist first.
<field name="destination" type="text" indexed="true" stored="true" required="false"/>
<field name="source1" type="text" indexed="false" stored="true" required="false" />
<field name="source2" type="text" indexed="false" stored="true" required="false" />
Then only you can make copy fields.
<copyField source="source1" dest="destination"/>
<copyField source="source2" dest="destination"/>
I have an json output which looks like,
"details": [
{
"id": "",
"name": "",
"status": "",
},
{
"id": "",
"name": "",
"status": "",
},
{
"id": "",
"name": "",
"status": "",
},
{
"id": "",
"name": "",
"status": "",
}
From this output I can iterate values like //jsonObject/details and fetching individual item like
json-eval('$.details.id'), but I want to store all Id's and Name's into a Array in wso2 ESB, from the output I get, Can anyone help me.
Not sure if that helps, I think the following pseydo code might do it but I haven't tried it.
//create an empty var
<property name="newArray" value=""/>
//iterate over the json
<iterate xmlns:ns="http://org.apache.synapse/xsd" continueParent="true" expression="//jsonObjects/object" id="MyIterator">
....
<property name="newArray" expression="fn:concat(get-property('newArray'),//jsonObjects/object/value)" scope="operation"/>
....
</iterate>
<log>
<property name="afterIterate" expression="get-property('operation','newArray')"/>
</log>
I am indexing data from MongoDB that roughly looks like
{
"name": "John Doe",
"age": "25",
"education": [
{
"title": "Masters",
"status": 53,
"finalProject": {
"title": "Integrating Advanced STJs using KKO",
"status": "In Progress"
}
},
{
"title": "Software Engineering",
"status": 52,
"finalProject": {
"title": "Use of LPI in Multi-sanctioned BPDs",
"status": "Completed"
}
},
{
"title": "Pre-Engineering",
"status": 51
},
{
"title": "Matriculation",
"status": 52
}
]
}
Notice that I have got two status fields; one at education.*.status which is integer and the other at education.*.finalProject.status. How can I specify copyFields for both?
I considered specifying them as follows in my schema
<field name="projectStatus" type="string" stored="true" indexed="true" multiValued="true"/>
<copyField source="*.finalProject.status" dest="projectStatus"/>
<field name="educationStatus" type="int" stored="true" indexed="true" multiValued="true"/>
<copyField source="*.status" dest="educationStatus"/>
but both the patterns seem to be conflicting as *.status already covers *.finalProject.status. How can I specify them both in separate copy fields?