Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Comment on lines +102 to +106
Copy link
Contributor

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

  • Prevent nil interface panics at call sites.
  • Prefer NewX naming for constructors.
-// Experimental API
-func Use(schema EXPERIMENTAL_PUBLIC_ZOG_SCHEMA) *CustomSchema {
-	return &CustomSchema{schema: schema}
-}
+// Experimental: NewCustomSchema wraps a user-provided ExperimentalSchema.
+func NewCustomSchema(schema ExperimentalSchema) *CustomSchema {
+	if schema == nil {
+		panic("NewCustomSchema: schema must not be nil")
+	}
+	return &CustomSchema{schema: schema}
+}

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In custom.go around lines 102 to 106, change the constructor to follow Go naming
conventions and guard against a nil schema: rename Use to NewCustomSchema,
change its signature to return (*CustomSchema, error), validate that the passed
schema (EXPERIMENTAL_PUBLIC_ZOG_SCHEMA) is not nil and return a descriptive
error (e.g., fmt.Errorf("schema cannot be nil")) if it is, otherwise return
&CustomSchema{schema: schema}, error nil; update callers accordingly to handle
the error.

// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Add 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
CustomSchema must implement the internal schema interface (lower-cased methods) used throughout the engine (e.g. c.process(...), c.getType(), s.setCoercer(...)). In custom.go, immediately after the existing exported methods, add:

// 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
In custom.go around lines 112 to 126, CustomSchema exposes exported methods but
is missing the lowercase internal adapter methods required by the engine; add
unexported adapter methods that simply forward to the exported ones so the type
satisfies internal interfaces: implement process(ctx *p.SchemaCtx) calling
c.schema.Process(ctx), validate(ctx *p.SchemaCtx) calling
c.schema.Validate(ctx), getType() zconst.ZogType returning c.schema.GetType(),
and setCoercer(coercer CoercerFunc) calling c.schema.SetCoercer(coercer).

Loading