• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Oudwins / zog / 20848116288

09 Jan 2026 09:57AM UTC coverage: 78.307% (+0.2%) from 78.086%
20848116288

push

github

web-flow
feat: experimental recursive schema (#209)

* feat: recursive schemas

* wp

* wp

* feat: recursive typesafe implementation

* refactor: naming

* test: feat tests

* fix: rebase

* fix: thread safety

* docs: recursive

* docs: fixes

* fix: docs

25 of 27 new or added lines in 1 file covered. (92.59%)

2451 of 3130 relevant lines covered (78.31%)

64.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.59
/recursive.go
1
package zog
2

3
import (
4
        "sync"
5

6
        p "github.com/Oudwins/zog/internals"
7
        zss "github.com/Oudwins/zog/pkgs/zss/core"
8
        "github.com/Oudwins/zog/zconst"
9
)
10

11
type lazySchema struct {
12
        innerSchema ZogSchema
13
        fn          func() ZogSchema
14
        once        sync.Once
15
}
16

17
var _ ZogSchema = &lazySchema{}
18

19
func (l *lazySchema) get() ZogSchema {
110✔
20
        l.once.Do(func() {
131✔
21
                l.innerSchema = l.fn()
21✔
22
        })
21✔
23
        return l.innerSchema
110✔
24
}
25

26
func (l *lazySchema) process(ctx *p.SchemaCtx) {
47✔
27
        l.get().process(ctx)
47✔
28
}
47✔
29
func (l *lazySchema) validate(ctx *p.SchemaCtx) {
6✔
30
        l.get().validate(ctx)
6✔
31
}
6✔
32
func (l *lazySchema) getType() zconst.ZogType  { return l.get().getType() }
57✔
NEW
33
func (l *lazySchema) setCoercer(c CoercerFunc) { l.get().setCoercer(c) }
×
NEW
34
func (l *lazySchema) toZSS() *zss.ZSSSchema    { return l.get().toZSS() }
×
35

36
func lazy(fn func() ZogSchema) *lazySchema {
23✔
37
        return &lazySchema{fn: fn}
23✔
38
}
23✔
39

40
type RecursiveSchemaUpdater[T ZogSchema] func(self T) T
41
type RecursiveSchema[T ZogSchema] func(updaters ...RecursiveSchemaUpdater[T]) ZogSchema
42
type RecursiveSchemaBuilder[T ZogSchema] func(self RecursiveSchema[T]) T
43

44
// Experimental API.
45
// Do not use unless you know what you are doing.
46
func EXPERIMENTAL_RECURSIVE[T ZogSchema](build RecursiveSchemaBuilder[T]) T {
22✔
47
        var self T
22✔
48
        var lazyBuilder RecursiveSchema[T] = func(updaters ...RecursiveSchemaUpdater[T]) ZogSchema {
45✔
49
                return lazy(func() ZogSchema {
44✔
50
                        if len(updaters) > 0 {
24✔
51
                                return updaters[0](self)
3✔
52
                        }
3✔
53
                        return self
18✔
54
                })
55
        }
56
        self = build(lazyBuilder)
22✔
57
        return self
22✔
58
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc