Class ReferenceSchema

java.lang.Object
org.everit.json.schema.Schema
org.everit.json.schema.ReferenceSchema

public class ReferenceSchema extends Schema
This class is used by SchemaLoader to resolve JSON pointers during the construction of the schema. This class has been made mutable to permit the loading of recursive schemas.
  • Constructor Details

  • Method Details

    • builder

      public static ReferenceSchema.Builder builder()
    • definesProperty

      public boolean definesProperty(String field)
      Description copied from class: Schema
      Determines if this Schema instance defines any restrictions for the object property denoted by field. The field should be a JSON pointer, denoting the property to be queried.

      For example the field "#/rectangle/a" is defined by the following schema:

       
       objectWithSchemaRectangleDep" : {
         "type" : "object",
         "dependencies" : {
             "d" : {
                 "type" : "object",
                 "properties" : {
                     "rectangle" : {
                        "$ref" : "#/definitions/Rectangle"
                     },
                     "list": {
                         "type": "array",
                         "items": {
                             "properties": {
                                "prop": {}
                             }
                         },
                         "minItems": 2,
                         "maxItems: 3
                     }
                 }
             }
         },
         "definitions" : {
             "size" : {
                 "type" : "number",
                 "minimum" : 0
             },
             "Rectangle" : {
                 "type" : "object",
                 "properties" : {
                     "a" : {"$ref" : "#/definitions/size"},
                     "b" : {"$ref" : "#/definitions/size"}
                 }
             }
          }
       }
       
       
      You can also check if a subschema of an array defines a property. In that case, to traverse the array, you can either use an integer array index, or the "all" or "any" meta-indexes. For example, in the above schema
      • definesProperty("#/list/any/prop") returns true
      • definesProperty("#/list/all/prop") returns true
      • definesProperty("#/list/1/prop") returns true
      • definesProperty("#/list/1/nonexistent") returns false (the property is not present in the subschema)
      • definesProperty("#/list/8/prop") returns false (the "list" does not define property 8, since "maxItems" is 3)
      The default implementation of this method always returns false.
      Overrides:
      definesProperty in class Schema
      Parameters:
      field - should be a JSON pointer in its string representation.
      Returns:
      true if the propertty denoted by field is defined by this schema instance
    • getReferredSchema

      public Schema getReferredSchema()
    • getReferenceValue

      public String getReferenceValue()
    • setReferredSchema

      public void setReferredSchema(Schema referredSchema)
      Called by SchemaLoader.load() to set the referred root schema after completing the loading process of the entire schema document.
      Parameters:
      referredSchema - the referred schema
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Schema
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Schema
    • canEqual

      protected boolean canEqual(Object other)
      Description copied from class: Schema
      Since we add state in subclasses, but want those subclasses to be non final, this allows us to have equals methods that satisfy the equals contract.

      http://www.artima.com/lejava/articles/equality.html

      Overrides:
      canEqual in class Schema
      Parameters:
      other - the subject of comparison
      Returns:
      true if this can be equal to other
    • getUnprocessedProperties

      public Map<String,Object> getUnprocessedProperties()
      Description copied from class: Schema
      Returns the properties of the original schema JSON which aren't keywords of json schema (therefore they weren't recognized during schema loading).
      Overrides:
      getUnprocessedProperties in class Schema
    • getTitle

      public String getTitle()
      Overrides:
      getTitle in class Schema
    • getDescription

      public String getDescription()
      Overrides:
      getDescription in class Schema
    • getLocation

      public SchemaLocation getLocation()
      Overrides:
      getLocation in class Schema