diff --git a/Makefile.am b/Makefile.am index 796aa99b5..8eb2d95d8 100755 --- a/Makefile.am +++ b/Makefile.am @@ -100,7 +100,6 @@ EXTRA_DIST = \ debian \ doc \ doap.rdf \ - json-schema.json \ package.json \ sonar-project.properties \ LICENSE \ diff --git a/configure.ac b/configure.ac index ddbf24f85..27299b491 100755 --- a/configure.ac +++ b/configure.ac @@ -742,6 +742,8 @@ AC_CONFIG_FILES([ lib/hs/Makefile lib/java/Makefile lib/js/test/Makefile + lib/json/Makefile + lib/json/test/Makefile lib/nodejs/Makefile lib/perl/Makefile lib/perl/test/Makefile diff --git a/lib/Makefile.am b/lib/Makefile.am index 44bb9ff41..650f3823b 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -17,7 +17,7 @@ # under the License. # -SUBDIRS = +SUBDIRS = json PRECROSS_TARGET = if WITH_CPP diff --git a/lib/json/Makefile.am b/lib/json/Makefile.am new file mode 100644 index 000000000..1051b9bac --- /dev/null +++ b/lib/json/Makefile.am @@ -0,0 +1,29 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +SUBDIRS = + +if WITH_JAVA +# Schema validation test depends on java +SUBDIRS += test +endif + +EXTRA_DIST = \ + schema.json \ + test diff --git a/json-schema.json b/lib/json/schema.json similarity index 70% rename from json-schema.json rename to lib/json/schema.json index d61216a3e..011b4d37a 100644 --- a/json-schema.json +++ b/lib/json/schema.json @@ -1,16 +1,18 @@ { "$schema": "http://json-schema.org/draft-04/schema#", - "id": "http://thrift.apache.org/program-schema#", + "id": "http://thrift.apache.org/schema.json#", "description": "Schema for Apache Thrift protocol descriptors", "definitions": { "type-id": { + "title": "Any type id (name)", "enum": [ "void", "string", "bool", "byte", + "i8", "i16", "i32", "i64", @@ -20,66 +22,78 @@ "map", "union", "struct", - "exception", "binary" ] }, "base-type": { - "title": "Base types", + "title": "Base type schema", "type": "object", "properties": { "typeId": { - "enum": [ "void", "string", "bool", "byte", "i16", "i32", "i64", "double", "binary" ] + "enum": ["void", "string", "bool", "byte", "i8", "i16", "i32", "i64", "double", "binary" ] } }, "required": [ "typeId" ] }, "list-type": { - "title": "List and set types", + "title": "List and set schema", "type": "object", "properties": { - "typeId": { "enum": [ "list", "set" ] }, - "elemTypeId": { "$ref": "#/definitions/type-id" }, - "elemType": { "$ref": "#/definitions/type-spec" } + "typeId": { + "enum": [ "list", "set" ] + }, + "elemTypeId": { "$ref": "#/definitions/type-id" }, + "elemType": { "$ref": "#/definitions/type-desc" } }, - "required": [ "typeId", "elemTypeId", "elemType" ] + "required": [ "typeId", "elemTypeId" ] }, "map-type": { - "title": "Map type", + "title": "Map schema", "type": "object", "properties": { - "typeId": { "enum": [ "map" ] }, + "typeId": { + "enum": [ "map" ] + }, "keyTypeId": { "$ref": "#/definitions/type-id" }, - "keyType": { "$ref": "#/definitions/type-spec" }, + "keyType": { "$ref": "#/definitions/type-desc" }, "valueTypeId": { "$ref": "#/definitions/type-id" }, - "valueType": { "$ref": "#/definitions/type-spec" } + "valueType": { "$ref": "#/definitions/type-desc" } }, "required": [ "typeId", "keyTypeId", "valueTypeId" ] }, - "struct-spec": { - "title": "Struct and union types", + "struct-type": { + "title": "Struct, union and exception schema", "type": "object", "properties": { - "typeId": { "enum": [ "union", "struct" ] }, - "class": { "type": "string" } + "typeId": { + "enum": [ "union", "struct", "exception" ] + } }, "required": [ "typeId", "class" ] }, - "type-spec": { + "type-desc": { + "title": "Type descriptor schema", "allOf": [ - { "type": "object" }, + { + "type": "object", + "properties": { + "typeId": { "type": "string" }, + "class": { "type": "string" } + } + }, { "oneOf": [ { "$ref": "#/definitions/base-type" }, { "$ref": "#/definitions/list-type" }, { "$ref": "#/definitions/map-type" }, - { "$ref": "#/definitions/struct-spec" } + { "$ref": "#/definitions/struct-type" } ] } ] }, "name-and-doc": { + "title": "Name and documentation sub-schema", "type": "object", "properties": { "name": { "type": "string" }, @@ -88,6 +102,7 @@ "required": [ "name" ] }, "enum": { + "title": "Thrift 'enum' definition schema", "type": "object", "allOf": [ { "$ref": "#/definitions/name-and-doc" }, @@ -110,23 +125,25 @@ ] }, "typedef": { + "title": "Thrift typedef definition schema", "type": "object", "allOf": [ { "$ref": "#/definitions/name-and-doc" }, { "properties": { "typeId": { "$ref": "#/definitions/type-id" }, - "type": { "$ref": "#/definitions/type-spec" } + "type": { "$ref": "#/definitions/type-desc" } }, "required": [ "typeId" ] } ] }, "constant": { + "title": "Thrift constant definition schema", "type": "object", "allOf": [ { "$ref": "#/definitions/name-and-doc" }, - { "$ref": "#/definitions/type-spec" }, + { "$ref": "#/definitions/type-desc" }, { "properties": { "value": { @@ -143,10 +160,10 @@ ] }, "field": { + "title": "Thrift struct field definition schema", "type": "object", "allOf": [ { "$ref": "#/definitions/name-and-doc" }, - { "$ref": "#/definitions/type-spec" }, { "properties": { "key": { @@ -157,6 +174,8 @@ "required": { "enum": [ "required", "optional", "req_out" ] }, + "typeId": { "$ref": "#/definitions/type-id" }, + "type": { "$ref": "#/definitions/type-desc" }, "default": { "oneOf": [ { "type": "string" }, @@ -171,6 +190,7 @@ ] }, "struct": { + "title": "Thrift struct definition schema", "type": "object", "allOf": [ { "$ref": "#/definitions/name-and-doc" }, @@ -190,45 +210,46 @@ ] }, "union": { + "title": "Thrift union definition schema", "$ref": "#/definitions/struct" }, "exception": { - "$ref": "#/definitions/struct" + "title": "Thrift exception definition schema", + "type": "object", + "properties": { + "key": { + "type": "integer", + "minimum": 1, + "maximum": 65535 + }, + "name": { "type": "string" }, + "typeId": { "enum": [ "exception" ] }, + "type": { "$ref": "#/definitions/struct-type" } + }, + "required": [ "key", "name", "typeId" ] }, "function": { + "title": "Thrift service function definition schema", "type": "object", "allOf": [ { "$ref": "#/definitions/name-and-doc" }, - { - "oneOf": [ - { - "properties": { "oneway": { "type": "boolean" } }, - "required": [ "oneway" ] - }, - { - "properties": { "returnType": { "$ref": "#/definitions/type-spec" } }, - "required": [ "returnType" ] - } - ] - }, { "properties": { + "oneway": { + "type": "boolean" + }, + "returnType": { + "$ref": "#/definitions/type-desc" + }, "arguments": { "type": "array", "items": { - "allOf": [ - { "$ref": "#/definitions/field" }, - { - "properties": { } - } - ] + "$ref": "#/definitions/field" } }, "exceptions": { "type": "array", - "items": { - "$ref": "#/definitions/exception" - } + "items": { "$ref": "#/definitions/exception" } } }, "required": [ "oneway", "arguments", "exceptions" ] @@ -236,6 +257,7 @@ ] }, "service": { + "title": "Thrift service definition schema", "type": "object", "allOf": [ { "$ref": "#/definitions/name-and-doc" }, @@ -257,8 +279,6 @@ "type": "object", "required": [ "name", - "namespaces", - "includes", "enums", "typedefs", "structs", diff --git a/lib/json/test/Makefile.am b/lib/json/test/Makefile.am new file mode 100644 index 000000000..bb87a5203 --- /dev/null +++ b/lib/json/test/Makefile.am @@ -0,0 +1,26 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +check: + $(ANT) $(ANT_FLAGS) test + +# Make sure this doesn't fail if ant is not configured. +clean-local: + ANT=$(ANT) ; if test -z "$$ANT" ; then ANT=: ; fi ; \ + $$ANT $(ANT_FLAGS) clean diff --git a/lib/json/test/build.properties b/lib/json/test/build.properties new file mode 100644 index 000000000..075f64001 --- /dev/null +++ b/lib/json/test/build.properties @@ -0,0 +1,10 @@ +# Jar versions +mvn.ant.task.version=2.1.3 + +# Dependency versions +json-schema-validator.version=2.2.6 + +# Maven dependency download locations +mvn.repo=http://repo1.maven.org/maven2 +mvn.ant.task.url=${mvn.repo}/org/apache/maven/maven-ant-tasks/${mvn.ant.task.version} +mvn.ant.task.jar=maven-ant-tasks-${mvn.ant.task.version}.jar diff --git a/lib/json/test/build.xml b/lib/json/test/build.xml new file mode 100644 index 000000000..956a2382b --- /dev/null +++ b/lib/json/test/build.xml @@ -0,0 +1,144 @@ + + + + JSON Schema Validation Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Thrift compiler is missing ! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +