...

Source file src/github.com/xeipuuv/gojsonschema/subSchema.go

Documentation: github.com/xeipuuv/gojsonschema

     1  // Copyright 2015 xeipuuv ( https://github.com/xeipuuv )
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //   http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // author           xeipuuv
    16  // author-github    https://github.com/xeipuuv
    17  // author-mail      xeipuuv@gmail.com
    18  //
    19  // repository-name  gojsonschema
    20  // repository-desc  An implementation of JSON Schema, based on IETF's draft v4 - Go language.
    21  //
    22  // description      Defines the structure of a sub-subSchema.
    23  //                  A sub-subSchema can contain other sub-schemas.
    24  //
    25  // created          27-02-2013
    26  
    27  package gojsonschema
    28  
    29  import (
    30  	"github.com/xeipuuv/gojsonreference"
    31  	"math/big"
    32  	"regexp"
    33  )
    34  
    35  // Constants
    36  const (
    37  	KEY_SCHEMA                = "$schema"
    38  	KEY_ID                    = "id"
    39  	KEY_ID_NEW                = "$id"
    40  	KEY_REF                   = "$ref"
    41  	KEY_TITLE                 = "title"
    42  	KEY_DESCRIPTION           = "description"
    43  	KEY_TYPE                  = "type"
    44  	KEY_ITEMS                 = "items"
    45  	KEY_ADDITIONAL_ITEMS      = "additionalItems"
    46  	KEY_PROPERTIES            = "properties"
    47  	KEY_PATTERN_PROPERTIES    = "patternProperties"
    48  	KEY_ADDITIONAL_PROPERTIES = "additionalProperties"
    49  	KEY_PROPERTY_NAMES        = "propertyNames"
    50  	KEY_DEFINITIONS           = "definitions"
    51  	KEY_MULTIPLE_OF           = "multipleOf"
    52  	KEY_MINIMUM               = "minimum"
    53  	KEY_MAXIMUM               = "maximum"
    54  	KEY_EXCLUSIVE_MINIMUM     = "exclusiveMinimum"
    55  	KEY_EXCLUSIVE_MAXIMUM     = "exclusiveMaximum"
    56  	KEY_MIN_LENGTH            = "minLength"
    57  	KEY_MAX_LENGTH            = "maxLength"
    58  	KEY_PATTERN               = "pattern"
    59  	KEY_FORMAT                = "format"
    60  	KEY_MIN_PROPERTIES        = "minProperties"
    61  	KEY_MAX_PROPERTIES        = "maxProperties"
    62  	KEY_DEPENDENCIES          = "dependencies"
    63  	KEY_REQUIRED              = "required"
    64  	KEY_MIN_ITEMS             = "minItems"
    65  	KEY_MAX_ITEMS             = "maxItems"
    66  	KEY_UNIQUE_ITEMS          = "uniqueItems"
    67  	KEY_CONTAINS              = "contains"
    68  	KEY_CONST                 = "const"
    69  	KEY_ENUM                  = "enum"
    70  	KEY_ONE_OF                = "oneOf"
    71  	KEY_ANY_OF                = "anyOf"
    72  	KEY_ALL_OF                = "allOf"
    73  	KEY_NOT                   = "not"
    74  	KEY_IF                    = "if"
    75  	KEY_THEN                  = "then"
    76  	KEY_ELSE                  = "else"
    77  )
    78  
    79  type subSchema struct {
    80  	draft *Draft
    81  
    82  	// basic subSchema meta properties
    83  	id          *gojsonreference.JsonReference
    84  	title       *string
    85  	description *string
    86  
    87  	property string
    88  
    89  	// Quick pass/fail for boolean schemas
    90  	pass *bool
    91  
    92  	// Types associated with the subSchema
    93  	types jsonSchemaType
    94  
    95  	// Reference url
    96  	ref *gojsonreference.JsonReference
    97  	// Schema referenced
    98  	refSchema *subSchema
    99  
   100  	// hierarchy
   101  	parent                      *subSchema
   102  	itemsChildren               []*subSchema
   103  	itemsChildrenIsSingleSchema bool
   104  	propertiesChildren          []*subSchema
   105  
   106  	// validation : number / integer
   107  	multipleOf       *big.Rat
   108  	maximum          *big.Rat
   109  	exclusiveMaximum *big.Rat
   110  	minimum          *big.Rat
   111  	exclusiveMinimum *big.Rat
   112  
   113  	// validation : string
   114  	minLength *int
   115  	maxLength *int
   116  	pattern   *regexp.Regexp
   117  	format    string
   118  
   119  	// validation : object
   120  	minProperties *int
   121  	maxProperties *int
   122  	required      []string
   123  
   124  	dependencies         map[string]interface{}
   125  	additionalProperties interface{}
   126  	patternProperties    map[string]*subSchema
   127  	propertyNames        *subSchema
   128  
   129  	// validation : array
   130  	minItems    *int
   131  	maxItems    *int
   132  	uniqueItems bool
   133  	contains    *subSchema
   134  
   135  	additionalItems interface{}
   136  
   137  	// validation : all
   138  	_const *string //const is a golang keyword
   139  	enum   []string
   140  
   141  	// validation : subSchema
   142  	oneOf []*subSchema
   143  	anyOf []*subSchema
   144  	allOf []*subSchema
   145  	not   *subSchema
   146  	_if   *subSchema // if/else are golang keywords
   147  	_then *subSchema
   148  	_else *subSchema
   149  }
   150  

View as plain text