subSchema.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. // author xeipuuv
  15. // author-github https://github.com/xeipuuv
  16. // author-mail xeipuuv@gmail.com
  17. //
  18. // repository-name gojsonschema
  19. // repository-desc An implementation of JSON Schema, based on IETF's draft v4 - Go language.
  20. //
  21. // description Defines the structure of a sub-subSchema.
  22. // A sub-subSchema can contain other sub-schemas.
  23. //
  24. // created 27-02-2013
  25. package gojsonschema
  26. import (
  27. "github.com/xeipuuv/gojsonreference"
  28. "math/big"
  29. "regexp"
  30. )
  31. // Constants
  32. const (
  33. KEY_SCHEMA = "$schema"
  34. KEY_ID = "id"
  35. KEY_ID_NEW = "$id"
  36. KEY_REF = "$ref"
  37. KEY_TITLE = "title"
  38. KEY_DESCRIPTION = "description"
  39. KEY_TYPE = "type"
  40. KEY_ITEMS = "items"
  41. KEY_ADDITIONAL_ITEMS = "additionalItems"
  42. KEY_PROPERTIES = "properties"
  43. KEY_PATTERN_PROPERTIES = "patternProperties"
  44. KEY_ADDITIONAL_PROPERTIES = "additionalProperties"
  45. KEY_PROPERTY_NAMES = "propertyNames"
  46. KEY_DEFINITIONS = "definitions"
  47. KEY_MULTIPLE_OF = "multipleOf"
  48. KEY_MINIMUM = "minimum"
  49. KEY_MAXIMUM = "maximum"
  50. KEY_EXCLUSIVE_MINIMUM = "exclusiveMinimum"
  51. KEY_EXCLUSIVE_MAXIMUM = "exclusiveMaximum"
  52. KEY_MIN_LENGTH = "minLength"
  53. KEY_MAX_LENGTH = "maxLength"
  54. KEY_PATTERN = "pattern"
  55. KEY_FORMAT = "format"
  56. KEY_MIN_PROPERTIES = "minProperties"
  57. KEY_MAX_PROPERTIES = "maxProperties"
  58. KEY_DEPENDENCIES = "dependencies"
  59. KEY_REQUIRED = "required"
  60. KEY_MIN_ITEMS = "minItems"
  61. KEY_MAX_ITEMS = "maxItems"
  62. KEY_UNIQUE_ITEMS = "uniqueItems"
  63. KEY_CONTAINS = "contains"
  64. KEY_CONST = "const"
  65. KEY_ENUM = "enum"
  66. KEY_ONE_OF = "oneOf"
  67. KEY_ANY_OF = "anyOf"
  68. KEY_ALL_OF = "allOf"
  69. KEY_NOT = "not"
  70. KEY_IF = "if"
  71. KEY_THEN = "then"
  72. KEY_ELSE = "else"
  73. )
  74. type subSchema struct {
  75. draft *Draft
  76. // basic subSchema meta properties
  77. id *gojsonreference.JsonReference
  78. title *string
  79. description *string
  80. property string
  81. // Quick pass/fail for boolean schemas
  82. pass *bool
  83. // Types associated with the subSchema
  84. types jsonSchemaType
  85. // Reference url
  86. ref *gojsonreference.JsonReference
  87. // Schema referenced
  88. refSchema *subSchema
  89. // hierarchy
  90. parent *subSchema
  91. itemsChildren []*subSchema
  92. itemsChildrenIsSingleSchema bool
  93. propertiesChildren []*subSchema
  94. // validation : number / integer
  95. multipleOf *big.Rat
  96. maximum *big.Rat
  97. exclusiveMaximum *big.Rat
  98. minimum *big.Rat
  99. exclusiveMinimum *big.Rat
  100. // validation : string
  101. minLength *int
  102. maxLength *int
  103. pattern *regexp.Regexp
  104. format string
  105. // validation : object
  106. minProperties *int
  107. maxProperties *int
  108. required []string
  109. dependencies map[string]interface{}
  110. additionalProperties interface{}
  111. patternProperties map[string]*subSchema
  112. propertyNames *subSchema
  113. // validation : array
  114. minItems *int
  115. maxItems *int
  116. uniqueItems bool
  117. contains *subSchema
  118. additionalItems interface{}
  119. // validation : all
  120. _const *string //const is a golang keyword
  121. enum []string
  122. // validation : subSchema
  123. oneOf []*subSchema
  124. anyOf []*subSchema
  125. allOf []*subSchema
  126. not *subSchema
  127. _if *subSchema // if/else are golang keywords
  128. _then *subSchema
  129. _else *subSchema
  130. }