You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2016/04/15 16:18:55 UTC

lucene-solr:apiv2: SOLR-8995: support string fro numbers and booleans in json. and added spec for schema API

Repository: lucene-solr
Updated Branches:
  refs/heads/apiv2 db32de3a8 -> 2519b2fe6


SOLR-8995: support string fro numbers and booleans in json. and added spec for schema API


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/2519b2fe
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/2519b2fe
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/2519b2fe

Branch: refs/heads/apiv2
Commit: 2519b2fe6fe01822868dc2735c77cc7ab641eef8
Parents: db32de3
Author: Noble Paul <no...@apache.org>
Authored: Fri Apr 15 19:48:23 2016 +0530
Committer: Noble Paul <no...@apache.org>
Committed: Fri Apr 15 19:48:23 2016 +0530

----------------------------------------------------------------------
 .../apache/solr/util/JsonSchemaValidator.java   | 27 +++++++++++++--
 .../apispec/core.SchemaEdit.addFieldType.json   | 35 +++++++++++++++++++-
 .../core.SchemaEdit.deleteCopyField.json        | 13 +++++---
 .../core.SchemaEdit.deleteDynamicField.json     |  7 +++-
 .../apispec/core.SchemaEdit.deleteField.json    |  1 +
 .../core.SchemaEdit.deleteFieldType.json        | 10 +++++-
 .../org/apache/solr/util/JsonValidatorTest.java | 15 +++++++++
 7 files changed, 99 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2519b2fe/solr/core/src/java/org/apache/solr/util/JsonSchemaValidator.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/util/JsonSchemaValidator.java b/solr/core/src/java/org/apache/solr/util/JsonSchemaValidator.java
index 1118fa8..9497ae7 100644
--- a/solr/core/src/java/org/apache/solr/util/JsonSchemaValidator.java
+++ b/solr/core/src/java/org/apache/solr/util/JsonSchemaValidator.java
@@ -240,8 +240,31 @@ public class JsonSchemaValidator {
         }
       }
     },
-    NUMBER(o -> o instanceof Number),
-    BOOLEAN(o -> o instanceof Boolean),
+    NUMBER(o -> o instanceof Number) {
+      @Override
+      void valdateData(String key, Object o, Attribute attr, List<String> errs) {
+        if (o instanceof String) {
+          try {
+            Double.parseDouble((String) o);
+          } catch (NumberFormatException e) {
+            errs.add(e.getClass().getName()+" "+ e.getMessage());
+          }
+
+        }
+      }
+    },
+    BOOLEAN(o -> o instanceof Boolean) {
+      @Override
+      void valdateData(String key, Object o, Attribute attr, List<String> errs) {
+        if (o instanceof String) {
+          try {
+            Boolean.parseBoolean((String) o);
+          } catch (Exception e) {
+            errs.add(e.getClass().getName()+" "+ e.getMessage());
+          }
+        }
+      }
+    },
     OBJECT(o -> o instanceof Map),
     UNKNOWN((o -> true));
     final String _name;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2519b2fe/solr/core/src/resources/apispec/core.SchemaEdit.addFieldType.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/core.SchemaEdit.addFieldType.json b/solr/core/src/resources/apispec/core.SchemaEdit.addFieldType.json
