File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,9 @@ implementation 'io.github.optimumcode:json-schema-validator:0.0.11-SNAPSHOT'
103
103
104
104
### Example
105
105
106
+ If you have just one JSON schema or many independent schemes
107
+ you can create it using factory methods defined on ` JsonSchema ` class.
108
+
106
109
``` kotlin
107
110
import io.github.optimumcode.json.schema.JsonSchema
108
111
import io.github.optimumcode.json.schema.ValidationError
@@ -131,6 +134,44 @@ val elementToValidate: JsonElement = loadJsonToValidate()
131
134
val valid = schema.validate(elementToValidate, errors::add)
132
135
```
133
136
137
+ If you need to use more than one schema, and they have references to other schemas you should use ` JsonSchemaLoader ` class.
138
+
139
+ ``` kotlin
140
+ import io.github.optimumcode.json.schema.JsonSchemaLoader
141
+ import io.github.optimumcode.json.schema.JsonSchema
142
+ import io.github.optimumcode.json.schema.ValidationError
143
+ import kotlinx.serialization.json.JsonElement
144
+
145
+ val schema: JsonSchema = JsonSchemaLoader .create()
146
+ .register(
147
+ """
148
+ {
149
+ "${KEY } id": "https://test.com",
150
+ "properties": {
151
+ "name": {
152
+ "type": "string"
153
+ }
154
+ }
155
+ }
156
+ """ .trimIndent(),
157
+ ).fromDefinition(
158
+ """
159
+ {
160
+ "properties": {
161
+ "anotherName": {
162
+ "${KEY } ref": "https://test.com#/properties/name"
163
+ }
164
+ }
165
+ }
166
+ """ .trimIndent(),
167
+ )
168
+
169
+ val errors = mutableListOf<ValidationError >()
170
+ val elementToValidate: JsonElement = loadJsonToValidate()
171
+
172
+ val valid = schema.validate(elementToValidate, errors::add)
173
+ ```
174
+
134
175
## Supported JSON schema drafts:
135
176
136
177
- [ Draft 7] ( https://json-schema.org/specification-links.html#draft-7 )
You can’t perform that action at this time.
0 commit comments