@zio.dev/zio-blocks 0.0.1 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.md +143 -15
- package/package.json +5 -2
- package/reference/binding.md +8 -14
- package/reference/chunk.md +36 -36
- package/reference/docs.md +2 -2
- package/reference/dynamic-value.md +34 -34
- package/reference/formats.md +16 -16
- package/reference/json-schema.md +20 -20
- package/reference/json.md +47 -47
- package/reference/optics.md +51 -37
- package/reference/reflect.md +3 -3
- package/reference/registers.md +7 -7
- package/reference/schema.md +18 -18
- package/reference/syntax.md +16 -16
- package/scope.md +481 -161
- package/reference/modifier.md +0 -276
- package/reference/reflect-transform.md +0 -387
- package/reference/type-class-derivation-internals.md +0 -632
|
@@ -33,7 +33,7 @@ Key design decisions:
|
|
|
33
33
|
|
|
34
34
|
Wraps scalar values in a `PrimitiveValue`:
|
|
35
35
|
|
|
36
|
-
```scala
|
|
36
|
+
```scala
|
|
37
37
|
import zio.blocks.schema.DynamicValue
|
|
38
38
|
|
|
39
39
|
// Using convenience constructors
|
|
@@ -53,7 +53,7 @@ val instant = DynamicValue.Primitive(
|
|
|
53
53
|
|
|
54
54
|
A collection of named fields, analogous to case classes or JSON objects:
|
|
55
55
|
|
|
56
|
-
```scala
|
|
56
|
+
```scala
|
|
57
57
|
import zio.blocks.schema.DynamicValue
|
|
58
58
|
import zio.blocks.chunk.Chunk
|
|
59
59
|
|
|
@@ -80,7 +80,7 @@ Field order is preserved and significant for equality. Use `sortFields` to norma
|
|
|
80
80
|
|
|
81
81
|
A tagged union value, analogous to sealed traits:
|
|
82
82
|
|
|
83
|
-
```scala
|
|
83
|
+
```scala
|
|
84
84
|
import zio.blocks.schema.DynamicValue
|
|
85
85
|
|
|
86
86
|
// A Some variant containing a value
|
|
@@ -101,7 +101,7 @@ some.caseValue // Some(DynamicValue.Primitive(...))
|
|
|
101
101
|
|
|
102
102
|
An ordered collection of values:
|
|
103
103
|
|
|
104
|
-
```scala
|
|
104
|
+
```scala
|
|
105
105
|
import zio.blocks.schema.DynamicValue
|
|
106
106
|
import zio.blocks.chunk.Chunk
|
|
107
107
|
|
|
@@ -126,7 +126,7 @@ val empty = DynamicValue.Sequence.empty
|
|
|
126
126
|
|
|
127
127
|
Key-value pairs where both keys and values are `DynamicValue`:
|
|
128
128
|
|
|
129
|
-
```scala
|
|
129
|
+
```scala
|
|
130
130
|
import zio.blocks.schema.DynamicValue
|
|
131
131
|
import zio.blocks.chunk.Chunk
|
|
132
132
|
|
|
@@ -152,7 +152,7 @@ Unlike `Record` which uses String keys, `Map` supports arbitrary `DynamicValue`
|
|
|
152
152
|
|
|
153
153
|
Represents the absence of a value:
|
|
154
154
|
|
|
155
|
-
```scala
|
|
155
|
+
```scala
|
|
156
156
|
import zio.blocks.schema.DynamicValue
|
|
157
157
|
|
|
158
158
|
val absent = DynamicValue.Null
|
|
@@ -199,7 +199,7 @@ val absent = DynamicValue.Null
|
|
|
199
199
|
|
|
200
200
|
Use `Schema.toDynamicValue` to convert typed Scala values to `DynamicValue`:
|
|
201
201
|
|
|
202
|
-
```scala
|
|
202
|
+
```scala
|
|
203
203
|
import zio.blocks.schema.{Schema, DynamicValue}
|
|
204
204
|
|
|
205
205
|
case class Person(name: String, age: Int)
|
|
@@ -220,7 +220,7 @@ val listDynamic = Schema[List[Int]].toDynamicValue(List(1, 2, 3))
|
|
|
220
220
|
|
|
221
221
|
Use `Schema.fromDynamicValue` to convert `DynamicValue` back to typed Scala values:
|
|
222
222
|
|
|
223
|
-
```scala
|
|
223
|
+
```scala
|
|
224
224
|
import zio.blocks.schema.{Schema, DynamicValue, SchemaError}
|
|
225
225
|
|
|
226
226
|
case class Person(name: String, age: Int)
|
|
@@ -248,7 +248,7 @@ val error = Schema[Person].fromDynamicValue(badDynamic)
|
|
|
248
248
|
|
|
249
249
|
Each `DynamicValue` has a corresponding `DynamicValueType` for runtime type checking:
|
|
250
250
|
|
|
251
|
-
```scala
|
|
251
|
+
```scala
|
|
252
252
|
import zio.blocks.schema.{DynamicValue, DynamicValueType}
|
|
253
253
|
|
|
254
254
|
val dv = DynamicValue.Record("x" -> DynamicValue.int(1))
|
|
@@ -269,7 +269,7 @@ val fields: Option[Chunk[(String, DynamicValue)]] =
|
|
|
269
269
|
|
|
270
270
|
### Extracting Primitive Values
|
|
271
271
|
|
|
272
|
-
```scala
|
|
272
|
+
```scala
|
|
273
273
|
import zio.blocks.schema.{DynamicValue, PrimitiveType, Validation}
|
|
274
274
|
|
|
275
275
|
val dv = DynamicValue.int(42)
|
|
@@ -288,7 +288,7 @@ val stringValue: Option[String] = dv.asPrimitive(PrimitiveType.String(Validation
|
|
|
288
288
|
|
|
289
289
|
Navigate using `get` methods that return `DynamicValueSelection`:
|
|
290
290
|
|
|
291
|
-
```scala
|
|
291
|
+
```scala
|
|
292
292
|
import zio.blocks.schema.DynamicValue
|
|
293
293
|
|
|
294
294
|
val data = DynamicValue.Record(
|
|
@@ -315,7 +315,7 @@ val name = firstName.one // Either[SchemaError, DynamicValue]
|
|
|
315
315
|
|
|
316
316
|
Use `DynamicOptic` for complex path expressions:
|
|
317
317
|
|
|
318
|
-
```scala
|
|
318
|
+
```scala
|
|
319
319
|
import zio.blocks.schema.{DynamicValue, DynamicOptic}
|
|
320
320
|
|
|
321
321
|
val data = DynamicValue.Record(
|
|
@@ -337,7 +337,7 @@ val result = data.get(path).one // Right(DynamicValue.Primitive(String("Alice")
|
|
|
337
337
|
|
|
338
338
|
`DynamicValueSelection` wraps navigation results and provides fluent chaining:
|
|
339
339
|
|
|
340
|
-
```scala
|
|
340
|
+
```scala
|
|
341
341
|
import zio.blocks.schema.{DynamicValue, DynamicValueSelection}
|
|
342
342
|
|
|
343
343
|
val selection: DynamicValueSelection = ???
|
|
@@ -366,7 +366,7 @@ selection.flatMap(dv => ???) // Chain selections
|
|
|
366
366
|
|
|
367
367
|
Update values at a path:
|
|
368
368
|
|
|
369
|
-
```scala
|
|
369
|
+
```scala
|
|
370
370
|
import zio.blocks.schema.{DynamicValue, DynamicOptic}
|
|
371
371
|
|
|
372
372
|
val data = DynamicValue.Record(
|
|
@@ -386,7 +386,7 @@ val updated = data.modify(path)(dv => DynamicValue.string("Bob"))
|
|
|
386
386
|
|
|
387
387
|
Replace a value at a path:
|
|
388
388
|
|
|
389
|
-
```scala
|
|
389
|
+
```scala
|
|
390
390
|
import zio.blocks.schema.{DynamicValue, DynamicOptic}
|
|
391
391
|
|
|
392
392
|
val data = DynamicValue.Record("x" -> DynamicValue.int(1))
|
|
@@ -400,7 +400,7 @@ val updated = data.set(path, DynamicValue.int(99))
|
|
|
400
400
|
|
|
401
401
|
Remove a value at a path:
|
|
402
402
|
|
|
403
|
-
```scala
|
|
403
|
+
```scala
|
|
404
404
|
import zio.blocks.schema.{DynamicValue, DynamicOptic}
|
|
405
405
|
|
|
406
406
|
val data = DynamicValue.Record(
|
|
@@ -416,7 +416,7 @@ val updated = data.delete(DynamicOptic.root.field("a"))
|
|
|
416
416
|
|
|
417
417
|
Add a value at a path (fails if path exists):
|
|
418
418
|
|
|
419
|
-
```scala
|
|
419
|
+
```scala
|
|
420
420
|
import zio.blocks.schema.{DynamicValue, DynamicOptic}
|
|
421
421
|
|
|
422
422
|
val data = DynamicValue.Record("a" -> DynamicValue.int(1))
|
|
@@ -432,7 +432,7 @@ val updated = data.insert(
|
|
|
432
432
|
|
|
433
433
|
Use `*OrFail` variants for operations that should fail explicitly:
|
|
434
434
|
|
|
435
|
-
```scala
|
|
435
|
+
```scala
|
|
436
436
|
import zio.blocks.schema.{DynamicValue, DynamicOptic, SchemaError}
|
|
437
437
|
|
|
438
438
|
val data = DynamicValue.Record("x" -> DynamicValue.int(1))
|
|
@@ -452,7 +452,7 @@ val result: Either[SchemaError, DynamicValue] =
|
|
|
452
452
|
- Adds `@ {tag: "..."}` annotations for Variants
|
|
453
453
|
- Adds `@ {type: "..."}` annotations for typed primitives (Instant, Duration, etc.)
|
|
454
454
|
|
|
455
|
-
```scala
|
|
455
|
+
```scala
|
|
456
456
|
import zio.blocks.schema.{DynamicValue, PrimitiveValue}
|
|
457
457
|
|
|
458
458
|
val person = DynamicValue.Record(
|
|
@@ -488,7 +488,7 @@ Use `toEjson(indent)` to control indentation level.
|
|
|
488
488
|
|
|
489
489
|
Merge two `DynamicValue` structures using configurable strategies:
|
|
490
490
|
|
|
491
|
-
```scala
|
|
491
|
+
```scala
|
|
492
492
|
import zio.blocks.schema.{DynamicValue, DynamicValueMergeStrategy}
|
|
493
493
|
|
|
494
494
|
val left = DynamicValue.Record(
|
|
@@ -517,7 +517,7 @@ val merged = left.merge(right, DynamicValueMergeStrategy.Auto)
|
|
|
517
517
|
| `Concat` | Concatenate Sequences instead of merging by index |
|
|
518
518
|
| `Custom(f, r)` | Custom function with custom recursion control |
|
|
519
519
|
|
|
520
|
-
```scala
|
|
520
|
+
```scala
|
|
521
521
|
import zio.blocks.schema.{DynamicValue, DynamicValueMergeStrategy}
|
|
522
522
|
|
|
523
523
|
val list1 = DynamicValue.Sequence(DynamicValue.int(1), DynamicValue.int(2))
|
|
@@ -532,7 +532,7 @@ val concatted = list1.merge(list2, DynamicValueMergeStrategy.Concat)
|
|
|
532
532
|
|
|
533
533
|
Transform `DynamicValue` structures for comparison or serialization:
|
|
534
534
|
|
|
535
|
-
```scala
|
|
535
|
+
```scala
|
|
536
536
|
import zio.blocks.schema.DynamicValue
|
|
537
537
|
|
|
538
538
|
val data = DynamicValue.Record(
|
|
@@ -566,7 +566,7 @@ data.normalize
|
|
|
566
566
|
|
|
567
567
|
Apply functions to all values in a structure:
|
|
568
568
|
|
|
569
|
-
```scala
|
|
569
|
+
```scala
|
|
570
570
|
import zio.blocks.schema.{DynamicValue, DynamicOptic, PrimitiveValue}
|
|
571
571
|
|
|
572
572
|
val data = DynamicValue.Record(
|
|
@@ -593,7 +593,7 @@ val topDown = data.transformDown { (path, dv) => ??? }
|
|
|
593
593
|
|
|
594
594
|
Rename all record fields:
|
|
595
595
|
|
|
596
|
-
```scala
|
|
596
|
+
```scala
|
|
597
597
|
import zio.blocks.schema.{DynamicValue, DynamicOptic}
|
|
598
598
|
|
|
599
599
|
val data = DynamicValue.Record(
|
|
@@ -615,7 +615,7 @@ val camelCase = data.transformFields { (path, name) =>
|
|
|
615
615
|
|
|
616
616
|
Aggregate values from a `DynamicValue` tree:
|
|
617
617
|
|
|
618
|
-
```scala
|
|
618
|
+
```scala
|
|
619
619
|
import zio.blocks.schema.{DynamicValue, DynamicOptic, PrimitiveValue}
|
|
620
620
|
|
|
621
621
|
val data = DynamicValue.Record(
|
|
@@ -638,7 +638,7 @@ val sum = data.foldUp(0) { (path, dv, acc) =>
|
|
|
638
638
|
|
|
639
639
|
### To JSON
|
|
640
640
|
|
|
641
|
-
```scala
|
|
641
|
+
```scala
|
|
642
642
|
import zio.blocks.schema.DynamicValue
|
|
643
643
|
import zio.blocks.schema.json.Json
|
|
644
644
|
|
|
@@ -653,7 +653,7 @@ val json: Json = dynamic.toJson
|
|
|
653
653
|
|
|
654
654
|
### From JSON
|
|
655
655
|
|
|
656
|
-
```scala
|
|
656
|
+
```scala
|
|
657
657
|
import zio.blocks.schema.DynamicValue
|
|
658
658
|
import zio.blocks.schema.json.Json
|
|
659
659
|
|
|
@@ -667,7 +667,7 @@ val dynamic: DynamicValue = json.toDynamicValue
|
|
|
667
667
|
|
|
668
668
|
Search recursively for values matching a predicate:
|
|
669
669
|
|
|
670
|
-
```scala
|
|
670
|
+
```scala
|
|
671
671
|
import zio.blocks.schema.{DynamicValue, DynamicValueType, PrimitiveValue}
|
|
672
672
|
|
|
673
673
|
val data = DynamicValue.Record(
|
|
@@ -691,7 +691,7 @@ val atDepth2 = data.select.queryPath(path => path.nodes.length == 2)
|
|
|
691
691
|
|
|
692
692
|
Work with data when the schema isn't known at compile time:
|
|
693
693
|
|
|
694
|
-
```scala
|
|
694
|
+
```scala
|
|
695
695
|
import zio.blocks.schema.{DynamicValue, PrimitiveValue}
|
|
696
696
|
|
|
697
697
|
def processAnyData(data: DynamicValue): DynamicValue = {
|
|
@@ -712,7 +712,7 @@ def processAnyData(data: DynamicValue): DynamicValue = {
|
|
|
712
712
|
|
|
713
713
|
Transform data between schema versions:
|
|
714
714
|
|
|
715
|
-
```scala
|
|
715
|
+
```scala
|
|
716
716
|
import zio.blocks.schema.{DynamicValue, DynamicOptic}
|
|
717
717
|
|
|
718
718
|
def migrateV1toV2(data: DynamicValue): DynamicValue = {
|
|
@@ -735,7 +735,7 @@ def migrateV1toV2(data: DynamicValue): DynamicValue = {
|
|
|
735
735
|
|
|
736
736
|
Build queries at runtime:
|
|
737
737
|
|
|
738
|
-
```scala
|
|
738
|
+
```scala
|
|
739
739
|
import zio.blocks.schema.{DynamicValue, DynamicOptic}
|
|
740
740
|
|
|
741
741
|
def buildPath(fields: List[String]): DynamicOptic =
|
|
@@ -761,7 +761,7 @@ val email = getValue(data, List("user", "profile", "email"))
|
|
|
761
761
|
|
|
762
762
|
Use `DynamicValue` as an intermediate format:
|
|
763
763
|
|
|
764
|
-
```scala
|
|
764
|
+
```scala
|
|
765
765
|
import zio.blocks.schema.{Schema, DynamicValue}
|
|
766
766
|
import zio.blocks.schema.json.Json
|
|
767
767
|
|
|
@@ -784,7 +784,7 @@ val json2 = dynamic2.toJson
|
|
|
784
784
|
|
|
785
785
|
`DynamicValue` has a total ordering for sorting and comparison:
|
|
786
786
|
|
|
787
|
-
```scala
|
|
787
|
+
```scala
|
|
788
788
|
import zio.blocks.schema.DynamicValue
|
|
789
789
|
|
|
790
790
|
val a = DynamicValue.int(1)
|
|
@@ -804,7 +804,7 @@ primitive < record // true
|
|
|
804
804
|
|
|
805
805
|
Compute differences between `DynamicValue` instances:
|
|
806
806
|
|
|
807
|
-
```scala
|
|
807
|
+
```scala
|
|
808
808
|
import zio.blocks.schema.DynamicValue
|
|
809
809
|
import zio.blocks.schema.patch.DynamicPatch
|
|
810
810
|
|
package/reference/formats.md
CHANGED
|
@@ -9,7 +9,7 @@ ZIO Blocks Schema provides automatic codec derivation for multiple serialization
|
|
|
9
9
|
|
|
10
10
|
All serialization formats in ZIO Blocks follow the same pattern: given a `Schema[A]`, you derive a codec by calling `derive` with a format object:
|
|
11
11
|
|
|
12
|
-
```scala
|
|
12
|
+
```scala
|
|
13
13
|
import zio.blocks.schema._
|
|
14
14
|
import zio.blocks.schema.toon._
|
|
15
15
|
|
|
@@ -54,7 +54,7 @@ libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "<version>"
|
|
|
54
54
|
|
|
55
55
|
### Basic Usage
|
|
56
56
|
|
|
57
|
-
```scala
|
|
57
|
+
```scala
|
|
58
58
|
import zio.blocks.schema._
|
|
59
59
|
import zio.blocks.schema.json._
|
|
60
60
|
|
|
@@ -89,7 +89,7 @@ Requires the Apache Avro library (1.12.x).
|
|
|
89
89
|
|
|
90
90
|
### Basic Usage
|
|
91
91
|
|
|
92
|
-
```scala
|
|
92
|
+
```scala
|
|
93
93
|
import zio.blocks.schema._
|
|
94
94
|
import zio.blocks.schema.avro._
|
|
95
95
|
|
|
@@ -114,7 +114,7 @@ val decoded: Either[SchemaError, Person] = codec.decode(bytes)
|
|
|
114
114
|
|
|
115
115
|
Each `AvroBinaryCodec` exposes an `avroSchema` property containing the Apache Avro schema:
|
|
116
116
|
|
|
117
|
-
```scala
|
|
117
|
+
```scala
|
|
118
118
|
import zio.blocks.schema._
|
|
119
119
|
import zio.blocks.schema.avro._
|
|
120
120
|
import org.apache.avro.{Schema => AvroSchema}
|
|
@@ -162,7 +162,7 @@ println(avroSchema.toString(true))
|
|
|
162
162
|
|
|
163
163
|
Sealed traits are encoded as Avro unions with an integer index prefix:
|
|
164
164
|
|
|
165
|
-
```scala
|
|
165
|
+
```scala
|
|
166
166
|
import zio.blocks.schema._
|
|
167
167
|
import zio.blocks.schema.avro._
|
|
168
168
|
|
|
@@ -202,7 +202,7 @@ libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "<version>"
|
|
|
202
202
|
|
|
203
203
|
### Basic Usage
|
|
204
204
|
|
|
205
|
-
```scala
|
|
205
|
+
```scala
|
|
206
206
|
import zio.blocks.schema._
|
|
207
207
|
import zio.blocks.schema.toon._
|
|
208
208
|
|
|
@@ -260,7 +260,7 @@ orders[2]{id,total}:
|
|
|
260
260
|
|
|
261
261
|
The `ToonBinaryCodecDeriver` provides extensive configuration:
|
|
262
262
|
|
|
263
|
-
```scala
|
|
263
|
+
```scala
|
|
264
264
|
import zio.blocks.schema._
|
|
265
265
|
import zio.blocks.schema.toon._
|
|
266
266
|
|
|
@@ -295,7 +295,7 @@ val codec = Schema[Person].derive(customDeriver)
|
|
|
295
295
|
|
|
296
296
|
### ADT Encoding Styles
|
|
297
297
|
|
|
298
|
-
```scala
|
|
298
|
+
```scala
|
|
299
299
|
import zio.blocks.schema._
|
|
300
300
|
import zio.blocks.schema.toon._
|
|
301
301
|
|
|
@@ -331,7 +331,7 @@ libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "<version>
|
|
|
331
331
|
|
|
332
332
|
### Basic Usage
|
|
333
333
|
|
|
334
|
-
```scala
|
|
334
|
+
```scala
|
|
335
335
|
import zio.blocks.schema._
|
|
336
336
|
import zio.blocks.schema.msgpack._
|
|
337
337
|
|
|
@@ -383,7 +383,7 @@ MessagePack provides significant space savings compared to JSON:
|
|
|
383
383
|
|
|
384
384
|
Sealed traits encode a variant index followed by the case value:
|
|
385
385
|
|
|
386
|
-
```scala
|
|
386
|
+
```scala
|
|
387
387
|
import zio.blocks.schema._
|
|
388
388
|
import zio.blocks.schema.msgpack._
|
|
389
389
|
|
|
@@ -416,7 +416,7 @@ Requires the MongoDB BSON library (5.x).
|
|
|
416
416
|
|
|
417
417
|
### Basic Usage
|
|
418
418
|
|
|
419
|
-
```scala
|
|
419
|
+
```scala
|
|
420
420
|
import zio.blocks.schema._
|
|
421
421
|
import zio.blocks.schema.bson._
|
|
422
422
|
|
|
@@ -438,7 +438,7 @@ val codec: BsonCodec[Person] = BsonSchemaCodec.bsonCodec(Schema[Person])
|
|
|
438
438
|
|
|
439
439
|
BSON provides native support for MongoDB ObjectIds:
|
|
440
440
|
|
|
441
|
-
```scala
|
|
441
|
+
```scala
|
|
442
442
|
import zio.blocks.schema._
|
|
443
443
|
import zio.blocks.schema.bson._
|
|
444
444
|
import org.bson.types.ObjectId
|
|
@@ -458,7 +458,7 @@ val codec = BsonSchemaCodec.bsonCodec(Schema[Document])
|
|
|
458
458
|
|
|
459
459
|
### Configuration Options
|
|
460
460
|
|
|
461
|
-
```scala
|
|
461
|
+
```scala
|
|
462
462
|
import zio.blocks.schema._
|
|
463
463
|
import zio.blocks.schema.bson._
|
|
464
464
|
import BsonSchemaCodec._
|
|
@@ -486,7 +486,7 @@ val codec = BsonSchemaCodec.bsonCodec(Schema[Person], config)
|
|
|
486
486
|
|
|
487
487
|
### Sum Type Handling
|
|
488
488
|
|
|
489
|
-
```scala
|
|
489
|
+
```scala
|
|
490
490
|
import zio.blocks.schema.bson.BsonSchemaCodec.SumTypeHandling
|
|
491
491
|
|
|
492
492
|
// Option 1: Wrapper with class name as field key (default)
|
|
@@ -515,7 +515,7 @@ Requires the Apache Thrift library (0.22.x).
|
|
|
515
515
|
|
|
516
516
|
### Basic Usage
|
|
517
517
|
|
|
518
|
-
```scala
|
|
518
|
+
```scala
|
|
519
519
|
import zio.blocks.schema._
|
|
520
520
|
import zio.blocks.schema.thrift._
|
|
521
521
|
import java.nio.ByteBuffer
|
|
@@ -616,7 +616,7 @@ All formats support the full set of ZIO Blocks Schema primitive types:
|
|
|
616
616
|
|
|
617
617
|
All formats return `Either[SchemaError, A]` for decoding operations. Errors include path information for debugging:
|
|
618
618
|
|
|
619
|
-
```scala
|
|
619
|
+
```scala
|
|
620
620
|
import zio.blocks.schema._
|
|
621
621
|
import zio.blocks.schema.toon._
|
|
622
622
|
|
package/reference/json-schema.md
CHANGED
|
@@ -31,7 +31,7 @@ The most common use case is deriving a JSON Schema from an existing `Schema[A]`.
|
|
|
31
31
|
|
|
32
32
|
### Basic Derivation
|
|
33
33
|
|
|
34
|
-
```scala
|
|
34
|
+
```scala
|
|
35
35
|
import zio.blocks.schema._
|
|
36
36
|
import zio.blocks.schema.json._
|
|
37
37
|
|
|
@@ -55,7 +55,7 @@ jsonSchema.conforms(invalid) // false
|
|
|
55
55
|
|
|
56
56
|
For more control, derive through `JsonBinaryCodec`:
|
|
57
57
|
|
|
58
|
-
```scala
|
|
58
|
+
```scala
|
|
59
59
|
import zio.blocks.schema._
|
|
60
60
|
import zio.blocks.schema.json._
|
|
61
61
|
|
|
@@ -75,7 +75,7 @@ val jsonSchema = codec.toJsonSchema
|
|
|
75
75
|
|
|
76
76
|
The simplest schemas accept or reject all values:
|
|
77
77
|
|
|
78
|
-
```scala
|
|
78
|
+
```scala
|
|
79
79
|
import zio.blocks.schema.json.JsonSchema
|
|
80
80
|
|
|
81
81
|
// Accepts any valid JSON value
|
|
@@ -89,7 +89,7 @@ val rejectAll = JsonSchema.False
|
|
|
89
89
|
|
|
90
90
|
Create schemas that validate specific JSON types:
|
|
91
91
|
|
|
92
|
-
```scala
|
|
92
|
+
```scala
|
|
93
93
|
import zio.blocks.schema.json.{JsonSchema, JsonSchemaType}
|
|
94
94
|
|
|
95
95
|
// Single type
|
|
@@ -110,7 +110,7 @@ val isBoolean = JsonSchema.boolean
|
|
|
110
110
|
|
|
111
111
|
Create schemas for string validation:
|
|
112
112
|
|
|
113
|
-
```scala
|
|
113
|
+
```scala
|
|
114
114
|
import zio.blocks.schema.json.{JsonSchema, NonNegativeInt, RegexPattern}
|
|
115
115
|
|
|
116
116
|
// String with length constraints (compile-time validated literals)
|
|
@@ -134,7 +134,7 @@ val uuid = JsonSchema.string(format = Some("uuid"))
|
|
|
134
134
|
|
|
135
135
|
Create schemas for number validation:
|
|
136
136
|
|
|
137
|
-
```scala
|
|
137
|
+
```scala
|
|
138
138
|
import zio.blocks.schema.json.{JsonSchema, PositiveNumber}
|
|
139
139
|
|
|
140
140
|
// Number with range
|
|
@@ -158,7 +158,7 @@ val evenNumber = JsonSchema.integer(
|
|
|
158
158
|
|
|
159
159
|
Create schemas for array validation:
|
|
160
160
|
|
|
161
|
-
```scala
|
|
161
|
+
```scala
|
|
162
162
|
import zio.blocks.schema.json.{JsonSchema, JsonSchemaType, NonNegativeInt}
|
|
163
163
|
|
|
164
164
|
// Array of strings
|
|
@@ -192,7 +192,7 @@ val point2D = JsonSchema.array(
|
|
|
192
192
|
|
|
193
193
|
Create schemas for object validation:
|
|
194
194
|
|
|
195
|
-
```scala
|
|
195
|
+
```scala
|
|
196
196
|
import zio.blocks.schema.json.{JsonSchema, JsonSchemaType}
|
|
197
197
|
import zio.blocks.chunk.ChunkMap
|
|
198
198
|
|
|
@@ -218,7 +218,7 @@ val strictPerson = JsonSchema.obj(
|
|
|
218
218
|
|
|
219
219
|
### Enum and Const
|
|
220
220
|
|
|
221
|
-
```scala
|
|
221
|
+
```scala
|
|
222
222
|
import zio.blocks.schema.json.{JsonSchema, Json}
|
|
223
223
|
|
|
224
224
|
// Enum of string values
|
|
@@ -240,7 +240,7 @@ val alwaysTrue = JsonSchema.constOf(Json.Boolean(true))
|
|
|
240
240
|
|
|
241
241
|
Combine schemas using logical operators:
|
|
242
242
|
|
|
243
|
-
```scala
|
|
243
|
+
```scala
|
|
244
244
|
import zio.blocks.schema.json.{JsonSchema, JsonSchemaType}
|
|
245
245
|
|
|
246
246
|
val stringSchema = JsonSchema.ofType(JsonSchemaType.String)
|
|
@@ -266,7 +266,7 @@ val nullableString = stringSchema || nullSchema
|
|
|
266
266
|
|
|
267
267
|
Make any schema nullable:
|
|
268
268
|
|
|
269
|
-
```scala
|
|
269
|
+
```scala
|
|
270
270
|
import zio.blocks.schema.json.{JsonSchema, JsonSchemaType}
|
|
271
271
|
|
|
272
272
|
val stringSchema = JsonSchema.ofType(JsonSchemaType.String)
|
|
@@ -281,7 +281,7 @@ val nullableString = stringSchema.withNullable
|
|
|
281
281
|
|
|
282
282
|
Apply different schemas based on conditions:
|
|
283
283
|
|
|
284
|
-
```scala
|
|
284
|
+
```scala
|
|
285
285
|
import zio.blocks.schema.json.{JsonSchema, JsonSchemaType, NonNegativeInt}
|
|
286
286
|
|
|
287
287
|
// If type is string, require minLength
|
|
@@ -296,7 +296,7 @@ val conditionalSchema = JsonSchema.Object(
|
|
|
296
296
|
|
|
297
297
|
Apply schemas when properties are present:
|
|
298
298
|
|
|
299
|
-
```scala
|
|
299
|
+
```scala
|
|
300
300
|
import zio.blocks.schema.json.{JsonSchema, JsonSchemaType}
|
|
301
301
|
import zio.blocks.chunk.ChunkMap
|
|
302
302
|
|
|
@@ -316,7 +316,7 @@ val paymentSchema = JsonSchema.Object(
|
|
|
316
316
|
|
|
317
317
|
### Basic Validation
|
|
318
318
|
|
|
319
|
-
```scala
|
|
319
|
+
```scala
|
|
320
320
|
import zio.blocks.schema.json.{JsonSchema, Json, JsonSchemaType}
|
|
321
321
|
import zio.blocks.chunk.ChunkMap
|
|
322
322
|
|
|
@@ -350,7 +350,7 @@ schema.conforms(invalidJson) // false
|
|
|
350
350
|
|
|
351
351
|
Control validation behavior:
|
|
352
352
|
|
|
353
|
-
```scala
|
|
353
|
+
```scala
|
|
354
354
|
import zio.blocks.schema.json.{JsonSchema, Json, ValidationOptions}
|
|
355
355
|
|
|
356
356
|
val schema = JsonSchema.string(format = Some("email"))
|
|
@@ -369,7 +369,7 @@ schema.check(value, lenientOptions) // None
|
|
|
369
369
|
|
|
370
370
|
Validation errors include path information:
|
|
371
371
|
|
|
372
|
-
```scala
|
|
372
|
+
```scala
|
|
373
373
|
import zio.blocks.schema.json.{JsonSchema, Json, JsonSchemaType}
|
|
374
374
|
import zio.blocks.chunk.ChunkMap
|
|
375
375
|
|
|
@@ -402,7 +402,7 @@ schema.check(invalid) match {
|
|
|
402
402
|
|
|
403
403
|
### Parsing from JSON
|
|
404
404
|
|
|
405
|
-
```scala
|
|
405
|
+
```scala
|
|
406
406
|
import zio.blocks.schema.json.{JsonSchema, Json}
|
|
407
407
|
|
|
408
408
|
// From JSON string
|
|
@@ -426,7 +426,7 @@ val fromJson = JsonSchema.fromJson(json)
|
|
|
426
426
|
|
|
427
427
|
### Serializing to JSON
|
|
428
428
|
|
|
429
|
-
```scala
|
|
429
|
+
```scala
|
|
430
430
|
import zio.blocks.schema.json.{JsonSchema, NonNegativeInt}
|
|
431
431
|
|
|
432
432
|
val schema = JsonSchema.string(
|
|
@@ -466,7 +466,7 @@ Format validation is enabled by default. Use `ValidationOptions.annotationOnly`
|
|
|
466
466
|
|
|
467
467
|
JSON Schema 2020-12 introduces `unevaluatedProperties` and `unevaluatedItems` for validating properties/items not matched by any applicator keyword:
|
|
468
468
|
|
|
469
|
-
```scala
|
|
469
|
+
```scala
|
|
470
470
|
import zio.blocks.schema.json.{JsonSchema, JsonSchemaType}
|
|
471
471
|
import zio.blocks.chunk.ChunkMap
|
|
472
472
|
|
|
@@ -554,7 +554,7 @@ The implementation passes **817 of 844 tests** (97%+) from the official JSON Sch
|
|
|
554
554
|
|
|
555
555
|
## Complete Example
|
|
556
556
|
|
|
557
|
-
```scala
|
|
557
|
+
```scala
|
|
558
558
|
import zio.blocks.schema.json._
|
|
559
559
|
import zio.blocks.chunk.ChunkMap
|
|
560
560
|
|