-
Notifications
You must be signed in to change notification settings - Fork 29
feat: experimental custom schemas #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,3 +90,37 @@ func (c *Custom[T]) setCoercer(coercer CoercerFunc) { | |
| func (c *Custom[T]) getType() zconst.ZogType { | ||
| return "custom" | ||
| } | ||
|
|
||
| // Experimental API | ||
| type EXPERIMENTAL_PUBLIC_ZOG_SCHEMA interface { | ||
| Process(ctx *p.SchemaCtx) | ||
| Validate(ctx *p.SchemaCtx) | ||
| GetType() zconst.ZogType | ||
| SetCoercer(c CoercerFunc) | ||
| } | ||
|
|
||
| // Experimental API | ||
| func Use(schema EXPERIMENTAL_PUBLIC_ZOG_SCHEMA) *CustomSchema { | ||
| return &CustomSchema{schema: schema} | ||
| } | ||
|
|
||
| // Experimental API | ||
| type CustomSchema struct { | ||
| schema EXPERIMENTAL_PUBLIC_ZOG_SCHEMA | ||
| } | ||
|
|
||
| func (c *CustomSchema) Process(ctx *p.SchemaCtx) { | ||
| c.schema.Process(ctx) | ||
| } | ||
|
|
||
| func (c *CustomSchema) Validate(ctx *p.SchemaCtx) { | ||
| c.schema.Validate(ctx) | ||
| } | ||
|
|
||
| func (c *CustomSchema) GetType() zconst.ZogType { | ||
| return c.schema.GetType() | ||
| } | ||
|
|
||
| func (c *CustomSchema) SetCoercer(coercer CoercerFunc) { | ||
| c.schema.SetCoercer(coercer) | ||
| } | ||
|
Comment on lines
+112
to
+126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainAdd unexported adapter methods to integrate with existing internal schema expectations (process/validate/getType/setCoercer) If the engine expects the unexported method set (as used by Custom[T]) rather than the exported ones, this wrapper won’t plug into existing flows. Mirror the internal method names so CustomSchema can be used wherever a built-in schema is accepted. Add these adapters (outside the changed hunk if necessary): // Internal adapters to match existing engine expectations.
func (c *CustomSchema) process(ctx *p.SchemaCtx) { c.schema.Process(ctx) }
func (c *CustomSchema) validate(ctx *p.SchemaCtx) { c.schema.Validate(ctx) }
func (c *CustomSchema) getType() zconst.ZogType { return c.schema.GetType() }
func (c *CustomSchema) setCoercer(coercer CoercerFunc) { c.schema.SetCoercer(coercer) }Run this to verify whether the codebase relies on the unexported method set or an internal interface that requires them: 🏁 Script executed: #!/bin/bash
# Look for an internal interface or callsites using unexported methods
rg -nP -C3 '(?s)interface\s+\w+\s*{[^}]*\bprocess\s*\(\s*\*p\.SchemaCtx\)[^}]*\bvalidate\s*\(\s*\*p\.SchemaCtx\)[^}]*\bgetType\s*\(\)\s*zconst\.ZogType[^}]*\bsetCoercer\s*\('
rg -nP -C2 '\.\s*process\s*\(|\.\s*validate\s*\(|\.\s*getType\s*\(|\.\s*setCoercer\s*\('Length of output: 14246 Add unexported adapter methods to CustomSchema // internal adapters for existing engine flows
func (c *CustomSchema) process(ctx *p.SchemaCtx) { c.schema.Process(ctx) }
func (c *CustomSchema) validate(ctx *p.SchemaCtx) { c.schema.Validate(ctx) }
func (c *CustomSchema) getType() zconst.ZogType { return c.schema.GetType() }
func (c *CustomSchema) setCoercer(coercer CoercerFunc) { c.schema.SetCoercer(coercer) }This ensures CustomSchema satisfies all call sites and interfaces discovered in the codebase. 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Constructor: guard against nil and follow Go naming conventions
🤖 Prompt for AI Agents