index be6e2e9..6e19f07 100644
--- a/solr/core/src/resources/apispec/core.SchemaEdit.addFieldType.json
+++ b/solr/core/src/resources/apispec/core.SchemaEdit.addFieldType.json
@@ -1,4 +1,37 @@
 {
   "type":"object",
-  "additionalProperties": true
+  "properties": {
+    "name": {
+      "type": "string"
+    },
+    "class": {
+      "type": "string"
+    },
+    "positionIncrementGap": {
+      "type": "number"
+    },
+    "autoGeneratePhraseQueries": {
+      "type": "boolean"
+    },
+    "docValuesFormat": {
+      "type": "string"
+    },
+    "postingsFormat": {
+      "type": "string"
+    },
+    "analyzer": {
+      "type": "object",
+      "properties": {
+        "type": {
+          "type": "string"
+        }
+      },
+      "additionalProperties": true
+    }
+  },
+  "additionalProperties": true,
+  "required": [
+    "name",
+    "class"
+  ]
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2519b2fe/solr/core/src/resources/apispec/core.SchemaEdit.deleteCopyField.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/core.SchemaEdit.deleteCopyField.json b/solr/core/src/resources/apispec/core.SchemaEdit.deleteCopyField.json
index dd7b818..b33549e 100644
--- a/solr/core/src/resources/apispec/core.SchemaEdit.deleteCopyField.json
+++ b/solr/core/src/resources/apispec/core.SchemaEdit.deleteCopyField.json
@@ -1,11 +1,16 @@
 {
   "type":"object",
-  "documentation":"https://cwiki.apache.org/confluence/display/solr/Schema+API#SchemaAPI-DeleteaField",
+  "documentation": "https://cwiki.apache.org/confluence/display/solr/Schema+API#SchemaAPI-DeleteaCopyFieldRule",
   "properties":{
-    "name":{
-      "description":"The delete-field command removes a field definition from your schema. If the field does not exist in the schema, or if the field is the source or destination of a copy field rule, an error is thrown",
+    "source": {
       "type":"string"
+    },
+    "dest": {
+      "type": "string"
     }
   },
-  "required": ["type"]
+  "required": [
+    "source",
+    "dest"
+  ]
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2519b2fe/solr/core/src/resources/apispec/core.SchemaEdit.deleteDynamicField.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/core.SchemaEdit.deleteDynamicField.json b/solr/core/src/resources/apispec/core.SchemaEdit.deleteDynamicField.json
index de27e24..4f34833 100644
--- a/solr/core/src/resources/apispec/core.SchemaEdit.deleteDynamicField.json
+++ b/solr/core/src/resources/apispec/core.SchemaEdit.deleteDynamicField.json
@@ -1,4 +1,9 @@
 {
+  "documentation": "https://cwiki.apache.org/confluence/display/solr/Schema+API#SchemaAPI-DeleteaDynamicFieldRule",
   "type":"object",
-  "additionalProperties":true
+  "properties": {
+    "name": {
+      "type": "string"
+    }
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2519b2fe/solr/core/src/resources/apispec/core.SchemaEdit.deleteField.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/core.SchemaEdit.deleteField.json b/solr/core/src/resources/apispec/core.SchemaEdit.deleteField.json
index 3952606..1a6126d 100644
--- a/solr/core/src/resources/apispec/core.SchemaEdit.deleteField.json
+++ b/solr/core/src/resources/apispec/core.SchemaEdit.deleteField.json
@@ -1,4 +1,5 @@
 {
+  "documentation" : "https://cwiki.apache.org/confluence/display/solr/Schema+API#SchemaAPI-DeleteaField",
   "type":"object",
   "properties":{
     "name":{

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2519b2fe/solr/core/src/resources/apispec/core.SchemaEdit.deleteFieldType.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/core.SchemaEdit.deleteFieldType.json b/solr/core/src/resources/apispec/core.SchemaEdit.deleteFieldType.json
index de27e24..fd17753 100644
--- a/solr/core/src/resources/apispec/core.SchemaEdit.deleteFieldType.json
+++ b/solr/core/src/resources/apispec/core.SchemaEdit.deleteFieldType.json
@@ -1,4 +1,12 @@
 {
+  "documentation":"https://cwiki.apache.org/confluence/display/solr/Schema+API#SchemaAPI-DeleteaFieldType",
   "type":"object",
-  "additionalProperties":true
+  "properties": {
+    "name": {
+      "type": "string"
+    }
+  },
+  "required": [
+    "name"
+  ]
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2519b2fe/solr/core/src/test/org/apache/solr/util/JsonValidatorTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/util/JsonValidatorTest.java b/solr/core/src/test/org/apache/solr/util/JsonValidatorTest.java
index 93bdf30..6e446f5 100644
--- a/solr/core/src/test/org/apache/solr/util/JsonValidatorTest.java
+++ b/solr/core/src/test/org/apache/solr/util/JsonValidatorTest.java
@@ -69,6 +69,21 @@ public class JsonValidatorTest extends SolrTestCaseJ4 {
     errs = validator.validateJson(Utils.fromJSONString("{name : x, collections: [ 1 , 2]}"));
     assertFalse(toJSONString(errs), errs.isEmpty());
     assertTrue(toJSONString(errs), errs.get(0).contains("Expected elements of type"));
+    Map schema = (Map) Utils.fromJSONString("{" +
+        "  type:object," +
+        "  properties: {" +
+        "   age : {type: number}," +
+        "   adult : {type: boolean}," +
+        "   name: {type: string}}}");
+    validator = new JsonSchemaValidator(schema);
+    errs = validator.validateJson(Utils.fromJSONString("{name:x, age:21, adult:true}"));
+    assertNull(errs);
+    errs = validator.validateJson(Utils.fromJSONString("{name:x, age:'21', adult:'true'}"));
+    assertNull(errs);
+
+    errs = validator.validateJson(Utils.fromJSONString("{name:x, age:'x21', adult:'true'}"));
+    assertEquals(1, errs.size());
+    
 
   }