Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: made the new generics based schema
=c01e1d460a33
diff --git a/backend-go/pkg/chita/field.go b/backend-go/pkg/chita/field.gonew file mode 100644index 0000000000..0a4c61d8e9--- /dev/null+++ b/backend-go/pkg/chita/field.go@@ -0,0 +1,327 @@+package chita++import (+ "encoding/json"+)++// Field is the interface implemented by Required and Optional.+type Field[T any] interface {+ Get() T+ Set(T)+ IsSet() bool+ IsRequired() bool+}++// Required represents a field that must be provided.+// For requests: validation fails if not set.+// For responses: ensures the field is always populated.+type Required[T any] struct {+ value T+ isSet bool+}++// Get returns the value.+func (r Required[T]) Get() T {+ return r.value+}++// Set sets the value and marks it as set.+func (r *Required[T]) Set(v T) {+ r.value = v+ r.isSet = true+}++// IsSet returns true if the value was explicitly set.+func (r Required[T]) IsSet() bool {+ return r.isSet+}++// IsRequired returns true (Required fields are always required).+func (r Required[T]) IsRequired() bool {+ return true+}++// MarshalJSON marshals just the value, making the wrapper transparent in JSON.+func (r Required[T]) MarshalJSON() ([]byte, error) {+ return json.Marshal(r.value)+}++// UnmarshalJSON unmarshals into the value and marks it as set.+// Null is treated as "not set".+func (r *Required[T]) UnmarshalJSON(data []byte) error {+ if string(data) == "null" {+ return nil // isSet stays false+ }+ if err := json.Unmarshal(data, &r.value); err != nil {+ return err+ }+ r.isSet = true+ return nil+}++// Optional represents a field that may or may not be provided.+// For requests: defaults apply if not set.+// For responses: field may be omitted if not set (with omitempty).+// Tracks three states: absent, null, or value present.+type Optional[T any] struct {+ value T+ isSet bool+ isNull bool+}++// Get returns the value.+func (o Optional[T]) Get() T {+ return o.value+}++// Set sets the value and marks it as set (not null).+func (o *Optional[T]) Set(v T) {+ o.value = v+ o.isSet = true+ o.isNull = false+}++// SetNull marks the field as explicitly null.+func (o *Optional[T]) SetNull() {+ var zero T+ o.value = zero+ o.isSet = true+ o.isNull = true+}++// IsSet returns true if the field was present in JSON (including null).+func (o Optional[T]) IsSet() bool {+ return o.isSet+}++// IsNull returns true if the field was explicitly set to null.+func (o Optional[T]) IsNull() bool {+ return o.isNull+}++// IsRequired returns false (Optional fields are never required).+func (o Optional[T]) IsRequired() bool {+ return false+}++// MarshalJSON marshals the value. If null, marshals as null.+func (o Optional[T]) MarshalJSON() ([]byte, error) {+ if o.isNull {+ return []byte("null"), nil+ }+ return json.Marshal(o.value)+}++// UnmarshalJSON unmarshals into the value and tracks null vs value.+func (o *Optional[T]) UnmarshalJSON(data []byte) error {+ if string(data) == "null" {+ o.isSet = true+ o.isNull = true+ return nil+ }+ if err := json.Unmarshal(data, &o.value); err != nil {+ return err+ }+ o.isSet = true+ o.isNull = false+ return nil+}++// IsZero returns true if the Optional is not set (absent).+// Used by json.Marshal with omitempty to omit absent fields.+func (o Optional[T]) IsZero() bool {+ return !o.isSet+}++// NewRequired creates a Required field with the given value (marked as set).+// Use this when constructing responses.+func NewRequired[T any](v T) Required[T] {+ return Required[T]{value: v, isSet: true}+}++// NewOptional creates an Optional field with the given value (marked as set).+// Use this when constructing responses or test requests.+func NewOptional[T any](v T) Optional[T] {+ return Optional[T]{value: v, isSet: true}+}++// --- String field helpers ---++// strFieldAccessor wraps Required[string] or Optional[string] for schema use.+type strFieldAccessor struct {+ req *Required[string]+ opt *Optional[string]+}++func (a *strFieldAccessor) Get() string {+ if a.req != nil {+ return a.req.Get()+ }+ return a.opt.Get()+}++func (a *strFieldAccessor) Set(v string) {+ if a.req != nil {+ a.req.Set(v)+ } else {+ a.opt.Set(v)+ }+}++func (a *strFieldAccessor) IsSet() bool {+ if a.req != nil {+ return a.req.IsSet()+ }+ return a.opt.IsSet()+}++func (a *strFieldAccessor) IsRequired() bool {+ return a.req != nil+}++// --- Bool field helpers ---++// boolFieldAccessor wraps Required[bool] or Optional[bool] for schema use.+type boolFieldAccessor struct {+ req *Required[bool]+ opt *Optional[bool]+}++func (a *boolFieldAccessor) Get() bool {+ if a.req != nil {+ return a.req.Get()+ }+ return a.opt.Get()+}++func (a *boolFieldAccessor) Set(v bool) {+ if a.req != nil {+ a.req.Set(v)+ } else {+ a.opt.Set(v)+ }+}++func (a *boolFieldAccessor) IsSet() bool {+ if a.req != nil {+ return a.req.IsSet()+ }+ return a.opt.IsSet()+}++func (a *boolFieldAccessor) IsRequired() bool {+ return a.req != nil+}++// --- Int field helpers ---++// intFieldAccessor wraps Required[int] or Optional[int] for schema use.+type intFieldAccessor struct {+ req *Required[int]+ opt *Optional[int]+ req64 *Required[int64]+ opt64 *Optional[int64]+}++func (a *intFieldAccessor) GetInt() int {+ if a.req != nil {+ return a.req.Get()+ }+ if a.opt != nil {+ return a.opt.Get()+ }+ if a.req64 != nil {+ return int(a.req64.Get())+ }+ return int(a.opt64.Get())+}++func (a *intFieldAccessor) GetInt64() int64 {+ if a.req64 != nil {+ return a.req64.Get()+ }+ if a.opt64 != nil {+ return a.opt64.Get()+ }+ if a.req != nil {+ return int64(a.req.Get())+ }+ return int64(a.opt.Get())+}++func (a *intFieldAccessor) SetInt(v int) {+ switch {+ case a.req != nil:+ a.req.Set(v)+ case a.opt != nil:+ a.opt.Set(v)+ case a.req64 != nil:+ a.req64.Set(int64(v))+ default:+ a.opt64.Set(int64(v))+ }+}++func (a *intFieldAccessor) SetInt64(v int64) {+ switch {+ case a.req64 != nil:+ a.req64.Set(v)+ case a.opt64 != nil:+ a.opt64.Set(v)+ case a.req != nil:+ a.req.Set(int(v))+ default:+ a.opt.Set(int(v))+ }+}++func (a *intFieldAccessor) IsSet() bool {+ if a.req != nil {+ return a.req.IsSet()+ }+ if a.opt != nil {+ return a.opt.IsSet()+ }+ if a.req64 != nil {+ return a.req64.IsSet()+ }+ return a.opt64.IsSet()+}++func (a *intFieldAccessor) IsRequired() bool {+ return a.req != nil || a.req64 != nil+}++// --- Float field helpers ---++// floatFieldAccessor wraps Required[float64] or Optional[float64] for schema use.+type floatFieldAccessor struct {+ req *Required[float64]+ opt *Optional[float64]+}++func (a *floatFieldAccessor) Get() float64 {+ if a.req != nil {+ return a.req.Get()+ }+ return a.opt.Get()+}++func (a *floatFieldAccessor) Set(v float64) {+ if a.req != nil {+ a.req.Set(v)+ } else {+ a.opt.Set(v)+ }+}++func (a *floatFieldAccessor) IsSet() bool {+ if a.req != nil {+ return a.req.IsSet()+ }+ return a.opt.IsSet()+}++func (a *floatFieldAccessor) IsRequired() bool {+ return a.req != nil+}diff --git a/backend-go/pkg/chita/handler.go b/backend-go/pkg/chita/handler.goindex c0799491b0..be271a6e21 100644--- a/backend-go/pkg/chita/handler.go+++ b/backend-go/pkg/chita/handler.go@@ -10,6 +10,7 @@ import (// ErrorBody is the JSON response shape sent to clients on error.// Matches the Node.js backend format for API compatibility.type ErrorBody struct {+ ReqID string `json:"reqId,omitempty"`StatusCode int `json:"statusCode"`Message string `json:"message"`Error string `json:"error"`diff --git a/backend-go/pkg/chita/http_test.go b/backend-go/pkg/chita/http_test.goindex b3a52c0101..e6e02efde1 100644--- a/backend-go/pkg/chita/http_test.go+++ b/backend-go/pkg/chita/http_test.go@@ -24,32 +24,32 @@ import (// --- Body validation (mixed) ---type SimpleRequest struct {- Name string `json:"name"`- Email string `json:"email"`- Count int `json:"count"`+ Name Required[string] `json:"name"`+ Email Required[string] `json:"email"`+ Count Optional[int] `json:"count"`}func (r *SimpleRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "name": String(&r.Name).Required().MinLength(2).MaxLength(50),- "email": String(&r.Email).Required().Email(),- "count": Int(&r.Count).Optional().Min(0).Max(1000),+ "name": Str(&r.Name).MinLength(2).MaxLength(50),+ "email": Str(&r.Email).Email(),+ "count": OptInt(&r.Count).Min(0).Max(1000),}).Title("SimpleRequest")}type SimpleResponse struct {- ID string `json:"id"`- Name string `json:"name"`- Email string `json:"email"`- Count int `json:"count"`+ ID Required[string] `json:"id"`+ Name Required[string] `json:"name"`+ Email Required[string] `json:"email"`+ Count Optional[int] `json:"count"`}func (r *SimpleResponse) Schema() *ObjectSchema {return Object(map[string]Schema{- "id": String(&r.ID).Required(),- "name": String(&r.Name).Required(),- "email": String(&r.Email).Required(),- "count": Int(&r.Count).Optional(),+ "id": Str(&r.ID),+ "name": Str(&r.Name),+ "email": Str(&r.Email),+ "count": OptInt(&r.Count),}).Title("SimpleResponse")}@@ -65,79 +65,79 @@ func (*CreatedSimpleResponse) Status() int { return http.StatusCreated }// --- Path + query (no body) ---type GetItemRequest struct {- ID string `json:"-"`- Page int `json:"-"`- PageSize int `json:"-"`- Search string `json:"-"`- StatusField string `json:"-"`+ ID Required[string] `json:"-"`+ Page Optional[int] `json:"-"`+ PageSize Optional[int] `json:"-"`+ Search Optional[string] `json:"-"`+ StatusField Optional[string] `json:"-"`}func (r *GetItemRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "id": String(&r.ID).From(SourcePath).Required().UUID(),- "page": Int(&r.Page).From(SourceQuery).Optional().Min(1).Default(1),- "pageSize": Int(&r.PageSize).From(SourceQuery).Optional().Min(1).Max(100).Default(20),- "search": String(&r.Search).From(SourceQuery).Optional().MaxLength(100),- "status": String(&r.StatusField).From(SourceQuery).Optional().Enum("active", "inactive", "pending"),+ "id": Str(&r.ID).From(SourcePath).UUID(),+ "page": OptInt(&r.Page).From(SourceQuery).Min(1).Default(1),+ "pageSize": OptInt(&r.PageSize).From(SourceQuery).Min(1).Max(100).Default(20),+ "search": OptStr(&r.Search).From(SourceQuery).MaxLength(100),+ "status": OptStr(&r.StatusField).From(SourceQuery).Enum("active", "inactive", "pending"),}).Title("GetItemRequest")}// --- Full mixed request: body + path + query + header ---type FullRequest struct {- ID string `json:"-"`- Page int `json:"-"`- PageSize int `json:"-"`- RequestID string `json:"-"`- Name string `json:"name"`- Email string `json:"email"`- Age int `json:"age"`- Score float64 `json:"score"`- IsActive bool `json:"isActive"`- Tags []string `json:"tags"`- ResourceID uuid.UUID `json:"resourceId"`- Description string `json:"description"`+ ID Required[string] `json:"-"`+ Page Optional[int] `json:"-"`+ PageSize Optional[int] `json:"-"`+ RequestID Optional[string] `json:"-"`+ Name Required[string] `json:"name"`+ Email Required[string] `json:"email"`+ Age Optional[int] `json:"age"`+ Score Optional[float64] `json:"score"`+ IsActive Optional[bool] `json:"isActive"`+ Tags []string `json:"tags"`+ ResourceID uuid.UUID `json:"resourceId"`+ Description Optional[string] `json:"description"`}func (r *FullRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "id": String(&r.ID).From(SourcePath).Required().UUID(),- "page": Int(&r.Page).From(SourceQuery).Optional().Min(1).Default(1),- "pageSize": Int(&r.PageSize).From(SourceQuery).Optional().Min(1).Max(100).Default(20),- "X-Request-ID": String(&r.RequestID).From(SourceHeader).Optional().UUID(),-- "name": String(&r.Name).Required().MinLength(1).MaxLength(100),- "email": String(&r.Email).Required().Email(),- "age": Int(&r.Age).Optional().Min(0).Max(150),- "score": Float(&r.Score).Optional().Min(0).Max(100),- "isActive": Bool(&r.IsActive).Optional(),- "tags": Array(String(nil)).Optional().MinItems(0).MaxItems(10),+ "id": Str(&r.ID).From(SourcePath).UUID(),+ "page": OptInt(&r.Page).From(SourceQuery).Min(1).Default(1),+ "pageSize": OptInt(&r.PageSize).From(SourceQuery).Min(1).Max(100).Default(20),+ "X-Request-ID": OptStr(&r.RequestID).From(SourceHeader).UUID(),++ "name": Str(&r.Name).MinLength(1).MaxLength(100),+ "email": Str(&r.Email).Email(),+ "age": OptInt(&r.Age).Min(0).Max(150),+ "score": OptFloat(&r.Score).Min(0).Max(100),+ "isActive": OptBool(&r.IsActive),+ "tags": Array(StringElem(nil)).Optional().MinItems(0).MaxItems(10),"resourceId": UUID(&r.ResourceID).Optional(),- "description": String(&r.Description).Optional().MaxLength(500),+ "description": OptStr(&r.Description).MaxLength(500),}).Title("FullRequest")}type FullResponse struct {- ID string `json:"id"`- Name string `json:"name"`- Email string `json:"email"`- Page int `json:"page"`- PageSize int `json:"pageSize"`- Search string `json:"search,omitempty"`- StatusField string `json:"status,omitempty"`- Tags []string `json:"tags,omitempty"`+ ID Required[string] `json:"id"`+ Name Required[string] `json:"name"`+ Email Required[string] `json:"email"`+ Page Required[int] `json:"page"`+ PageSize Required[int] `json:"pageSize"`+ Search Optional[string] `json:"search,omitempty"`+ StatusField Optional[string] `json:"status,omitempty"`+ Tags []string `json:"tags,omitempty"`}func (r *FullResponse) Schema() *ObjectSchema {return Object(map[string]Schema{- "id": String(&r.ID).Required(),- "name": String(&r.Name).Required(),- "email": String(&r.Email).Required(),- "page": Int(&r.Page).Required(),- "pageSize": Int(&r.PageSize).Required(),- "search": String(&r.Search).Optional(),- "status": String(&r.StatusField).Optional(),- "tags": Array(String(nil)).Optional(),+ "id": Str(&r.ID),+ "name": Str(&r.Name),+ "email": Str(&r.Email),+ "page": Int(&r.Page),+ "pageSize": Int(&r.PageSize),+ "search": OptStr(&r.Search),+ "status": OptStr(&r.StatusField),+ "tags": Array(StringElem(nil)).Optional(),}).Title("FullResponse")}@@ -146,12 +146,12 @@ func (*FullResponse) Status() int { return http.StatusOK }// --- Path only ---type DeleteItemRequest struct {- ID string `json:"-"`+ ID Required[string] `json:"-"`}func (r *DeleteItemRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "id": String(&r.ID).From(SourcePath).Required().UUID(),+ "id": Str(&r.ID).From(SourcePath).UUID(),}).Title("DeleteItemRequest")}@@ -164,23 +164,23 @@ func (Deleted) Status() int { return http.StatusNoContent }// --- Path source for error type dispatch ---type ErrorTypeRequest struct {- ErrorType string `json:"-"`+ ErrorType Required[string] `json:"-"`}func (r *ErrorTypeRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "type": String(&r.ErrorType).From(SourcePath).Required(),+ "type": Str(&r.ErrorType).From(SourcePath),}).Title("ErrorTypeRequest")}// OKStatus is a simple OK responsetype OKStatus struct {- StatusMsg string `json:"status"`+ StatusMsg Required[string] `json:"status"`}func (r *OKStatus) Schema() *ObjectSchema {return Object(map[string]Schema{- "status": String(&r.StatusMsg).Required(),+ "status": Str(&r.StatusMsg),})}@@ -189,26 +189,26 @@ func (*OKStatus) Status() int { return http.StatusOK }// --- Cookies ---type CookieRequest struct {- SessionID string `json:"-"`- UserID string `json:"-"`+ SessionID Required[string] `json:"-"`+ UserID Optional[string] `json:"-"`}func (r *CookieRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "session_id": String(&r.SessionID).From(SourceCookie).Required(),- "user_id": String(&r.UserID).From(SourceCookie).Optional(),+ "session_id": Str(&r.SessionID).From(SourceCookie),+ "user_id": OptStr(&r.UserID).From(SourceCookie),}).Title("CookieRequest")}type CookieResponse struct {- SessionID string `json:"sessionId"`- UserID string `json:"userId"`+ SessionID Required[string] `json:"sessionId"`+ UserID Optional[string] `json:"userId"`}func (r *CookieResponse) Schema() *ObjectSchema {return Object(map[string]Schema{- "sessionId": String(&r.SessionID).Required(),- "userId": String(&r.UserID).Optional(),+ "sessionId": Str(&r.SessionID),+ "userId": OptStr(&r.UserID),})}@@ -217,26 +217,26 @@ func (*CookieResponse) Status() int { return http.StatusOK }// --- Date query param ---type TimeQueryRequest struct {- ID string `json:"-"`- StartDate string `json:"-"`+ ID Required[string] `json:"-"`+ StartDate Optional[string] `json:"-"`}func (r *TimeQueryRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "id": String(&r.ID).From(SourcePath).Required().UUID(),- "startDate": String(&r.StartDate).From(SourceQuery).Optional().Description("Start date in YYYY-MM-DD format"),+ "id": Str(&r.ID).From(SourcePath).UUID(),+ "startDate": OptStr(&r.StartDate).From(SourceQuery).Description("Start date in YYYY-MM-DD format"),}).Title("TimeQueryRequest")}type TimeResponse struct {- ID string `json:"id"`- StartDate string `json:"startDate,omitempty"`+ ID Required[string] `json:"id"`+ StartDate Optional[string] `json:"startDate,omitempty"`}func (r *TimeResponse) Schema() *ObjectSchema {return Object(map[string]Schema{- "id": String(&r.ID).Required(),- "startDate": String(&r.StartDate).Optional(),+ "id": Str(&r.ID),+ "startDate": OptStr(&r.StartDate),})}@@ -245,16 +245,16 @@ func (*TimeResponse) Status() int { return http.StatusOK }// --- Pattern validation ---type PatternRequest struct {- Code string `json:"code"`- Phone string `json:"phone"`- SlugField string `json:"slug"`+ Code Required[string] `json:"code"`+ Phone Optional[string] `json:"phone"`+ SlugField Optional[string] `json:"slug"`}func (r *PatternRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "code": String(&r.Code).Required().Pattern(`^[A-Z]{3}-\d{4}$`).Description("Format: XXX-0000"),- "phone": String(&r.Phone).Optional().Pattern(`^\+\d{1,3}-\d{3}-\d{3}-\d{4}$`),- "slug": String(&r.SlugField).Optional().Pattern(`^[a-z0-9]+(?:-[a-z0-9]+)*$`),+ "code": Str(&r.Code).Pattern(`^[A-Z]{3}-\d{4}$`).Description("Format: XXX-0000"),+ "phone": OptStr(&r.Phone).Pattern(`^\+\d{1,3}-\d{3}-\d{3}-\d{4}$`),+ "slug": OptStr(&r.SlugField).Pattern(`^[a-z0-9]+(?:-[a-z0-9]+)*$`),}).Title("PatternRequest")}@@ -263,16 +263,16 @@ func (*PatternRequest) Status() int { return http.StatusOK }// --- URL/URI format ---type URLRequest struct {- Website string `json:"website"`- Callback string `json:"callback"`- ResourceURI string `json:"resourceUri"`+ Website Required[string] `json:"website"`+ Callback Optional[string] `json:"callback"`+ ResourceURI Optional[string] `json:"resourceUri"`}func (r *URLRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "website": String(&r.Website).Required().URL(),- "callback": String(&r.Callback).Optional().URL(),- "resourceUri": String(&r.ResourceURI).Optional().URI(),+ "website": Str(&r.Website).URL(),+ "callback": OptStr(&r.Callback).URL(),+ "resourceUri": OptStr(&r.ResourceURI).URI(),}).Title("URLRequest")}@@ -281,16 +281,16 @@ func (*URLRequest) Status() int { return http.StatusOK }// --- Float validation ---type MeasurementRequest struct {- Temperature float64 `json:"temperature"`- Humidity float64 `json:"humidity"`- Pressure float64 `json:"pressure"`+ Temperature Required[float64] `json:"temperature"`+ Humidity Optional[float64] `json:"humidity"`+ Pressure Optional[float64] `json:"pressure"`}func (r *MeasurementRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "temperature": Float(&r.Temperature).Required().Min(-273.15).Max(1000),- "humidity": Float(&r.Humidity).Optional().Min(0).Max(100),- "pressure": Float(&r.Pressure).Optional().Min(0),+ "temperature": Float(&r.Temperature).Min(-273.15).Max(1000),+ "humidity": OptFloat(&r.Humidity).Min(0).Max(100),+ "pressure": OptFloat(&r.Pressure).Min(0),}).Title("MeasurementRequest")}@@ -299,14 +299,14 @@ func (*MeasurementRequest) Status() int { return http.StatusOK }// --- Array with custom validation ---type TagsRequest struct {- Name string `json:"name"`- Tags []string `json:"tags"`+ Name Required[string] `json:"name"`+ Tags []string `json:"tags"`}func (r *TagsRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "name": String(&r.Name).Required(),- "tags": Array(String(nil)).+ "name": Str(&r.Name),+ "tags": Array(StringElem(nil)).Required().MinItems(1).MaxItems(5).@@ -330,56 +330,56 @@ func (*TagsRequest) Status() int { return http.StatusOK }// --- Nested object ---type CreateOrderRequest struct {- CustomerName string `json:"customerName"`+ CustomerName Required[string] `json:"customerName"`ShippingAddress struct {- Street string `json:"street"`- City string `json:"city"`- ZipCode string `json:"zipCode"`- Country string `json:"country"`+ Street Required[string] `json:"street"`+ City Required[string] `json:"city"`+ ZipCode Required[string] `json:"zipCode"`+ Country Required[string] `json:"country"`} `json:"shippingAddress"`}func (r *CreateOrderRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "customerName": String(&r.CustomerName).Required().MinLength(1),+ "customerName": Str(&r.CustomerName).MinLength(1),"shippingAddress": Object(map[string]Schema{- "street": String(&r.ShippingAddress.Street).Required().MinLength(1).MaxLength(200),- "city": String(&r.ShippingAddress.City).Required().MinLength(1).MaxLength(100),- "zipCode": String(&r.ShippingAddress.ZipCode).Required().Pattern(`^\d{5}(-\d{4})?$`),- "country": String(&r.ShippingAddress.Country).Required().Enum("US", "CA", "UK", "DE"),+ "street": Str(&r.ShippingAddress.Street).MinLength(1).MaxLength(200),+ "city": Str(&r.ShippingAddress.City).MinLength(1).MaxLength(100),+ "zipCode": Str(&r.ShippingAddress.ZipCode).Pattern(`^\d{5}(-\d{4})?$`),+ "country": Str(&r.ShippingAddress.Country).Enum("US", "CA", "UK", "DE"),}).Required(),}).Title("CreateOrderRequest")}func (*CreateOrderRequest) Status() int { return http.StatusOK }-// --- Nullable fields bound to actual pointer struct fields ---+// --- Nullable fields (using Optional to track presence) ---type NullableRequest struct {- Name string `json:"name"`- Nickname *string `json:"nickname"`- Age *int `json:"age"`+ Name Required[string] `json:"name"`+ Nickname Optional[string] `json:"nickname"`+ Age Optional[int] `json:"age"`}func (r *NullableRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "name": String(&r.Name).Required(),- "nickname": String(r.Nickname).Optional().Nullable(),- "age": Int(r.Age).Optional().Nullable().Min(0),+ "name": Str(&r.Name),+ "nickname": OptStr(&r.Nickname).Nullable(),+ "age": OptInt(&r.Age).Min(0),}).Title("NullableRequest")}type NullableResponse struct {- Name string `json:"name"`- HasNickname bool `json:"hasNickname"`- HasAge bool `json:"hasAge"`+ Name Required[string] `json:"name"`+ HasNickname Required[bool] `json:"hasNickname"`+ HasAge Required[bool] `json:"hasAge"`}func (r *NullableResponse) Schema() *ObjectSchema {return Object(map[string]Schema{- "name": String(&r.Name).Required(),- "hasNickname": Bool(&r.HasNickname).Required(),- "hasAge": Bool(&r.HasAge).Required(),+ "name": Str(&r.Name),+ "hasNickname": Bool(&r.HasNickname),+ "hasAge": Bool(&r.HasAge),})}@@ -388,24 +388,24 @@ func (*NullableResponse) Status() int { return http.StatusOK }// --- Context echo (reads headers, sets headers / cookies) ---type ContextRequest struct {- Data string `json:"data"`+ Data Optional[string] `json:"data"`}func (r *ContextRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "data": String(&r.Data).Optional(),+ "data": OptStr(&r.Data),}).Title("ContextRequest")}type ContextResponse struct {- ReceivedHeader string `json:"receivedHeader"`- Data string `json:"data"`+ ReceivedHeader Optional[string] `json:"receivedHeader"`+ Data Optional[string] `json:"data"`}func (r *ContextResponse) Schema() *ObjectSchema {return Object(map[string]Schema{- "receivedHeader": String(&r.ReceivedHeader).Optional(),- "data": String(&r.Data).Optional(),+ "receivedHeader": OptStr(&r.ReceivedHeader),+ "data": OptStr(&r.Data),})}@@ -420,16 +420,16 @@ type PetUnion interface {type DogPet struct {UnionBase- Type string `json:"type"`- Name string `json:"name"`- Breed string `json:"breed"`+ Type Required[string] `json:"type"`+ Name Required[string] `json:"name"`+ Breed Required[string] `json:"breed"`}func (d *DogPet) Schema() *ObjectSchema {return Object(map[string]Schema{- "type": String(&d.Type).Required(),- "name": String(&d.Name).Required().MinLength(1),- "breed": String(&d.Breed).Required().MinLength(1),+ "type": Str(&d.Type),+ "name": Str(&d.Name).MinLength(1),+ "breed": Str(&d.Breed).MinLength(1),}).Title("DogPet")}func (d *DogPet) unionMarker() {}@@ -437,16 +437,16 @@ func (d *DogPet) petMarker() {}type CatPet struct {UnionBase- Type string `json:"type"`- Name string `json:"name"`- Indoor bool `json:"indoor"`+ Type Required[string] `json:"type"`+ Name Required[string] `json:"name"`+ Indoor Optional[bool] `json:"indoor"`}func (c *CatPet) Schema() *ObjectSchema {return Object(map[string]Schema{- "type": String(&c.Type).Required(),- "name": String(&c.Name).Required().MinLength(1),- "indoor": Bool(&c.Indoor).Optional(),+ "type": Str(&c.Type),+ "name": Str(&c.Name).MinLength(1),+ "indoor": OptBool(&c.Indoor),}).Title("CatPet")}func (c *CatPet) unionMarker() {}@@ -461,13 +461,13 @@ var PetUnionDef = UnionDef[PetUnion]{}type AdoptPetRequest struct {- AdopterName string `json:"adopterName"`- Pet PetUnion `json:"-"`+ AdopterName Required[string] `json:"adopterName"`+ Pet PetUnion `json:"-"`}func (r *AdoptPetRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "adopterName": String(&r.AdopterName).Required().MinLength(1),+ "adopterName": Str(&r.AdopterName).MinLength(1),"pet": UnionField(&r.Pet, PetUnionDef).Required(),}).Title("AdoptPetRequest")}@@ -481,16 +481,16 @@ func (r *AdoptPetRequest) UnmarshalJSON(data []byte) error {}type AdoptResponse struct {- Adopter string `json:"adopter"`- PetType string `json:"petType"`- PetName string `json:"petName"`+ Adopter Required[string] `json:"adopter"`+ PetType Required[string] `json:"petType"`+ PetName Required[string] `json:"petName"`}func (r *AdoptResponse) Schema() *ObjectSchema {return Object(map[string]Schema{- "adopter": String(&r.Adopter).Required(),- "petType": String(&r.PetType).Required(),- "petName": String(&r.PetName).Required(),+ "adopter": Str(&r.Adopter),+ "petType": Str(&r.PetType),+ "petName": Str(&r.PetName),})}@@ -504,31 +504,31 @@ type ProcessResult interface {}type ProcessOK struct {- StatusMsg string `json:"status"`+ StatusMsg Required[string] `json:"status"`}func (r *ProcessOK) Schema() *ObjectSchema {- return Object(map[string]Schema{"status": String(&r.StatusMsg).Required()})+ return Object(map[string]Schema{"status": Str(&r.StatusMsg)})}func (*ProcessOK) Status() int { return http.StatusOK }func (*ProcessOK) processMarker() {}type ProcessCreated struct {- ID string `json:"id"`+ ID Required[string] `json:"id"`}func (r *ProcessCreated) Schema() *ObjectSchema {- return Object(map[string]Schema{"id": String(&r.ID).Required()})+ return Object(map[string]Schema{"id": Str(&r.ID)})}func (*ProcessCreated) Status() int { return http.StatusCreated }func (*ProcessCreated) processMarker() {}type ProcessAccepted struct {- StatusMsg string `json:"status"`+ StatusMsg Required[string] `json:"status"`}func (r *ProcessAccepted) Schema() *ObjectSchema {- return Object(map[string]Schema{"status": String(&r.StatusMsg).Required()})+ return Object(map[string]Schema{"status": Str(&r.StatusMsg)})}func (*ProcessAccepted) Status() int { return http.StatusAccepted }func (*ProcessAccepted) processMarker() {}@@ -540,11 +540,11 @@ func (*ProcessNoContent) Status() int { return http.StatusNoContent }func (*ProcessNoContent) processMarker() {}type ProcessCustom struct {- StatusMsg string `json:"status"`+ StatusMsg Required[string] `json:"status"`}func (r *ProcessCustom) Schema() *ObjectSchema {- return Object(map[string]Schema{"status": String(&r.StatusMsg).Required()})+ return Object(map[string]Schema{"status": Str(&r.StatusMsg)})}func (*ProcessCustom) Status() int { return 207 }func (*ProcessCustom) processMarker() {}@@ -552,11 +552,11 @@ func (*ProcessCustom) processMarker() {}// --- Health response ---type HealthResponse struct {- StatusMsg string `json:"status"`+ StatusMsg Required[string] `json:"status"`}func (r *HealthResponse) Schema() *ObjectSchema {- return Object(map[string]Schema{"status": String(&r.StatusMsg).Required()})+ return Object(map[string]Schema{"status": Str(&r.StatusMsg)})}func (*HealthResponse) Status() int { return http.StatusOK }@@ -569,19 +569,19 @@ func (*HealthResponse) Status() int { return http.StatusOK }// =============================================================================func errorByName(_ context.Context, req *SimpleRequest) (OKStatus, error) {- switch req.Name {+ switch req.Name.Get() {case "conflict":- return OKStatus{}, Conflict("item %s already exists", req.Name)+ return OKStatus{}, Conflict("item %s already exists", req.Name.Get())case "notfound":return OKStatus{}, NotFound("item not found")case "forbidden":return OKStatus{}, Forbidden("access denied")}- return OKStatus{StatusMsg: "ok"}, nil+ return OKStatus{StatusMsg: NewRequired("ok")}, nil}func errorByType(_ context.Context, req *ErrorTypeRequest) (OKStatus, error) {- switch req.ErrorType {+ switch req.ErrorType.Get() {case "bad-request":return OKStatus{}, BadRequest("invalid input")case "unauthorized":@@ -603,21 +603,21 @@ func errorByType(_ context.Context, req *ErrorTypeRequest) (OKStatus, error) {case "gateway-timeout":return OKStatus{}, GatewayTimeout("upstream timeout")}- return OKStatus{StatusMsg: "ok"}, nil+ return OKStatus{StatusMsg: NewRequired("ok")}, nil}func statusByName(_ context.Context, req *SimpleRequest) (ProcessResult, error) {- switch req.Name {+ switch req.Name.Get() {case "create":- return &ProcessCreated{ID: "new-id"}, nil+ return &ProcessCreated{ID: NewRequired("new-id")}, nilcase "accepted":- return &ProcessAccepted{StatusMsg: "processing"}, nil+ return &ProcessAccepted{StatusMsg: NewRequired("processing")}, nilcase "nocontent":return &ProcessNoContent{}, nilcase "custom":- return &ProcessCustom{StatusMsg: "multi-status"}, nil+ return &ProcessCustom{StatusMsg: NewRequired("multi-status")}, nil}- return &ProcessOK{StatusMsg: "ok"}, nil+ return &ProcessOK{StatusMsg: NewRequired("ok")}, nil}func contextEcho(ctx context.Context, req *ContextRequest) (ContextResponse, error) {@@ -628,16 +628,16 @@ func contextEcho(ctx context.Context, req *ContextRequest) (ContextResponse, errcustomHeader := httpCtx.Header("X-Custom-Header")httpCtx.SetHeader("X-Response-Header", "response-value")httpCtx.SetCookie(&http.Cookie{Name: "test_cookie", Value: "cookie-value"})- return ContextResponse{ReceivedHeader: customHeader, Data: req.Data}, nil+ return ContextResponse{ReceivedHeader: NewOptional(customHeader), Data: req.Data}, nil}func getItemEcho(_ context.Context, req *GetItemRequest) (FullResponse, error) {return FullResponse{ID: req.ID,- Name: "Test Item",- Email: "[email protected]",- Page: req.Page,- PageSize: req.PageSize,+ Name: NewRequired("Test Item"),+ Email: NewRequired("[email protected]"),+ Page: NewRequired(req.Page.Get()),+ PageSize: NewRequired(req.PageSize.Get()),Search: req.Search,StatusField: req.StatusField,}, nil@@ -648,8 +648,8 @@ func updateItemEcho(_ context.Context, req *FullRequest) (FullResponse, error) {ID: req.ID,Name: req.Name,Email: req.Email,- Page: req.Page,- PageSize: req.PageSize,+ Page: NewRequired(req.Page.Get()),+ PageSize: NewRequired(req.PageSize.Get()),Tags: req.Tags,}, nil}@@ -661,7 +661,7 @@ func deleteItemEcho(_ context.Context, _ *DeleteItemRequest) (Deleted, error) {func createItem(_ context.Context, req *SimpleRequest) (CreatedSimpleResponse, error) {return CreatedSimpleResponse{SimpleResponse: SimpleResponse{- ID: uuid.New().String(),+ ID: NewRequired(uuid.New().String()),Name: req.Name,Email: req.Email,Count: req.Count,@@ -681,22 +681,22 @@ func adoptEcho(_ context.Context, req *AdoptPetRequest) (AdoptResponse, error) {var petType, petName stringswitch p := req.Pet.(type) {case *DogPet:- petType, petName = "dog", p.Name+ petType, petName = "dog", p.Name.Get()case *CatPet:- petType, petName = "cat", p.Name+ petType, petName = "cat", p.Name.Get()}return AdoptResponse{- Adopter: req.AdopterName,- PetType: petType,- PetName: petName,+ Adopter: NewRequired(req.AdopterName.Get()),+ PetType: NewRequired(petType),+ PetName: NewRequired(petName),}, nil}func nullableEcho(_ context.Context, req *NullableRequest) (NullableResponse, error) {return NullableResponse{Name: req.Name,- HasNickname: req.Nickname != nil,- HasAge: req.Age != nil,+ HasNickname: NewRequired(req.Nickname.IsSet() && !req.Nickname.IsNull()),+ HasAge: NewRequired(req.Age.IsSet() && !req.Age.IsNull()),}, nil}@@ -721,7 +721,7 @@ func orderEcho(_ context.Context, req *CreateOrderRequest) (CreateOrderRequest,}func healthHandler(_ context.Context, _ *EmptyRequest) (HealthResponse, error) {- return HealthResponse{StatusMsg: "healthy"}, nil+ return HealthResponse{StatusMsg: NewRequired("healthy")}, nil}// =============================================================================diff --git a/backend-go/pkg/chita/integration_test.go b/backend-go/pkg/chita/integration_test.goindex 2f4bbd86fb..837e2e5f81 100644--- a/backend-go/pkg/chita/integration_test.go+++ b/backend-go/pkg/chita/integration_test.go@@ -15,23 +15,23 @@ import (// --- Simple Request with Validation + OpenAPI ---type CreateProjectRequest struct {- Name string `json:"name"`- Description string `json:"description"`- IsPublic bool `json:"isPublic"`+ Name Required[string] `json:"name"`+ Description Optional[string] `json:"description"`+ IsPublic Optional[bool] `json:"isPublic"`}func (r *CreateProjectRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "name": String(&r.Name).Required().MinLength(1).MaxLength(100).Description("Project name"),- "description": String(&r.Description).Optional().MaxLength(500).Description("Project description"),- "isPublic": Bool(&r.IsPublic).Optional().Default(false).Description("Whether project is public"),+ "name": Str(&r.Name).MinLength(1).MaxLength(100).Description("Project name"),+ "description": OptStr(&r.Description).MaxLength(500).Description("Project description"),+ "isPublic": OptBool(&r.IsPublic).Default(false).Description("Whether project is public"),}).Title("CreateProjectRequest").Description("Request to create a new project")}func TestIntegration_SimpleRequest_ValidationAndOpenAPI(t *testing.T) {// Test 1: Validation works correctlyt.Run("validation_empty_name", func(t *testing.T) {- req := &CreateProjectRequest{Name: "", Description: "desc"}+ req := &CreateProjectRequest{} // Name not seterrs := req.Schema().Validate()require.Len(t, errs, 1)assert.Equal(t, "name", errs[0].Field)@@ -39,7 +39,7 @@ func TestIntegration_SimpleRequest_ValidationAndOpenAPI(t *testing.T) {})t.Run("validation_name_too_long", func(t *testing.T) {- req := &CreateProjectRequest{Name: string(make([]byte, 101))}+ req := &CreateProjectRequest{Name: NewRequired(string(make([]byte, 101)))}errs := req.Schema().Validate()require.Len(t, errs, 1)assert.Equal(t, "name", errs[0].Field)@@ -47,7 +47,7 @@ func TestIntegration_SimpleRequest_ValidationAndOpenAPI(t *testing.T) {})t.Run("validation_valid_request", func(t *testing.T) {- req := &CreateProjectRequest{Name: "My Project", Description: "A great project"}+ req := &CreateProjectRequest{Name: NewRequired("My Project"), Description: NewOptional("A great project")}errs := req.Schema().Validate()assert.Empty(t, errs)})@@ -91,29 +91,29 @@ func TestIntegration_SimpleRequest_ValidationAndOpenAPI(t *testing.T) {// --- Nested Object with Validation + OpenAPI ---type Address struct {- Street string `json:"street"`- City string `json:"city"`- ZipCode string `json:"zipCode"`+ Street Required[string] `json:"street"`+ City Required[string] `json:"city"`+ ZipCode Required[string] `json:"zipCode"`}func (a *Address) Schema() *ObjectSchema {return Object(map[string]Schema{- "street": String(&a.Street).Required().MinLength(1),- "city": String(&a.City).Required().MinLength(1),- "zipCode": String(&a.ZipCode).Required().Pattern(`^\d{5}$`),+ "street": Str(&a.Street).MinLength(1),+ "city": Str(&a.City).MinLength(1),+ "zipCode": Str(&a.ZipCode).Pattern(`^\d{5}$`),})}type CreateUserWithAddressRequest struct {- Name string `json:"name"`- Email string `json:"email"`- Address Address `json:"address"`+ Name Required[string] `json:"name"`+ Email Required[string] `json:"email"`+ Address Address `json:"address"`}func (r *CreateUserWithAddressRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "name": String(&r.Name).Required().MinLength(1),- "email": String(&r.Email).Required().Email(),+ "name": Str(&r.Name).MinLength(1),+ "email": Str(&r.Email).Email(),"address": r.Address.Schema().Required(),})}@@ -121,12 +121,12 @@ func (r *CreateUserWithAddressRequest) Schema() *ObjectSchema {func TestIntegration_NestedObject_ValidationAndOpenAPI(t *testing.T) {t.Run("validation_nested_errors", func(t *testing.T) {req := &CreateUserWithAddressRequest{- Name: "John",- Email: "invalid-email",+ Name: NewRequired("John"),+ Email: NewRequired("invalid-email"),Address: Address{- Street: "",- City: "NYC",- ZipCode: "invalid",+ Street: Required[string]{}, // not set+ City: NewRequired("NYC"),+ ZipCode: NewRequired("invalid"),},}errs := req.Schema().Validate()@@ -143,12 +143,12 @@ func TestIntegration_NestedObject_ValidationAndOpenAPI(t *testing.T) {t.Run("validation_valid_nested", func(t *testing.T) {req := &CreateUserWithAddressRequest{- Name: "John",- Email: "[email protected]",+ Name: NewRequired("John"),+ Email: NewRequired("[email protected]"),Address: Address{- Street: "123 Main St",- City: "NYC",- ZipCode: "10001",+ Street: NewRequired("123 Main St"),+ City: NewRequired("NYC"),+ ZipCode: NewRequired("10001"),},}errs := req.Schema().Validate()@@ -182,20 +182,20 @@ type Provider interface {}type SqlDatabaseProvider struct {- Type string `json:"type"`- Host string `json:"host"`- Port int `json:"port"`- Database string `json:"database"`- Username string `json:"username"`+ Type Required[string] `json:"type"`+ Host Required[string] `json:"host"`+ Port Required[int] `json:"port"`+ Database Required[string] `json:"database"`+ Username Required[string] `json:"username"`}func (p *SqlDatabaseProvider) Schema() *ObjectSchema {return Object(map[string]Schema{- "type": String(&p.Type).Required(),- "host": String(&p.Host).Required().MinLength(1).Description("Database host"),- "port": Int(&p.Port).Required().Min(1).Max(65535).Description("Database port"),- "database": String(&p.Database).Required().MinLength(1).Description("Database name"),- "username": String(&p.Username).Required().MinLength(1).Description("Database username"),+ "type": Str(&p.Type),+ "host": Str(&p.Host).MinLength(1).Description("Database host"),+ "port": Int(&p.Port).Min(1).Max(65535).Description("Database port"),+ "database": Str(&p.Database).MinLength(1).Description("Database name"),+ "username": Str(&p.Username).MinLength(1).Description("Database username"),}).Title("SqlDatabaseProvider")}@@ -203,18 +203,18 @@ func (p *SqlDatabaseProvider) unionMarker() {}func (p *SqlDatabaseProvider) providerMarker() {}type AwsIamProvider struct {- Type string `json:"type"`- Region string `json:"region"`- AccountID string `json:"accountId"`- RoleArn string `json:"roleArn"`+ Type Required[string] `json:"type"`+ Region Required[string] `json:"region"`+ AccountID Required[string] `json:"accountId"`+ RoleArn Required[string] `json:"roleArn"`}func (p *AwsIamProvider) Schema() *ObjectSchema {return Object(map[string]Schema{- "type": String(&p.Type).Required(),- "region": String(&p.Region).Required().Pattern(`^[a-z]{2}-[a-z]+-\d$`).Description("AWS region"),- "accountId": String(&p.AccountID).Required().Pattern(`^\d{12}$`).Description("AWS account ID"),- "roleArn": String(&p.RoleArn).Required().MinLength(1).Description("IAM role ARN"),+ "type": Str(&p.Type),+ "region": Str(&p.Region).Pattern(`^[a-z]{2}-[a-z]+-\d$`).Description("AWS region"),+ "accountId": Str(&p.AccountID).Pattern(`^\d{12}$`).Description("AWS account ID"),+ "roleArn": Str(&p.RoleArn).MinLength(1).Description("IAM role ARN"),}).Title("AwsIamProvider")}@@ -222,18 +222,18 @@ func (p *AwsIamProvider) unionMarker() {}func (p *AwsIamProvider) providerMarker() {}type RedisProvider struct {- Type string `json:"type"`- Host string `json:"host"`- Port int `json:"port"`- Password string `json:"password"`+ Type Required[string] `json:"type"`+ Host Required[string] `json:"host"`+ Port Required[int] `json:"port"`+ Password Optional[string] `json:"password"`}func (p *RedisProvider) Schema() *ObjectSchema {return Object(map[string]Schema{- "type": String(&p.Type).Required(),- "host": String(&p.Host).Required().MinLength(1),- "port": Int(&p.Port).Required().Min(1).Max(65535),- "password": String(&p.Password).Optional().WriteOnly(),+ "type": Str(&p.Type),+ "host": Str(&p.Host).MinLength(1),+ "port": Int(&p.Port).Min(1).Max(65535),+ "password": OptStr(&p.Password).WriteOnly(),}).Title("RedisProvider")}@@ -250,13 +250,13 @@ var ProviderParser = UnionDef[Provider]{}type CreateDynamicSecretRequest struct {- Name string `json:"name"`- Provider Provider `json:"-"`+ Name Required[string] `json:"name"`+ Provider Provider `json:"-"`}func (r *CreateDynamicSecretRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "name": String(&r.Name).Required().MinLength(1).MaxLength(64).Pattern(`^[a-zA-Z0-9_-]+$`),+ "name": Str(&r.Name).MinLength(1).MaxLength(64).Pattern(`^[a-zA-Z0-9_-]+$`),"provider": UnionField(&r.Provider, ProviderParser).Required().Description("Provider configuration"),}).Title("CreateDynamicSecretRequest")}@@ -288,14 +288,14 @@ func TestIntegration_Union_ValidationAndOpenAPI(t *testing.T) {err := json.Unmarshal(data, &req)require.NoError(t, err)- assert.Equal(t, "my-secret", req.Name)+ assert.Equal(t, "my-secret", req.Name.Get())require.NotNil(t, req.Provider)sqlProvider, ok := req.Provider.(*SqlDatabaseProvider)require.True(t, ok)- assert.Equal(t, "localhost", sqlProvider.Host)- assert.Equal(t, 5432, sqlProvider.Port)- assert.Equal(t, "mydb", sqlProvider.Database)+ assert.Equal(t, "localhost", sqlProvider.Host.Get())+ assert.Equal(t, 5432, sqlProvider.Port.Get())+ assert.Equal(t, "mydb", sqlProvider.Database.Get())})t.Run("parse_aws_iam_provider", func(t *testing.T) {@@ -315,8 +315,8 @@ func TestIntegration_Union_ValidationAndOpenAPI(t *testing.T) {awsProvider, ok := req.Provider.(*AwsIamProvider)require.True(t, ok)- assert.Equal(t, "us-east-1", awsProvider.Region)- assert.Equal(t, "123456789012", awsProvider.AccountID)+ assert.Equal(t, "us-east-1", awsProvider.Region.Get())+ assert.Equal(t, "123456789012", awsProvider.AccountID.Get())})t.Run("parse_unknown_provider_type", func(t *testing.T) {@@ -335,7 +335,7 @@ func TestIntegration_Union_ValidationAndOpenAPI(t *testing.T) {t.Run("validation_provider_required", func(t *testing.T) {req := &CreateDynamicSecretRequest{- Name: "test",+ Name: NewRequired("test"),Provider: nil,}errs := req.Schema().Validate()@@ -353,13 +353,13 @@ func TestIntegration_Union_ValidationAndOpenAPI(t *testing.T) {t.Run("validation_provider_fields", func(t *testing.T) {req := &CreateDynamicSecretRequest{- Name: "test",+ Name: NewRequired("test"),Provider: &SqlDatabaseProvider{- Type: "sql-database",- Host: "", // Invalid - required- Port: 99999, // Invalid - max 65535- Database: "db",- Username: "user",+ Type: NewRequired("sql-database"),+ Host: Required[string]{}, // Invalid - not set+ Port: NewRequired(99999), // Invalid - max 65535+ Database: NewRequired("db"),+ Username: NewRequired("user"),},}errs := req.Schema().Validate()@@ -368,13 +368,13 @@ func TestIntegration_Union_ValidationAndOpenAPI(t *testing.T) {t.Run("validation_valid_request", func(t *testing.T) {req := &CreateDynamicSecretRequest{- Name: "my-secret",+ Name: NewRequired("my-secret"),Provider: &SqlDatabaseProvider{- Type: "sql-database",- Host: "localhost",- Port: 5432,- Database: "mydb",- Username: "admin",+ Type: NewRequired("sql-database"),+ Host: NewRequired("localhost"),+ Port: NewRequired(5432),+ Database: NewRequired("mydb"),+ Username: NewRequired("admin"),},}errs := req.Schema().Validate()@@ -501,7 +501,7 @@ func TestIntegration_FullOpenAPISpec(t *testing.T) {NewSecurity("apiKey"),},QueryParams: map[string]Schema{- "projectId": String(new(string)).Required().UUID().Description("Project ID"),+ "projectId": StringElem(nil).UUID().Description("Project ID"),},},})@@ -546,7 +546,7 @@ func TestIntegration_FullOpenAPISpec(t *testing.T) {require.Len(t, params, 1)assert.Equal(t, "projectId", params[0]["name"])assert.Equal(t, "query", params[0]["in"])- assert.Equal(t, true, params[0]["required"])+ // QueryParams with StringElem are optional by default// Verify it serializes to valid JSONjsonBytes, err := spec.JSONIndent("", " ")@@ -562,16 +562,16 @@ func TestIntegration_FullOpenAPISpec(t *testing.T) {// --- UUID Field Integration ---type ResourceRequest struct {- ID uuid.UUID `json:"id"`- ParentID uuid.UUID `json:"parentId"`- Name string `json:"name"`+ ID uuid.UUID `json:"id"`+ ParentID uuid.UUID `json:"parentId"`+ Name Required[string] `json:"name"`}func (r *ResourceRequest) Schema() *ObjectSchema {return Object(map[string]Schema{"id": UUID(&r.ID).Required().Description("Resource ID"),"parentId": UUID(&r.ParentID).Optional().Nullable().Description("Parent resource ID"),- "name": String(&r.Name).Required().MinLength(1),+ "name": Str(&r.Name).MinLength(1),})}@@ -579,7 +579,7 @@ func TestIntegration_UUID_ValidationAndOpenAPI(t *testing.T) {t.Run("validation_uuid_required", func(t *testing.T) {req := &ResourceRequest{ID: uuid.Nil,- Name: "test",+ Name: NewRequired("test"),}errs := req.Schema().Validate()require.NotEmpty(t, errs)@@ -590,7 +590,7 @@ func TestIntegration_UUID_ValidationAndOpenAPI(t *testing.T) {req := &ResourceRequest{ID: uuid.New(),ParentID: uuid.Nil, // Optional, should be fine- Name: "test",+ Name: NewRequired("test"),}errs := req.Schema().Validate()assert.Empty(t, errs)@@ -616,20 +616,20 @@ func TestIntegration_UUID_ValidationAndOpenAPI(t *testing.T) {// --- Enum Validation + OpenAPI ---type StatusRequest struct {- Status string `json:"status"`- Level int `json:"level"`+ Status Required[string] `json:"status"`+ Level Required[int] `json:"level"`}func (r *StatusRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "status": String(&r.Status).Required().Enum("active", "inactive", "pending").Description("Resource status"),- "level": Int(&r.Level).Required().Enum(1, 2, 3, 4, 5).Description("Priority level"),+ "status": Str(&r.Status).Enum("active", "inactive", "pending").Description("Resource status"),+ "level": Int(&r.Level).Enum(1, 2, 3, 4, 5).Description("Priority level"),})}func TestIntegration_Enum_ValidationAndOpenAPI(t *testing.T) {t.Run("validation_string_enum_invalid", func(t *testing.T) {- req := &StatusRequest{Status: "unknown", Level: 1}+ req := &StatusRequest{Status: NewRequired("unknown"), Level: NewRequired(1)}errs := req.Schema().Validate()require.Len(t, errs, 1)assert.Equal(t, "status", errs[0].Field)@@ -637,7 +637,7 @@ func TestIntegration_Enum_ValidationAndOpenAPI(t *testing.T) {})t.Run("validation_int_enum_invalid", func(t *testing.T) {- req := &StatusRequest{Status: "active", Level: 10}+ req := &StatusRequest{Status: NewRequired("active"), Level: NewRequired(10)}errs := req.Schema().Validate()require.Len(t, errs, 1)assert.Equal(t, "level", errs[0].Field)@@ -645,7 +645,7 @@ func TestIntegration_Enum_ValidationAndOpenAPI(t *testing.T) {})t.Run("validation_enum_valid", func(t *testing.T) {- req := &StatusRequest{Status: "active", Level: 3}+ req := &StatusRequest{Status: NewRequired("active"), Level: NewRequired(3)}errs := req.Schema().Validate()assert.Empty(t, errs)})diff --git a/backend-go/pkg/chita/ispresent_test.go b/backend-go/pkg/chita/ispresent_test.goindex 2f7e136b3a..2135cd5bc2 100644--- a/backend-go/pkg/chita/ispresent_test.go+++ b/backend-go/pkg/chita/ispresent_test.go@@ -18,27 +18,27 @@ func TestSchema_IsPresent(t *testing.T) {build func() SchemawantPresent bool}{- // String- {"string/nil", func() Schema { return String(nil) }, false},- {"string/empty", func() Schema { v := ""; return String(&v) }, false},- {"string/non-empty", func() Schema { v := "hello"; return String(&v) }, true},- {"string/whitespace", func() Schema { v := " "; return String(&v) }, true},-- // Int- {"int/nil", func() Schema { return Int(nil) }, false},- {"int/zero", func() Schema { v := 0; return Int(&v) }, true},- {"int/non-zero", func() Schema { v := 42; return Int(&v) }, true},- {"int/negative", func() Schema { v := -10; return Int(&v) }, true},-- // Float- {"float/nil", func() Schema { return Float(nil) }, false},- {"float/zero", func() Schema { v := 0.0; return Float(&v) }, true},- {"float/non-zero", func() Schema { v := 3.14; return Float(&v) }, true},-- // Bool- {"bool/nil", func() Schema { return Bool(nil) }, false},- {"bool/false", func() Schema { v := false; return Bool(&v) }, true},- {"bool/true", func() Schema { v := true; return Bool(&v) }, true},+ // String (using Required/Optional)+ {"string/not-set", func() Schema { var v Required[string]; return Str(&v) }, false},+ {"string/empty", func() Schema { v := NewRequired(""); return Str(&v) }, false},+ {"string/non-empty", func() Schema { v := NewRequired("hello"); return Str(&v) }, true},+ {"string/whitespace", func() Schema { v := NewRequired(" "); return Str(&v) }, true},++ // Int (using Required/Optional)+ {"int/not-set", func() Schema { var v Required[int]; return Int(&v) }, false},+ {"int/zero", func() Schema { v := NewRequired(0); return Int(&v) }, true},+ {"int/non-zero", func() Schema { v := NewRequired(42); return Int(&v) }, true},+ {"int/negative", func() Schema { v := NewRequired(-10); return Int(&v) }, true},++ // Float (using Required/Optional)+ {"float/not-set", func() Schema { var v Required[float64]; return Float(&v) }, false},+ {"float/zero", func() Schema { v := NewRequired(0.0); return Float(&v) }, true},+ {"float/non-zero", func() Schema { v := NewRequired(3.14); return Float(&v) }, true},++ // Bool (using Required/Optional)+ {"bool/not-set", func() Schema { var v Required[bool]; return Bool(&v) }, false},+ {"bool/false", func() Schema { v := NewRequired(false); return Bool(&v) }, true},+ {"bool/true", func() Schema { v := NewRequired(true); return Bool(&v) }, true},// UUID{"uuid/nil", func() Schema { return UUID(nil) }, false},@@ -83,79 +83,79 @@ func TestSchema_IsPresent(t *testing.T) {func TestCompositeSchema_IsPresent(t *testing.T) {t.Run("object/none present", func(t *testing.T) {- name := ""- schema := Object(map[string]Schema{"name": String(&name)})+ var name Required[string] // not set+ schema := Object(map[string]Schema{"name": Str(&name)})assert.False(t, schema.IsPresent())})t.Run("object/one present", func(t *testing.T) {- name := "John"- schema := Object(map[string]Schema{"name": String(&name)})+ name := NewRequired("John")+ schema := Object(map[string]Schema{"name": Str(&name)})assert.True(t, schema.IsPresent())})t.Run("object/partial present", func(t *testing.T) {- name := ""- age := 25- schema := Object(map[string]Schema{"name": String(&name), "age": Int(&age)})+ var name Required[string] // not set+ age := NewRequired(25)+ schema := Object(map[string]Schema{"name": Str(&name), "age": Int(&age)})assert.True(t, schema.IsPresent())})t.Run("array/no fn", func(t *testing.T) {- schema := Array(String(new(string)))+ schema := Array(StringElem(nil))assert.False(t, schema.IsPresent())})t.Run("array/empty", func(t *testing.T) {items := []string{}- schema := Array(String(new(string))).IsPresentFn(func() bool { return len(items) > 0 })+ schema := Array(StringElem(nil)).IsPresentFn(func() bool { return len(items) > 0 })assert.False(t, schema.IsPresent())})t.Run("array/non-empty", func(t *testing.T) {items := []string{"a", "b"}- schema := Array(String(new(string))).IsPresentFn(func() bool { return len(items) > 0 })+ schema := Array(StringElem(nil)).IsPresentFn(func() bool { return len(items) > 0 })assert.True(t, schema.IsPresent())})t.Run("map/no fn", func(t *testing.T) {- schema := Map(String(new(string)))+ schema := Map(StringElem(nil))assert.False(t, schema.IsPresent())})t.Run("map/non-empty", func(t *testing.T) {m := map[string]string{"key": "value"}- schema := Map(String(new(string))).IsPresentFn(func() bool { return len(m) > 0 })+ schema := Map(StringElem(nil)).IsPresentFn(func() bool { return len(m) > 0 })assert.True(t, schema.IsPresent())})t.Run("oneOf/none", func(t *testing.T) {- v := ""- assert.False(t, OneOfSchemas(String(&v)).IsPresent())+ var v Required[string]+ assert.False(t, OneOfSchemas(Str(&v)).IsPresent())})t.Run("oneOf/one", func(t *testing.T) {- v := "hello"- assert.True(t, OneOfSchemas(String(&v)).IsPresent())+ v := NewRequired("hello")+ assert.True(t, OneOfSchemas(Str(&v)).IsPresent())})t.Run("anyOf/none", func(t *testing.T) {- v := ""- assert.False(t, AnyOf(String(&v)).IsPresent())+ var v Required[string]+ assert.False(t, AnyOf(Str(&v)).IsPresent())})t.Run("anyOf/one", func(t *testing.T) {- v := "hello"- assert.True(t, AnyOf(String(&v)).IsPresent())+ v := NewRequired("hello")+ assert.True(t, AnyOf(Str(&v)).IsPresent())})t.Run("allOf/none", func(t *testing.T) {- v := ""- assert.False(t, AllOf(String(&v)).IsPresent())+ var v Required[string]+ assert.False(t, AllOf(Str(&v)).IsPresent())})t.Run("allOf/present", func(t *testing.T) {- v := "hello"- assert.True(t, AllOf(String(&v)).IsPresent())+ v := NewRequired("hello")+ assert.True(t, AllOf(Str(&v)).IsPresent())})}diff --git a/backend-go/pkg/chita/nullable.go b/backend-go/pkg/chita/nullable.godeleted file mode 100644index 18d5f27f56..0000000000--- a/backend-go/pkg/chita/nullable.go+++ /dev/null@@ -1,204 +0,0 @@-package chita--import (- "bytes"- "encoding/json"-)--// JsonNullable distinguishes between absent, null, and present JSON values.-// Use this for optional request bodies or fields where you need to tell apart:-// - Field not present in JSON (Present=false, Null=false)-// - Field explicitly set to null (Present=true, Null=true)-// - Field has a value (Present=true, Null=false, Value populated)-type JsonNullable[T any] struct {- Value T- Present bool // true if the key existed in JSON (even if value was null)- Null bool // true if the value was explicitly "null"-}--// IsSet returns true if a non-null value was provided-func (j JsonNullable[T]) IsSet() bool {- return j.Present && !j.Null-}--// UnmarshalJSON implements json.Unmarshaler-func (j *JsonNullable[T]) UnmarshalJSON(data []byte) error {- j.Present = true- if bytes.Equal(data, []byte("null")) {- j.Null = true- return nil- }- return json.Unmarshal(data, &j.Value)-}--// MarshalJSON implements json.Marshaler-func (j JsonNullable[T]) MarshalJSON() ([]byte, error) {- if !j.Present || j.Null {- return []byte("null"), nil- }- return json.Marshal(j.Value)-}--// Ptr returns a pointer to the value if set, nil otherwise.-// Useful for passing to schema validators.-func (j *JsonNullable[T]) Ptr() *T {- if j.IsSet() {- return &j.Value- }- return nil-}--// Set creates a JsonNullable with a value-func Set[T any](value T) JsonNullable[T] {- return JsonNullable[T]{- Value: value,- Present: true,- Null: false,- }-}--// Null creates a JsonNullable that is explicitly null-func Null[T any]() JsonNullable[T] {- return JsonNullable[T]{- Present: true,- Null: true,- }-}--// Absent creates a JsonNullable that represents an absent field-func Absent[T any]() JsonNullable[T] {- return JsonNullable[T]{- Present: false,- Null: false,- }-}--// NullableSchema wraps any schema to handle the absent/null/present tri-state.-// Use this for PATCH semantics where you need to distinguish:-// - Field absent → don't update-// - Field null → clear/unset the value-// - Field present → update with value-//-// Usage:-//-// type UpdateRequest struct {-// Name JsonNullable[string] `json:"name"`-// }-//-// func (r *UpdateRequest) Schema() *ObjectSchema {-// return Object(map[string]Schema{-// "name": Nullable(&r.Name, String(&r.Name.Value).MinLength(1)).Optional(),-// })-// }-type NullableSchema[T any] struct {- ptr *JsonNullable[T]- inner Schema- required bool- title string- description string- deprecated bool- example any-}--// Nullable creates a NullableSchema wrapping an inner schema.-// The inner schema should bind to the JsonNullable's Value field.-func Nullable[T any](ptr *JsonNullable[T], inner Schema) *NullableSchema[T] {- return &NullableSchema[T]{- ptr: ptr,- inner: inner,- }-}--func (s *NullableSchema[T]) Required() *NullableSchema[T] {- s.required = true- return s-}--func (s *NullableSchema[T]) Optional() *NullableSchema[T] {- s.required = false- return s-}--func (s *NullableSchema[T]) Title(val string) *NullableSchema[T] {- s.title = val- return s-}--func (s *NullableSchema[T]) Description(val string) *NullableSchema[T] {- s.description = val- return s-}--func (s *NullableSchema[T]) Deprecated() *NullableSchema[T] {- s.deprecated = true- return s-}--func (s *NullableSchema[T]) Example(val any) *NullableSchema[T] {- s.example = val- return s-}--func (s *NullableSchema[T]) IsRequired() bool {- return s.required-}--func (s *NullableSchema[T]) GetSource() ParamSource {- return s.inner.GetSource()-}--// IsPresent returns true if a non-null value was provided-func (s *NullableSchema[T]) IsPresent() bool {- return s.ptr != nil && s.ptr.Present && !s.ptr.Null-}--// IsNull returns true if the field was explicitly set to null-func (s *NullableSchema[T]) IsNull() bool {- return s.ptr != nil && s.ptr.Present && s.ptr.Null-}--// IsAbsent returns true if the field was not present in the JSON-func (s *NullableSchema[T]) IsAbsent() bool {- return s.ptr == nil || !s.ptr.Present-}--func (s *NullableSchema[T]) Validate() []ValidationError {- if s.ptr == nil || !s.ptr.Present {- // Field absent- if s.required {- return []ValidationError{{Code: "required", Message: "is required"}}- }- return nil- }-- if s.ptr.Null {- // Explicitly null- if s.required {- return []ValidationError{{Code: "required", Message: "cannot be null"}}- }- return nil- }-- // Present with value - validate inner schema (skip its required check)- return s.inner.Validate()-}--func (s *NullableSchema[T]) OpenAPI() map[string]any {- schema := s.inner.OpenAPI()- schema["nullable"] = true-- if s.title != "" {- schema["title"] = s.title- }- if s.description != "" {- schema["description"] = s.description- }- if s.deprecated {- schema["deprecated"] = true- }- if s.example != nil {- schema["example"] = s.example- }-- return schema-}diff --git a/backend-go/pkg/chita/nullable_test.go b/backend-go/pkg/chita/nullable_test.godeleted file mode 100644index 17b1e96d94..0000000000--- a/backend-go/pkg/chita/nullable_test.go+++ /dev/null@@ -1,284 +0,0 @@-package chita--import (- "encoding/json"- "testing"-- "github.com/stretchr/testify/assert"- "github.com/stretchr/testify/require"-)--func TestJsonNullable_UnmarshalJSON_Value(t *testing.T) {- type Request struct {- Name JsonNullable[string] `json:"name"`- }-- data := []byte(`{"name": "John"}`)- var req Request- err := json.Unmarshal(data, &req)- require.NoError(t, err)-- assert.True(t, req.Name.Present)- assert.False(t, req.Name.Null)- assert.Equal(t, "John", req.Name.Value)- assert.True(t, req.Name.IsSet())-}--func TestJsonNullable_UnmarshalJSON_Null(t *testing.T) {- type Request struct {- Name JsonNullable[string] `json:"name"`- }-- data := []byte(`{"name": null}`)- var req Request- err := json.Unmarshal(data, &req)- require.NoError(t, err)-- assert.True(t, req.Name.Present)- assert.True(t, req.Name.Null)- assert.Equal(t, "", req.Name.Value) // zero value- assert.False(t, req.Name.IsSet())-}--func TestJsonNullable_UnmarshalJSON_Absent(t *testing.T) {- type Request struct {- Name JsonNullable[string] `json:"name"`- }-- data := []byte(`{}`)- var req Request- err := json.Unmarshal(data, &req)- require.NoError(t, err)-- assert.False(t, req.Name.Present)- assert.False(t, req.Name.Null)- assert.Equal(t, "", req.Name.Value)- assert.False(t, req.Name.IsSet())-}--func TestJsonNullable_UnmarshalJSON_ComplexType(t *testing.T) {- type Address struct {- Street string `json:"street"`- City string `json:"city"`- }-- type Request struct {- Address JsonNullable[Address] `json:"address"`- }-- data := []byte(`{"address": {"street": "123 Main St", "city": "NYC"}}`)- var req Request- err := json.Unmarshal(data, &req)- require.NoError(t, err)-- assert.True(t, req.Address.Present)- assert.False(t, req.Address.Null)- assert.Equal(t, "123 Main St", req.Address.Value.Street)- assert.Equal(t, "NYC", req.Address.Value.City)-}--func TestJsonNullable_MarshalJSON_Value(t *testing.T) {- val := Set("hello")- data, err := json.Marshal(val)- require.NoError(t, err)- assert.Equal(t, `"hello"`, string(data))-}--func TestJsonNullable_MarshalJSON_Null(t *testing.T) {- val := Null[string]()- data, err := json.Marshal(val)- require.NoError(t, err)- assert.Equal(t, `null`, string(data))-}--func TestJsonNullable_MarshalJSON_Absent(t *testing.T) {- val := Absent[string]()- data, err := json.Marshal(val)- require.NoError(t, err)- assert.Equal(t, `null`, string(data)) // absent marshals as null-}--func TestJsonNullable_Ptr_Set(t *testing.T) {- val := Set(42)- ptr := val.Ptr()- require.NotNil(t, ptr)- assert.Equal(t, 42, *ptr)-}--func TestJsonNullable_Ptr_Null(t *testing.T) {- val := Null[int]()- ptr := val.Ptr()- assert.Nil(t, ptr)-}--func TestJsonNullable_Ptr_Absent(t *testing.T) {- val := Absent[int]()- ptr := val.Ptr()- assert.Nil(t, ptr)-}--func TestJsonNullable_WithSchema(t *testing.T) {- type Request struct {- Count JsonNullable[int] `json:"count"`- }-- t.Run("value provided", func(t *testing.T) {- data := []byte(`{"count": 0}`) // 0 is a valid value- var req Request- err := json.Unmarshal(data, &req)- require.NoError(t, err)-- // Use Ptr() to get pointer for schema- schema := Int(req.Count.Ptr()).Required()- errs := schema.Validate()- assert.Empty(t, errs) // 0 is valid- })-- t.Run("value absent", func(t *testing.T) {- data := []byte(`{}`)- var req Request- err := json.Unmarshal(data, &req)- require.NoError(t, err)-- // Ptr() returns nil for absent- schema := Int(req.Count.Ptr()).Required()- errs := schema.Validate()- require.Len(t, errs, 1)- assert.Equal(t, "required", errs[0].Code)- })-- t.Run("value null", func(t *testing.T) {- data := []byte(`{"count": null}`)- var req Request- err := json.Unmarshal(data, &req)- require.NoError(t, err)-- // Ptr() returns nil for null- schema := Int(req.Count.Ptr()).Required()- errs := schema.Validate()- require.Len(t, errs, 1)- assert.Equal(t, "required", errs[0].Code)- })-}--func TestNullableSchema_TriState(t *testing.T) {- type UpdateRequest struct {- Name JsonNullable[string] `json:"name"`- }-- t.Run("value present - valid", func(t *testing.T) {- data := []byte(`{"name": "John"}`)- var req UpdateRequest- require.NoError(t, json.Unmarshal(data, &req))-- schema := Nullable(&req.Name, String(&req.Name.Value).MinLength(1)).Required()- errs := schema.Validate()- assert.Empty(t, errs)- assert.True(t, schema.IsPresent())- assert.False(t, schema.IsNull())- assert.False(t, schema.IsAbsent())- })-- t.Run("value present - invalid pattern", func(t *testing.T) {- data := []byte(`{"name": "invalid-email"}`)- var req UpdateRequest- require.NoError(t, json.Unmarshal(data, &req))-- schema := Nullable(&req.Name, String(&req.Name.Value).Email()).Required()- errs := schema.Validate()- require.Len(t, errs, 1)- assert.Equal(t, "format", errs[0].Code)- })-- t.Run("value null - required fails", func(t *testing.T) {- data := []byte(`{"name": null}`)- var req UpdateRequest- require.NoError(t, json.Unmarshal(data, &req))-- schema := Nullable(&req.Name, String(&req.Name.Value)).Required()- errs := schema.Validate()- require.Len(t, errs, 1)- assert.Equal(t, "required", errs[0].Code)- assert.Contains(t, errs[0].Message, "null")- assert.False(t, schema.IsPresent())- assert.True(t, schema.IsNull())- })-- t.Run("value null - optional ok", func(t *testing.T) {- data := []byte(`{"name": null}`)- var req UpdateRequest- require.NoError(t, json.Unmarshal(data, &req))-- schema := Nullable(&req.Name, String(&req.Name.Value)).Optional()- errs := schema.Validate()- assert.Empty(t, errs)- assert.True(t, schema.IsNull())- })-- t.Run("value absent - required fails", func(t *testing.T) {- data := []byte(`{}`)- var req UpdateRequest- require.NoError(t, json.Unmarshal(data, &req))-- schema := Nullable(&req.Name, String(&req.Name.Value)).Required()- errs := schema.Validate()- require.Len(t, errs, 1)- assert.Equal(t, "required", errs[0].Code)- assert.True(t, schema.IsAbsent())- })-- t.Run("value absent - optional ok", func(t *testing.T) {- data := []byte(`{}`)- var req UpdateRequest- require.NoError(t, json.Unmarshal(data, &req))-- schema := Nullable(&req.Name, String(&req.Name.Value)).Optional()- errs := schema.Validate()- assert.Empty(t, errs)- assert.True(t, schema.IsAbsent())- })-}--func TestNullableSchema_OpenAPI(t *testing.T) {- var name JsonNullable[string]- schema := Nullable(&name, String(&name.Value).MinLength(1).MaxLength(100)).- Description("User name").- Example("John")-- openapi := schema.OpenAPI()-- assert.Equal(t, "string", openapi["type"])- assert.Equal(t, true, openapi["nullable"])- assert.Equal(t, 1, openapi["minLength"])- assert.Equal(t, 100, openapi["maxLength"])- assert.Equal(t, "User name", openapi["description"])- assert.Equal(t, "John", openapi["example"])-}--func TestNullableSchema_IntType(t *testing.T) {- type Request struct {- Count JsonNullable[int] `json:"count"`- }-- t.Run("zero is valid value", func(t *testing.T) {- data := []byte(`{"count": 0}`)- var req Request- require.NoError(t, json.Unmarshal(data, &req))-- schema := Nullable(&req.Count, Int(&req.Count.Value).Min(0)).Required()- errs := schema.Validate()- assert.Empty(t, errs)- assert.True(t, schema.IsPresent())- })-- t.Run("negative fails min", func(t *testing.T) {- data := []byte(`{"count": -5}`)- var req Request- require.NoError(t, json.Unmarshal(data, &req))-- schema := Nullable(&req.Count, Int(&req.Count.Value).Min(0)).Required()- errs := schema.Validate()- require.Len(t, errs, 1)- assert.Equal(t, "minimum", errs[0].Code)- })-}diff --git a/backend-go/pkg/chita/oneof_anyof_test.go b/backend-go/pkg/chita/oneof_anyof_test.goindex e8542654b8..80382fa334 100644--- a/backend-go/pkg/chita/oneof_anyof_test.go+++ b/backend-go/pkg/chita/oneof_anyof_test.go@@ -10,12 +10,12 @@ import (// --- OneOfSchemas Validation Tests ---func TestOneOfSchemas_Validate_NonePresent_Required(t *testing.T) {- strVal := ""- var intPtr *int+ var strVal Required[string]+ var intVal Required[int]schema := OneOfSchemas(- String(&strVal),- Int(intPtr),+ Str(&strVal),+ Int(&intVal),).Required()errs := schema.Validate()@@ -25,12 +25,12 @@ func TestOneOfSchemas_Validate_NonePresent_Required(t *testing.T) {}func TestOneOfSchemas_Validate_NonePresent_Optional(t *testing.T) {- strVal := ""- var intPtr *int+ var strVal Required[string]+ var intVal Required[int]schema := OneOfSchemas(- String(&strVal),- Int(intPtr),+ Str(&strVal),+ Int(&intVal),).Optional()errs := schema.Validate()@@ -38,12 +38,12 @@ func TestOneOfSchemas_Validate_NonePresent_Optional(t *testing.T) {}func TestOneOfSchemas_Validate_OnePresent(t *testing.T) {- strVal := "hello"- var intPtr *int+ strVal := NewRequired("hello")+ var intVal Required[int]schema := OneOfSchemas(- String(&strVal).MinLength(1),- Int(intPtr),+ Str(&strVal).MinLength(1),+ Int(&intVal),).Required()errs := schema.Validate()@@ -51,11 +51,11 @@ func TestOneOfSchemas_Validate_OnePresent(t *testing.T) {}func TestOneOfSchemas_Validate_MultiplePresent(t *testing.T) {- strVal := "hello"- intVal := 42+ strVal := NewRequired("hello")+ intVal := NewRequired(42)schema := OneOfSchemas(- String(&strVal),+ Str(&strVal),Int(&intVal),).Required()@@ -66,10 +66,10 @@ func TestOneOfSchemas_Validate_MultiplePresent(t *testing.T) {}func TestOneOfSchemas_Validate_PresentButInvalid(t *testing.T) {- strVal := "hi" // Too short for minLength(5)+ strVal := NewRequired("hi") // Too short for minLength(5)schema := OneOfSchemas(- String(&strVal).MinLength(5),+ Str(&strVal).MinLength(5),).Required()errs := schema.Validate()@@ -78,33 +78,32 @@ func TestOneOfSchemas_Validate_PresentButInvalid(t *testing.T) {}func TestOneOfSchemas_Validate_WithObjects(t *testing.T) {- // Simulate: either plaintext OR referencetype SecretReference struct {- SecretID string- Version int+ SecretID Required[string]+ Version Required[int]}- plaintext := ""- ref := SecretReference{SecretID: "abc-123", Version: 1}+ var plaintext Required[string]+ ref := SecretReference{SecretID: NewRequired("abc-123"), Version: NewRequired(1)}schema := OneOfSchemas(- String(&plaintext).Description("Raw value"),+ Str(&plaintext).Description("Raw value"),Object(map[string]Schema{- "secretId": String(&ref.SecretID).Required(),- "version": Int(&ref.Version).Required(),+ "secretId": Str(&ref.SecretID),+ "version": Int(&ref.Version),}).Description("Reference"),).Required()errs := schema.Validate()- assert.Empty(t, errs) // Object is present (secretId is non-empty)+ assert.Empty(t, errs) // Object is present (secretId is set)}func TestOneOfSchemas_OpenAPI(t *testing.T) {- strVal := ""- intVal := 0+ var strVal Required[string]+ var intVal Required[int]schema := OneOfSchemas(- String(&strVal).Description("String option"),+ Str(&strVal).Description("String option"),Int(&intVal).Description("Int option"),).Title("FlexValue").Description("Either string or int")@@ -117,7 +116,6 @@ func TestOneOfSchemas_OpenAPI(t *testing.T) {assert.Equal(t, "FlexValue", openapi["title"])assert.Equal(t, "Either string or int", openapi["description"])- // Should NOT have discriminator for simple oneOf_, hasDiscriminator := openapi["discriminator"]assert.False(t, hasDiscriminator)}@@ -125,12 +123,12 @@ func TestOneOfSchemas_OpenAPI(t *testing.T) {// --- AnyOf Validation Tests ---func TestAnyOf_Validate_NonePresent_Required(t *testing.T) {- email := ""- slack := ""+ var email Required[string]+ var slack Required[string]schema := AnyOf(- String(&email),- String(&slack),+ Str(&email),+ Str(&slack),).Required()errs := schema.Validate()@@ -140,12 +138,12 @@ func TestAnyOf_Validate_NonePresent_Required(t *testing.T) {}func TestAnyOf_Validate_NonePresent_Optional(t *testing.T) {- email := ""- slack := ""+ var email Required[string]+ var slack Required[string]schema := AnyOf(- String(&email),- String(&slack),+ Str(&email),+ Str(&slack),).Optional()errs := schema.Validate()@@ -153,12 +151,12 @@ func TestAnyOf_Validate_NonePresent_Optional(t *testing.T) {}func TestAnyOf_Validate_OnePresent(t *testing.T) {- email := "[email protected]"- slack := ""+ email := NewRequired("[email protected]")+ var slack Required[string]schema := AnyOf(- String(&email).Email(),- String(&slack),+ Str(&email).Email(),+ Str(&slack),).Required()errs := schema.Validate()@@ -166,12 +164,12 @@ func TestAnyOf_Validate_OnePresent(t *testing.T) {}func TestAnyOf_Validate_MultiplePresent(t *testing.T) {- email := "[email protected]"- slack := "#channel"+ email := NewRequired("[email protected]")+ slack := NewRequired("#channel")schema := AnyOf(- String(&email).Email(),- String(&slack).MinLength(1),+ Str(&email).Email(),+ Str(&slack).MinLength(1),).Required()errs := schema.Validate()@@ -179,12 +177,12 @@ func TestAnyOf_Validate_MultiplePresent(t *testing.T) {}func TestAnyOf_Validate_MultiplePresent_OneInvalid(t *testing.T) {- email := "invalid-email" // Invalid email format- slack := "#channel"+ email := NewRequired("invalid-email") // Invalid email format+ slack := NewRequired("#channel")schema := AnyOf(- String(&email).Email(),- String(&slack).MinLength(1),+ Str(&email).Email(),+ Str(&slack).MinLength(1),).Required()errs := schema.Validate()@@ -194,44 +192,37 @@ func TestAnyOf_Validate_MultiplePresent_OneInvalid(t *testing.T) {func TestAnyOf_Validate_WithObjects(t *testing.T) {type EmailConfig struct {- To string- Subject string+ To Required[string]+ Subject Required[string]}type SlackConfig struct {- Channel string+ Channel Required[string]}- email := EmailConfig{To: "[email protected]", Subject: "Alert"}- slack := SlackConfig{} // Empty+ email := EmailConfig{To: NewRequired("[email protected]"), Subject: NewRequired("Alert")}+ var slack SlackConfig // Emptyschema := AnyOf(Object(map[string]Schema{- "to": String(&email.To).Required().Email(),- "subject": String(&email.Subject).Required(),+ "to": Str(&email.To).Email(),+ "subject": Str(&email.Subject),}),Object(map[string]Schema{- "channel": String(&slack.Channel).Required(),+ "channel": Str(&slack.Channel),}),).Required()errs := schema.Validate()- // Email object is present (to is non-empty)- // Slack object validation will have errors but email is valid- // Actually, let me think about this...- // Both objects are validated if present- // Email is present (to is non-empty)- // Slack is NOT present (channel is empty)- // So only email is validatedassert.Empty(t, errs)}func TestAnyOf_OpenAPI(t *testing.T) {- email := ""- slack := ""+ var email Required[string]+ var slack Required[string]schema := AnyOf(- String(&email).Description("Email config"),- String(&slack).Description("Slack config"),+ Str(&email).Description("Email config"),+ Str(&slack).Description("Slack config"),).Title("NotificationConfig").Description("At least one channel")openapi := schema.OpenAPI()@@ -244,18 +235,18 @@ func TestAnyOf_OpenAPI(t *testing.T) {assert.Equal(t, "At least one channel", openapi["description"])}-// --- AllOf Validation Tests (unchanged, but verify) ---+// --- AllOf Validation Tests ---func TestAllOf_Validate_AllValid(t *testing.T) {- name := "John"- age := 25+ name := NewRequired("John")+ age := NewRequired(25)schema := AllOf(Object(map[string]Schema{- "name": String(&name).Required().MinLength(1),+ "name": Str(&name).MinLength(1),}),Object(map[string]Schema{- "age": Int(&age).Required().Min(0),+ "age": Int(&age).Min(0),}),)@@ -264,15 +255,15 @@ func TestAllOf_Validate_AllValid(t *testing.T) {}func TestAllOf_Validate_OneInvalid(t *testing.T) {- name := "" // Invalid - required- age := 25+ var name Required[string] // Not set - invalid+ age := NewRequired(25)schema := AllOf(Object(map[string]Schema{- "name": String(&name).Required().MinLength(1),+ "name": Str(&name).MinLength(1),}),Object(map[string]Schema{- "age": Int(&age).Required().Min(0),+ "age": Int(&age).Min(0),}),)@@ -282,15 +273,15 @@ func TestAllOf_Validate_OneInvalid(t *testing.T) {}func TestAllOf_Validate_MultipleInvalid(t *testing.T) {- name := "" // Invalid- age := -10 // Invalid - min 0+ var name Required[string] // Not set+ age := NewRequired(-10) // Invalid - min 0schema := AllOf(Object(map[string]Schema{- "name": String(&name).Required().MinLength(1),+ "name": Str(&name).MinLength(1),}),Object(map[string]Schema{- "age": Int(&age).Required().Min(0),+ "age": Int(&age).Min(0),}),)@@ -300,23 +291,12 @@ func TestAllOf_Validate_MultipleInvalid(t *testing.T) {// --- Real-world Use Case Tests ----func TestOneOf_SecretValue_UsCase(t *testing.T) {- // Use case: Secret value can be plaintext OR reference, not both- type SecretValue struct {- Plaintext *string- Reference *struct {- SecretID string- Version int- }- }-+func TestOneOf_SecretValue_UseCase(t *testing.T) {t.Run("plaintext provided", func(t *testing.T) {- plaintext := "my-secret-value"- sv := SecretValue{Plaintext: &plaintext}+ plaintext := NewRequired("my-secret-value")schema := OneOfSchemas(- String(sv.Plaintext),- // Reference would be nil, so its object properties wouldn't be present+ Str(&plaintext),).Required()errs := schema.Validate()@@ -324,9 +304,10 @@ func TestOneOf_SecretValue_UsCase(t *testing.T) {})t.Run("neither provided", func(t *testing.T) {- var plaintext string+ var plaintext Required[string]+schema := OneOfSchemas(- String(&plaintext), // Empty string+ Str(&plaintext),).Required()errs := schema.Validate()@@ -336,21 +317,15 @@ func TestOneOf_SecretValue_UsCase(t *testing.T) {}func TestAnyOf_NotificationConfig_UseCase(t *testing.T) {- // Use case: Notification config - at least one channel required- type NotificationConfig struct {- Email *string- Slack *string- Webhook *string- }-t.Run("one channel configured", func(t *testing.T) {- email := "[email protected]"- nc := NotificationConfig{Email: &email}+ email := NewRequired("[email protected]")+ var slack Required[string]+ var webhook Required[string]schema := AnyOf(- String(nc.Email).Email(),- String(nc.Slack),- String(nc.Webhook),+ Str(&email).Email(),+ Str(&slack),+ Str(&webhook),).Required()errs := schema.Validate()@@ -358,27 +333,29 @@ func TestAnyOf_NotificationConfig_UseCase(t *testing.T) {})t.Run("multiple channels configured", func(t *testing.T) {- email := "[email protected]"- slack := "#alerts"- nc := NotificationConfig{Email: &email, Slack: &slack}+ email := NewRequired("[email protected]")+ slack := NewRequired("#alerts")+ var webhook Required[string]schema := AnyOf(- String(nc.Email).Email(),- String(nc.Slack).MinLength(1),- String(nc.Webhook),+ Str(&email).Email(),+ Str(&slack).MinLength(1),+ Str(&webhook),).Required()errs := schema.Validate()- assert.Empty(t, errs) // Both present and valid is OK+ assert.Empty(t, errs)})t.Run("no channels configured", func(t *testing.T) {- nc := NotificationConfig{}+ var email Required[string]+ var slack Required[string]+ var webhook Required[string]schema := AnyOf(- String(nc.Email),- String(nc.Slack),- String(nc.Webhook),+ Str(&email),+ Str(&slack),+ Str(&webhook),).Required()errs := schema.Validate()diff --git a/backend-go/pkg/chita/openapi_test.go b/backend-go/pkg/chita/openapi_test.goindex 2ef0738d1b..60f7a5e1c1 100644--- a/backend-go/pkg/chita/openapi_test.go+++ b/backend-go/pkg/chita/openapi_test.go@@ -15,40 +15,40 @@ import (// =============================================================================type CreateUserRequest struct {- Name string- Email string+ Name Required[string]+ Email Required[string]}func (r *CreateUserRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "name": String(&r.Name).Required().MinLength(1).MaxLength(100),- "email": String(&r.Email).Required().Email(),+ "name": Str(&r.Name).MinLength(1).MaxLength(100),+ "email": Str(&r.Email).Email(),}).Title("CreateUserRequest")}type UserResponse struct {- ID string- Name string- Email string+ ID Required[string]+ Name Required[string]+ Email Required[string]}func (r *UserResponse) Schema() *ObjectSchema {return Object(map[string]Schema{- "id": String(&r.ID).Required().UUID(),- "name": String(&r.Name).Required(),- "email": String(&r.Email).Required().Email(),+ "id": Str(&r.ID).UUID(),+ "name": Str(&r.Name),+ "email": Str(&r.Email).Email(),}).Title("UserResponse")}type ErrorResponse struct {- Code string- Message string+ Code Required[string]+ Message Required[string]}func (r *ErrorResponse) Schema() *ObjectSchema {return Object(map[string]Schema{- "code": String(&r.Code).Required(),- "message": String(&r.Message).Required(),+ "code": Str(&r.Code),+ "message": Str(&r.Message),}).Title("ErrorResponse")}@@ -546,10 +546,10 @@ func TestOpenAPI_DefaultResponseDescriptions(t *testing.T) {func TestObjectSchema_Ref(t *testing.T) {DefaultRegistry.Clear()- var name, email string+ var name, email Required[string]userSchema := Object(map[string]Schema{- "name": String(&name).Required(),- "email": String(&email).Email(),+ "name": Str(&name),+ "email": Str(&email).Email(),}).Title("User").Ref("User")openAPI := userSchema.OpenAPI()@@ -568,10 +568,10 @@ func TestObjectSchema_Ref(t *testing.T) {func TestObjectSchema_Ref_InOpenAPISpec(t *testing.T) {DefaultRegistry.Clear()- var errorCode, errorMsg string+ var errorCode, errorMsg Required[string]errorSchema := Object(map[string]Schema{- "code": String(&errorCode).Required(),- "message": String(&errorMsg).Required(),+ "code": Str(&errorCode),+ "message": Str(&errorMsg),}).Title("Error").Ref("Error")result := generate(t, minimalConfig(), Endpoint{@@ -598,8 +598,7 @@ func TestObjectSchema_Ref_InOpenAPISpec(t *testing.T) {func TestArraySchema_Ref(t *testing.T) {DefaultRegistry.Clear()- var item string- tagsSchema := Array(String(&item)).MinItems(1).Ref("Tags")+ tagsSchema := Array(StringElem(nil)).MinItems(1).Ref("Tags")openAPI := tagsSchema.OpenAPI()assert.Equal(t, "#/components/schemas/Tags", openAPI["$ref"])diff --git a/backend-go/pkg/chita/request.go b/backend-go/pkg/chita/request.goindex 3e70fdf1b2..3e2050091a 100644--- a/backend-go/pkg/chita/request.go+++ b/backend-go/pkg/chita/request.go@@ -110,48 +110,35 @@ func setFieldValue(schema Schema, value string) error {switch s := schema.(type) {case *StringSchema:- if s.ptr != nil {- *s.ptr = value- }+ s.Set(value)case *IntSchema:i, err := strconv.ParseInt(value, 10, 64)if err != nil {return fmt.Errorf("invalid integer: %w", err)}- if s.ptr != nil {- *s.ptr = int(i)- }- if s.ptr64 != nil {- *s.ptr64 = i- }+ s.SetInt64(i)case *FloatSchema:f, err := strconv.ParseFloat(value, 64)if err != nil {return fmt.Errorf("invalid float: %w", err)}- if s.ptr != nil {- *s.ptr = f- }+ s.Set(f)case *BoolSchema:b, err := strconv.ParseBool(value)if err != nil {return fmt.Errorf("invalid boolean: %w", err)}- if s.ptr != nil {- *s.ptr = b- }+ s.Set(b)case *UUIDSchema:u, err := uuid.Parse(value)if err != nil {return fmt.Errorf("invalid UUID: %w", err)}- if s.ptr != nil {- *s.ptr = u- }+ s.Set(u)case *TimeSchema:var t time.Time@@ -167,9 +154,7 @@ func setFieldValue(schema Schema, value string) error {if err != nil {return fmt.Errorf("invalid time: %w", err)}- if s.ptr != nil {- *s.ptr = t- }+ s.Set(t)default:return fmt.Errorf("unsupported schema type for parameter: %T", schema)@@ -472,33 +457,25 @@ func ParseQueryArrayCSV(r *http.Request, name string) []string {}// applyDefaults applies default values to schema fields that weren't set.-// For non-body fields (query, path, etc.), if the value is zero and a default exists, apply it.+// For non-body fields (query, path, etc.), if the value wasn't explicitly set and a default exists, apply it.func applyDefaults(schema *ObjectSchema) {for _, fieldSchema := range schema.properties {switch s := fieldSchema.(type) {case *IntSchema:- if s.defaultVal != nil && s.source != SourceBody {- val, _ := s.value()- if val == 0 {- if s.ptr != nil {- *s.ptr = int(*s.defaultVal)- }- if s.ptr64 != nil {- *s.ptr64 = *s.defaultVal- }- }+ if s.defaultVal != nil && s.source != SourceBody && !s.IsSet() {+ s.SetInt64(*s.defaultVal)}case *StringSchema:- if s.defaultVal != nil && s.source != SourceBody && s.ptr != nil && *s.ptr == "" {- *s.ptr = *s.defaultVal+ if s.defaultVal != nil && s.source != SourceBody && !s.IsSet() {+ s.Set(*s.defaultVal)}case *BoolSchema:- if s.defaultVal != nil && s.source != SourceBody && s.ptr != nil && !*s.ptr {- *s.ptr = *s.defaultVal+ if s.defaultVal != nil && s.source != SourceBody && !s.IsSet() {+ s.Set(*s.defaultVal)}case *FloatSchema:- if s.defaultVal != nil && s.source != SourceBody && s.ptr != nil && *s.ptr == 0 {- *s.ptr = *s.defaultVal+ if s.defaultVal != nil && s.source != SourceBody && !s.IsSet() {+ s.Set(*s.defaultVal)}}}diff --git a/backend-go/pkg/chita/request_test.go b/backend-go/pkg/chita/request_test.goindex 9a5f16ac30..06adab3153 100644--- a/backend-go/pkg/chita/request_test.go+++ b/backend-go/pkg/chita/request_test.go@@ -15,18 +15,18 @@ import ()type ParseTestRequest struct {- OrgID string `json:"-"`- Include string `json:"-"`- Name string `json:"name"`- Age int `json:"age"`+ OrgID Required[string] `json:"-"`+ Include Optional[string] `json:"-"`+ Name Required[string] `json:"name"`+ Age Optional[int] `json:"age"`}func (r *ParseTestRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "orgId": String(&r.OrgID).Required().From(SourcePath),- "include": String(&r.Include).Optional().From(SourceQuery),- "name": String(&r.Name).Required(),- "age": Int(&r.Age).Optional(),+ "orgId": Str(&r.OrgID).From(SourcePath),+ "include": OptStr(&r.Include).From(SourceQuery),+ "name": Str(&r.Name),+ "age": OptInt(&r.Age),})}@@ -39,17 +39,17 @@ func TestParseRequest_PathAndQuery(t *testing.T) {return}- if req.OrgID != "org-123" {- t.Errorf("expected OrgID 'org-123', got %q", req.OrgID)+ if req.OrgID.Get() != "org-123" {+ t.Errorf("expected OrgID 'org-123', got %q", req.OrgID.Get())}- if req.Include != "metadata" {- t.Errorf("expected Include 'metadata', got %q", req.Include)+ if req.Include.Get() != "metadata" {+ t.Errorf("expected Include 'metadata', got %q", req.Include.Get())}- if req.Name != "John" {- t.Errorf("expected Name 'John', got %q", req.Name)+ if req.Name.Get() != "John" {+ t.Errorf("expected Name 'John', got %q", req.Name.Get())}- if req.Age != 30 {- t.Errorf("expected Age 30, got %d", req.Age)+ if req.Age.Get() != 30 {+ t.Errorf("expected Age 30, got %d", req.Age.Get())}}@@ -139,13 +139,14 @@ func TestExtractPathParams(t *testing.T) {}func TestSplitSchemaBySource(t *testing.T) {- var name, orgID, include, token string+ var name, orgID, token Required[string]+ var include Optional[string]schema := Object(map[string]Schema{- "name": String(&name).Required(),- "orgId": String(&orgID).Required().From(SourcePath),- "include": String(&include).Optional().From(SourceQuery),- "token": String(&token).Required().From(SourceHeader),+ "name": Str(&name),+ "orgId": Str(&orgID).From(SourcePath),+ "include": OptStr(&include).From(SourceQuery),+ "token": Str(&token).From(SourceHeader),})bodySchema, params := SplitSchemaBySource(schema)@@ -172,14 +173,15 @@ func TestSplitSchemaBySource(t *testing.T) {}func TestBuildOpenAPIParameters(t *testing.T) {- var name, orgID, include string- var limit int+ var name, orgID Required[string]+ var include Optional[string]+ var limit Optional[int]schema := Object(map[string]Schema{- "name": String(&name).Required(),- "orgId": String(&orgID).Required().From(SourcePath).Description("Organization ID"),- "include": String(&include).Optional().From(SourceQuery).Description("Fields to include"),- "limit": Int(&limit).Optional().From(SourceQuery),+ "name": Str(&name),+ "orgId": Str(&orgID).From(SourcePath).Description("Organization ID"),+ "include": OptStr(&include).From(SourceQuery).Description("Fields to include"),+ "limit": OptInt(&limit).From(SourceQuery),})params := BuildOpenAPIParameters(schema)@@ -214,11 +216,11 @@ func TestBuildOpenAPIParameters(t *testing.T) {}func TestBuildOpenAPIRequestBody(t *testing.T) {- var name, orgID string+ var name, orgID Required[string]schema := Object(map[string]Schema{- "name": String(&name).Required(),- "orgId": String(&orgID).Required().From(SourcePath),+ "name": Str(&name),+ "orgId": Str(&orgID).From(SourcePath),})body := BuildOpenAPIRequestBody(schema, "")@@ -266,16 +268,16 @@ func TestParamSourceString(t *testing.T) {}type HeaderCookieRequest struct {- AuthToken string `json:"-"`- SessionID string `json:"-"`- RequestBody string `json:"body"`+ AuthToken Required[string] `json:"-"`+ SessionID Optional[string] `json:"-"`+ RequestBody Required[string] `json:"body"`}func (r *HeaderCookieRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "Authorization": String(&r.AuthToken).Required().From(SourceHeader),- "session_id": String(&r.SessionID).Optional().From(SourceCookie),- "body": String(&r.RequestBody).Required(),+ "Authorization": Str(&r.AuthToken).From(SourceHeader),+ "session_id": OptStr(&r.SessionID).From(SourceCookie),+ "body": Str(&r.RequestBody),})}@@ -288,14 +290,14 @@ func TestParseRequest_HeaderAndCookie(t *testing.T) {return}- if req.AuthToken != "Bearer token123" {- t.Errorf("expected AuthToken 'Bearer token123', got %q", req.AuthToken)+ if req.AuthToken.Get() != "Bearer token123" {+ t.Errorf("expected AuthToken 'Bearer token123', got %q", req.AuthToken.Get())}- if req.SessionID != "sess-abc" {- t.Errorf("expected SessionID 'sess-abc', got %q", req.SessionID)+ if req.SessionID.Get() != "sess-abc" {+ t.Errorf("expected SessionID 'sess-abc', got %q", req.SessionID.Get())}- if req.RequestBody != "hello" {- t.Errorf("expected RequestBody 'hello', got %q", req.RequestBody)+ if req.RequestBody.Get() != "hello" {+ t.Errorf("expected RequestBody 'hello', got %q", req.RequestBody.Get())}}@@ -317,38 +319,38 @@ func TestParseRequest_HeaderAndCookie(t *testing.T) {}func TestSetFieldValue_Int(t *testing.T) {- var val int+ var val Required[int]schema := Int(&val)if err := setFieldValue(schema, "42"); err != nil {t.Fatalf("setFieldValue failed: %v", err)}- if val != 42 {- t.Errorf("expected 42, got %d", val)+ if val.Get() != 42 {+ t.Errorf("expected 42, got %d", val.Get())}}func TestSetFieldValue_Bool(t *testing.T) {- var val bool+ var val Required[bool]schema := Bool(&val)if err := setFieldValue(schema, "true"); err != nil {t.Fatalf("setFieldValue failed: %v", err)}- if !val {+ if !val.Get() {t.Error("expected true, got false")}}func TestSetFieldValue_Float(t *testing.T) {- var val float64+ var val Required[float64]schema := Float(&val)if err := setFieldValue(schema, "3.14"); err != nil {t.Fatalf("setFieldValue failed: %v", err)}- if val != 3.14 {- t.Errorf("expected 3.14, got %f", val)+ if val.Get() != 3.14 {+ t.Errorf("expected 3.14, got %f", val.Get())}}@@ -366,7 +368,7 @@ func TestSetFieldValue_UUID(t *testing.T) {}func TestSetFieldValue_InvalidInt(t *testing.T) {- var val int+ var val Required[int]schema := Int(&val)if err := setFieldValue(schema, "not-a-number"); err == nil {@@ -409,13 +411,13 @@ func TestParseQueryArrayCSV(t *testing.T) {func TestParseRequest_NoBody(t *testing.T) {type GetRequest struct {- ID string `json:"-"`+ ID Required[string] `json:"-"`}handler := func(w http.ResponseWriter, r *http.Request) {var req GetRequestschema := Object(map[string]Schema{- "id": String(&req.ID).Required().From(SourcePath),+ "id": Str(&req.ID).From(SourcePath),})// Extract path param manually (since GetRequest doesn't implement SchemaProvider)@@ -429,8 +431,8 @@ func TestParseRequest_NoBody(t *testing.T) {}}- if req.ID != "item-123" {- t.Errorf("expected ID 'item-123', got %q", req.ID)+ if req.ID.Get() != "item-123" {+ t.Errorf("expected ID 'item-123', got %q", req.ID.Get())}}@@ -449,20 +451,20 @@ func TestParseRequest_NoBody(t *testing.T) {func TestParseRequest_EmptyBody_RequiredFieldValidation(t *testing.T) {type RequestWithRequiredBody struct {- ID string `json:"-"`- Name string `json:"name"`+ ID Required[string] `json:"-"`+ Name Required[string] `json:"name"`}var failed boolhandler := func(w http.ResponseWriter, r *http.Request) {var req RequestWithRequiredBodyschema := Object(map[string]Schema{- "id": String(&req.ID).Required().From(SourcePath),- "name": String(&req.Name).Required(),+ "id": Str(&req.ID).From(SourcePath),+ "name": Str(&req.Name),})// Parse path params- req.ID = chi.URLParam(r, "id")+ req.ID.Set(chi.URLParam(r, "id"))// Body is empty (ContentLength == 0), validation should fail for required "name"errs := schema.Validate()@@ -495,8 +497,8 @@ func TestParseRequest_ChunkedTransferEncoding(t *testing.T) {return}- if req.Name != "ChunkedTest" {- t.Errorf("expected Name 'ChunkedTest', got %q", req.Name)+ if req.Name.Get() != "ChunkedTest" {+ t.Errorf("expected Name 'ChunkedTest', got %q", req.Name.Get())}}@@ -518,12 +520,12 @@ func TestParseRequest_ChunkedTransferEncoding(t *testing.T) {}type RequiredHeaderRequest struct {- APIKey string `json:"-"`+ APIKey Required[string] `json:"-"`}func (r *RequiredHeaderRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "X-API-Key": String(&r.APIKey).Required().From(SourceHeader),+ "X-API-Key": Str(&r.APIKey).From(SourceHeader),})}@@ -552,12 +554,12 @@ func TestParseAndValidate_RequiredHeaderMissing(t *testing.T) {}type RequiredCookieRequest struct {- SessionID string `json:"-"`+ SessionID Required[string] `json:"-"`}func (r *RequiredCookieRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "session_id": String(&r.SessionID).Required().From(SourceCookie),+ "session_id": Str(&r.SessionID).From(SourceCookie),})}@@ -593,7 +595,7 @@ func TestParseRequest_UUIDPath_WithSchemaProvider(t *testing.T) {// Helper to create schema - using closure to bind to requestschemaFor := func(req *UUIDPathRequest) *ObjectSchema {return Object(map[string]Schema{- "id": UUID(&req.ID).Required().From(SourcePath),+ "id": UUID(&req.ID).From(SourcePath),})}@@ -663,14 +665,14 @@ func TestParseQueryArrayCSV_SingleValue(t *testing.T) {// --- Mass Assignment Tests ---type MassAssignmentRequest struct {- OrgID string `json:"orgId"` // Intentionally NOT json:"-" to test the vulnerability- Name string `json:"name"`+ OrgID Required[string] `json:"orgId"` // Intentionally NOT json:"-" to test the vulnerability+ Name Required[string] `json:"name"`}func (r *MassAssignmentRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "orgId": String(&r.OrgID).Required().From(SourcePath),- "name": String(&r.Name).Required(),+ "orgId": Str(&r.OrgID).From(SourcePath),+ "name": Str(&r.Name),})}@@ -685,8 +687,8 @@ func TestParseRequest_MassAssignment_PathWinsOverBody(t *testing.T) {// Path parameter should win over body, even with matching JSON tag// This tests the fix for the mass-assignment vulnerability- assert.Equal(t, "legitimate-org", req.OrgID, "path param should override body")- assert.Equal(t, "secret-name", req.Name)+ assert.Equal(t, "legitimate-org", req.OrgID.Get(), "path param should override body")+ assert.Equal(t, "secret-name", req.Name.Get())}router := chi.NewRouter()@@ -706,16 +708,16 @@ func TestParseRequest_MassAssignment_PathWinsOverBody(t *testing.T) {// --- Header/Cookie Parameter Tests ---type HeaderCookieTestRequest struct {- AuthHeader string `json:"-"`- SessionID string `json:"-"`- BodyField string `json:"body"`+ AuthHeader Required[string] `json:"-"`+ SessionID Optional[string] `json:"-"`+ BodyField Required[string] `json:"body"`}func (r *HeaderCookieTestRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "X-Auth-Token": String(&r.AuthHeader).Required().From(SourceHeader),- "session": String(&r.SessionID).Optional().From(SourceCookie),- "body": String(&r.BodyField).Required(),+ "X-Auth-Token": Str(&r.AuthHeader).From(SourceHeader),+ "session": OptStr(&r.SessionID).From(SourceCookie),+ "body": Str(&r.BodyField),})}@@ -727,8 +729,8 @@ func TestParseRequest_HeaderParam(t *testing.T) {return}- assert.Equal(t, "token-value", req.AuthHeader)- assert.Equal(t, "data", req.BodyField)+ assert.Equal(t, "token-value", req.AuthHeader.Get())+ assert.Equal(t, "data", req.BodyField.Get())}router := chi.NewRouter()@@ -753,7 +755,7 @@ func TestParseRequest_CookieParam(t *testing.T) {return}- assert.Equal(t, "sess-123", req.SessionID)+ assert.Equal(t, "sess-123", req.SessionID.Get())}router := chi.NewRouter()@@ -780,7 +782,7 @@ func TestParseRequest_MissingCookie_Tolerated(t *testing.T) {}// Missing optional cookie should be tolerated- assert.Empty(t, req.SessionID)+ assert.False(t, req.SessionID.IsSet())}router := chi.NewRouter()@@ -800,12 +802,12 @@ func TestParseRequest_MissingCookie_Tolerated(t *testing.T) {func TestParseRequest_EmptyBody_SkipsBodyParsing(t *testing.T) {type GetRequest struct {- ID string `json:"-"`+ ID Required[string] `json:"-"`}var req GetRequestschema := Object(map[string]Schema{- "id": String(&req.ID).Required().From(SourcePath),+ "id": Str(&req.ID).From(SourcePath),})// Create request with Content-Length: 0@@ -833,8 +835,8 @@ func TestParseAndValidate_ValidRequest(t *testing.T) {return}- assert.Equal(t, "org-123", req.OrgID)- assert.Equal(t, "John", req.Name)+ assert.Equal(t, "org-123", req.OrgID.Get())+ assert.Equal(t, "John", req.Name.Get())}router := chi.NewRouter()@@ -877,12 +879,12 @@ func TestParseAndValidate_InvalidRequest(t *testing.T) {// --- DisallowUnknownFields Tests ---type strictBodyRequest struct {- Name string `json:"name"`+ Name Required[string] `json:"name"`}func (r *strictBodyRequest) Schema() *ObjectSchema {return Object(map[string]Schema{- "name": String(&r.Name).Required(),+ "name": Str(&r.Name),})}@@ -915,7 +917,7 @@ func TestParseRequestWithOptions_DisallowUnknownFields(t *testing.T) {func TestSetFieldValue_ErrorPaths(t *testing.T) {t.Run("invalid int", func(t *testing.T) {- var val int+ var val Required[int]schema := Int(&val)err := setFieldValue(schema, "not-a-number")require.Error(t, err)@@ -923,7 +925,7 @@ func TestSetFieldValue_ErrorPaths(t *testing.T) {})t.Run("invalid float", func(t *testing.T) {- var val float64+ var val Required[float64]schema := Float(&val)err := setFieldValue(schema, "not-a-float")require.Error(t, err)@@ -931,7 +933,7 @@ func TestSetFieldValue_ErrorPaths(t *testing.T) {})t.Run("invalid bool", func(t *testing.T) {- var val bool+ var val Required[bool]schema := Bool(&val)err := setFieldValue(schema, "not-a-bool")require.Error(t, err)diff --git a/backend-go/pkg/chita/router_test.go b/backend-go/pkg/chita/router_test.goindex 9a0ce9e00b..7482ab8fc7 100644--- a/backend-go/pkg/chita/router_test.go+++ b/backend-go/pkg/chita/router_test.go@@ -24,12 +24,12 @@ func (r *EmptyRequest) Schema() *ObjectSchema {// TestOKResponse is a simple 200 responsetype TestOKResponse struct {- Message string `json:"message"`+ Message Optional[string] `json:"message"`}func (r *TestOKResponse) Schema() *ObjectSchema {return Object(map[string]Schema{- "message": String(&r.Message).Optional(),+ "message": OptStr(&r.Message),})}@@ -37,12 +37,12 @@ func (*TestOKResponse) Status() int { return http.StatusOK }// TestCreatedResponse is a 201 responsetype TestCreatedResponse struct {- ID string `json:"id"`+ ID Optional[string] `json:"id"`}func (r *TestCreatedResponse) Schema() *ObjectSchema {return Object(map[string]Schema{- "id": String(&r.ID).Optional(),+ "id": OptStr(&r.ID),})}@@ -59,11 +59,11 @@ func (*TestNoContent) Status() int { return http.StatusNoContent }// =============================================================================func testOKHandler(_ context.Context, _ *EmptyRequest) (TestOKResponse, error) {- return TestOKResponse{Message: "ok"}, nil+ return TestOKResponse{Message: NewOptional("ok")}, nil}func testCreatedHandler(_ context.Context, _ *EmptyRequest) (TestCreatedResponse, error) {- return TestCreatedResponse{ID: "123"}, nil+ return TestCreatedResponse{ID: NewOptional("123")}, nil}func testNoContentHandler(_ context.Context, _ *EmptyRequest) (TestNoContent, error) {diff --git a/backend-go/pkg/chita/schema.go b/backend-go/pkg/chita/schema.goindex 69c22a9c73..b0c7a50791 100644--- a/backend-go/pkg/chita/schema.go+++ b/backend-go/pkg/chita/schema.go@@ -96,8 +96,7 @@ func (e ValidationErrors) HasErrors() bool {// --- String Schema ---type StringSchema struct {- ptr *string- required bool+ field *strFieldAccessorminLength *intmaxLength *intpattern *regexp.Regexp@@ -115,8 +114,50 @@ type StringSchema struct {source ParamSource}-func String(ptr *string) *StringSchema {- return &StringSchema{ptr: ptr}+// Str creates a StringSchema for a Required[string] field (for requests).+func Str(field *Required[string]) *StringSchema {+ return &StringSchema{field: &strFieldAccessor{req: field}}+}++// OptStr creates a StringSchema for an Optional[string] field (for requests).+func OptStr(field *Optional[string]) *StringSchema {+ return &StringSchema{field: &strFieldAccessor{opt: field}}+}++// StringElem creates a StringSchema for array element definitions (no binding).+func StringElem(_ *string) *StringSchema {+ var placeholder Optional[string]+ return &StringSchema{field: &strFieldAccessor{opt: &placeholder}}+}++// StringPtr creates a StringSchema bound to a raw string pointer.+// For internal/test use where Required/Optional isn't needed.+func StringPtr(ptr *string) *StringSchema {+ if ptr == nil {+ var placeholder Optional[string]+ return &StringSchema{field: &strFieldAccessor{opt: &placeholder}}+ }+ // Wrap in Optional and set value if non-empty+ var opt Optional[string]+ if *ptr != "" {+ opt.Set(*ptr)+ }+ return &StringSchema{field: &strFieldAccessor{opt: &opt}}+}++// Get returns the current string value.+func (s *StringSchema) Get() string {+ return s.field.Get()+}++// Set sets the string value.+func (s *StringSchema) Set(v string) {+ s.field.Set(v)+}++// IsSet returns true if the value was explicitly set.+func (s *StringSchema) IsSet() bool {+ return s.field.IsSet()}// From sets the parameter source (Path, Query, Header, Cookie). Default is Body.@@ -129,16 +170,6 @@ func (s *StringSchema) GetSource() ParamSource {return s.source}-func (s *StringSchema) Required() *StringSchema {- s.required = true- return s-}--func (s *StringSchema) Optional() *StringSchema {- s.required = false- return s-}-func (s *StringSchema) MinLength(n int) *StringSchema {s.minLength = &nreturn s@@ -287,24 +318,24 @@ func (s *StringSchema) WriteOnly() *StringSchema {}func (s *StringSchema) IsRequired() bool {- return s.required+ return s.field.IsRequired()}func (s *StringSchema) IsPresent() bool {- return s.ptr != nil && *s.ptr != ""+ return s.field.IsSet() && s.field.Get() != ""}func (s *StringSchema) Validate() []ValidationError {var errs []ValidationError- val := ""- if s.ptr != nil {- val = *s.ptr+ val := s.Get()++ if s.IsRequired() && !s.IsSet() {+ errs = append(errs, ValidationError{Code: "required", Message: "is required"})+ return errs}+ // Skip other validations if value is empty and not requiredif val == "" {- if s.required {- errs = append(errs, ValidationError{Code: "required", Message: "is required"})- }return errs}@@ -444,9 +475,7 @@ func (s *StringSchema) OpenAPI() map[string]any {// --- Int Schema ---type IntSchema struct {- ptr *int- ptr64 *int64- required bool+ field *intFieldAccessorminimum *int64maximum *int64exclusiveMinimum *int64@@ -464,33 +493,60 @@ type IntSchema struct {source ParamSource}-func Int(ptr *int) *IntSchema {- return &IntSchema{ptr: ptr}+// Int creates an IntSchema for a Required[int] field.+func Int(field *Required[int]) *IntSchema {+ return &IntSchema{field: &intFieldAccessor{req: field}}}-func Int64(ptr *int64) *IntSchema {- return &IntSchema{ptr64: ptr}+// OptInt creates an IntSchema for an Optional[int] field.+func OptInt(field *Optional[int]) *IntSchema {+ return &IntSchema{field: &intFieldAccessor{opt: field}}}-func (s *IntSchema) From(source ParamSource) *IntSchema {- s.source = source- return s+// Int64 creates an IntSchema for a Required[int64] field.+func Int64(field *Required[int64]) *IntSchema {+ return &IntSchema{field: &intFieldAccessor{req64: field}}}-func (s *IntSchema) GetSource() ParamSource {- return s.source+// OptInt64 creates an IntSchema for an Optional[int64] field.+func OptInt64(field *Optional[int64]) *IntSchema {+ return &IntSchema{field: &intFieldAccessor{opt64: field}}}-func (s *IntSchema) Required() *IntSchema {- s.required = true- return s+// GetInt returns the current int value.+func (s *IntSchema) GetInt() int {+ return s.field.GetInt()}-func (s *IntSchema) Optional() *IntSchema {- s.required = false+// GetInt64 returns the current int64 value.+func (s *IntSchema) GetInt64() int64 {+ return s.field.GetInt64()+}++// SetInt sets the int value.+func (s *IntSchema) SetInt(v int) {+ s.field.SetInt(v)+}++// SetInt64 sets the int64 value.+func (s *IntSchema) SetInt64(v int64) {+ s.field.SetInt64(v)+}++// IsSet returns true if the value was explicitly set.+func (s *IntSchema) IsSet() bool {+ return s.field.IsSet()+}++func (s *IntSchema) From(source ParamSource) *IntSchema {+ s.source = sourcereturn s}+func (s *IntSchema) GetSource() ParamSource {+ return s.source+}+func (s *IntSchema) Min(n int64) *IntSchema {s.minimum = &nreturn s@@ -568,36 +624,26 @@ func (s *IntSchema) WriteOnly() *IntSchema {}func (s *IntSchema) IsRequired() bool {- return s.required+ return s.field.IsRequired()}func (s *IntSchema) IsPresent() bool {- return s.ptr != nil || s.ptr64 != nil-}--//nolint:unparam // bool used for interface consistency-func (s *IntSchema) value() (int64, bool) {- if s.ptr != nil {- return int64(*s.ptr), true- }- if s.ptr64 != nil {- return *s.ptr64, true- }- return 0, false+ return s.field.IsSet()}func (s *IntSchema) Validate() []ValidationError {var errs []ValidationError- // ptr == nil means the value was not provided (distinct from value being 0)- if s.ptr == nil && s.ptr64 == nil {- if s.required {- errs = append(errs, ValidationError{Code: "required", Message: "is required"})- }+ if s.IsRequired() && !s.IsSet() {+ errs = append(errs, ValidationError{Code: "required", Message: "is required"})+ return errs+ }++ if !s.IsSet() {return errs}- val, _ := s.value()+ val := s.GetInt64()if s.minimum != nil && val < *s.minimum {errs = append(errs, ValidationError{@@ -699,8 +745,7 @@ func (s *IntSchema) OpenAPI() map[string]any {// --- Float Schema ---type FloatSchema struct {- ptr *float64- required bool+ field *floatFieldAccessorminimum *float64maximum *float64exclusiveMinimum *float64@@ -717,29 +762,40 @@ type FloatSchema struct {source ParamSource}-func Float(ptr *float64) *FloatSchema {- return &FloatSchema{ptr: ptr}+// Float creates a FloatSchema for a Required[float64] field.+func Float(field *Required[float64]) *FloatSchema {+ return &FloatSchema{field: &floatFieldAccessor{req: field}}}-func (s *FloatSchema) From(source ParamSource) *FloatSchema {- s.source = source- return s+// OptFloat creates a FloatSchema for an Optional[float64] field.+func OptFloat(field *Optional[float64]) *FloatSchema {+ return &FloatSchema{field: &floatFieldAccessor{opt: field}}}-func (s *FloatSchema) GetSource() ParamSource {- return s.source+// Set sets the float value.+func (s *FloatSchema) Set(v float64) {+ s.field.Set(v)}-func (s *FloatSchema) Required() *FloatSchema {- s.required = true- return s+// Get returns the current float value.+func (s *FloatSchema) Get() float64 {+ return s.field.Get()}-func (s *FloatSchema) Optional() *FloatSchema {- s.required = false+// IsSet returns true if the value was explicitly set.+func (s *FloatSchema) IsSet() bool {+ return s.field.IsSet()+}++func (s *FloatSchema) From(source ParamSource) *FloatSchema {+ s.source = sourcereturn s}+func (s *FloatSchema) GetSource() ParamSource {+ return s.source+}+func (s *FloatSchema) Min(n float64) *FloatSchema {s.minimum = &nreturn s@@ -812,25 +868,24 @@ func (s *FloatSchema) WriteOnly() *FloatSchema {}func (s *FloatSchema) IsRequired() bool {- return s.required+ return s.field.IsRequired()}func (s *FloatSchema) IsPresent() bool {- return s.ptr != nil+ return s.field.IsSet()}func (s *FloatSchema) Validate() []ValidationError {var errs []ValidationError- // ptr == nil means the value was not provided (distinct from value being 0)- if s.ptr == nil {- if s.required {+ if !s.field.IsSet() {+ if s.field.IsRequired() {errs = append(errs, ValidationError{Code: "required", Message: "is required"})}return errs}- val := *s.ptr+ val := s.field.Get()if s.minimum != nil && val < *s.minimum {errs = append(errs, ValidationError{@@ -912,8 +967,7 @@ func (s *FloatSchema) OpenAPI() map[string]any {// --- Bool Schema ---type BoolSchema struct {- ptr *bool- required bool+ field *boolFieldAccessordefaultVal *boolexample anytitle string@@ -925,29 +979,40 @@ type BoolSchema struct {source ParamSource}-func Bool(ptr *bool) *BoolSchema {- return &BoolSchema{ptr: ptr}+// Bool creates a BoolSchema for a Required[bool] field.+func Bool(field *Required[bool]) *BoolSchema {+ return &BoolSchema{field: &boolFieldAccessor{req: field}}}-func (s *BoolSchema) From(source ParamSource) *BoolSchema {- s.source = source- return s+// OptBool creates a BoolSchema for an Optional[bool] field.+func OptBool(field *Optional[bool]) *BoolSchema {+ return &BoolSchema{field: &boolFieldAccessor{opt: field}}}-func (s *BoolSchema) GetSource() ParamSource {- return s.source+// Get returns the current bool value.+func (s *BoolSchema) Get() bool {+ return s.field.Get()}-func (s *BoolSchema) Required() *BoolSchema {- s.required = true- return s+// Set sets the bool value.+func (s *BoolSchema) Set(v bool) {+ s.field.Set(v)}-func (s *BoolSchema) Optional() *BoolSchema {- s.required = false+// IsSet returns true if the value was explicitly set.+func (s *BoolSchema) IsSet() bool {+ return s.field.IsSet()+}++func (s *BoolSchema) From(source ParamSource) *BoolSchema {+ s.source = sourcereturn s}+func (s *BoolSchema) GetSource() ParamSource {+ return s.source+}+func (s *BoolSchema) Default(val bool) *BoolSchema {s.defaultVal = &valreturn s@@ -989,21 +1054,18 @@ func (s *BoolSchema) WriteOnly() *BoolSchema {}func (s *BoolSchema) IsRequired() bool {- return s.required+ return s.field.IsRequired()}func (s *BoolSchema) IsPresent() bool {- return s.ptr != nil+ return s.field.IsSet()}func (s *BoolSchema) Validate() []ValidationError {var errs []ValidationError- // ptr == nil means the value was not provided (distinct from value being false)- if s.ptr == nil {- if s.required {- errs = append(errs, ValidationError{Code: "required", Message: "is required"})- }+ if s.IsRequired() && !s.IsSet() {+ errs = append(errs, ValidationError{Code: "required", Message: "is required"})}return errs@@ -1059,6 +1121,26 @@ func UUID(ptr *uuid.UUID) *UUIDSchema {return &UUIDSchema{ptr: ptr}}+// Set sets the UUID value.+func (s *UUIDSchema) Set(v uuid.UUID) {+ if s.ptr != nil {+ *s.ptr = v+ }+}++// Get returns the current UUID value.+func (s *UUIDSchema) Get() uuid.UUID {+ if s.ptr != nil {+ return *s.ptr+ }+ return uuid.Nil+}++// IsSet returns true if the value is set (non-nil UUID).+func (s *UUIDSchema) IsSet() bool {+ return s.ptr != nil && *s.ptr != uuid.Nil+}+func (s *UUIDSchema) From(source ParamSource) *UUIDSchema {s.source = sourcereturn s@@ -1181,6 +1263,26 @@ func Time(ptr *time.Time) *TimeSchema {return &TimeSchema{ptr: ptr, format: "date-time"}}+// Set sets the time value.+func (s *TimeSchema) Set(v time.Time) {+ if s.ptr != nil {+ *s.ptr = v+ }+}++// Get returns the current time value.+func (s *TimeSchema) Get() time.Time {+ if s.ptr != nil {+ return *s.ptr+ }+ return time.Time{}+}++// IsSet returns true if the value is set (non-zero time).+func (s *TimeSchema) IsSet() bool {+ return s.ptr != nil && !s.ptr.IsZero()+}+func (s *TimeSchema) From(source ParamSource) *TimeSchema {s.source = sourcereturn sdiff --git a/backend-go/pkg/chita/schema_composite_test.go b/backend-go/pkg/chita/schema_composite_test.goindex a4e34f77e0..56e09fc06f 100644--- a/backend-go/pkg/chita/schema_composite_test.go+++ b/backend-go/pkg/chita/schema_composite_test.go@@ -10,12 +10,12 @@ import (// --- Object Schema Tests ---func TestObjectSchema_Validate(t *testing.T) {- var name string- var age *int+ var name Required[string]+ var age Required[int]schema := Object(map[string]Schema{- "name": String(&name).Required().MinLength(1),- "age": Int(age).Required().Min(0), // nil pointer = missing+ "name": Str(&name).MinLength(1),+ "age": Int(&age).Min(0),})// Both fields missing - should have 2 errors@@ -23,46 +23,40 @@ func TestObjectSchema_Validate(t *testing.T) {require.Len(t, errs, 2)// Set valid values- name = "John"- ageVal := 25- age = &ageVal- // Rebuild schema with new pointer- schema = Object(map[string]Schema{- "name": String(&name).Required().MinLength(1),- "age": Int(age).Required().Min(0),- })+ name.Set("John")+ age.Set(25)errs = schema.Validate()assert.Empty(t, errs)}func TestObjectSchema_NestedValidation(t *testing.T) {- var street string- var city string+ var street Required[string]+ var city Required[string]schema := Object(map[string]Schema{"address": Object(map[string]Schema{- "street": String(&street).Required(),- "city": String(&city).Required(),+ "street": Str(&street),+ "city": Str(&city),}),})errs := schema.Validate()require.Len(t, errs, 2)- street = "123 Main St"- city = "NYC"+ street.Set("123 Main St")+ city.Set("NYC")errs = schema.Validate()assert.Empty(t, errs)}func TestObjectSchema_NestedFieldPaths(t *testing.T) {// Issue #6: Nested validation error paths should be properly constructed- var email string+ var email Required[string]schema := Object(map[string]Schema{"user": Object(map[string]Schema{"profile": Object(map[string]Schema{- "email": String(&email).Required().Email(),+ "email": Str(&email).Email(),}),}),})@@ -74,7 +68,7 @@ func TestObjectSchema_NestedFieldPaths(t *testing.T) {assert.Equal(t, "required", errs[0].Code)// Invalid email should produce error with full path- email = "not-an-email"+ email.Set("not-an-email")errs = schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "user.profile.email", errs[0].Field)@@ -82,12 +76,13 @@ func TestObjectSchema_NestedFieldPaths(t *testing.T) {}func TestObjectSchema_NestedFieldPaths_MultipleErrors(t *testing.T) {- var name string+ var name Required[string]+ var age Required[int]schema := Object(map[string]Schema{"data": Object(map[string]Schema{- "name": String(&name).Required(),- "age": Int(nil).Required(), // nil pointer = missing+ "name": Str(&name),+ "age": Int(&age),}),})@@ -104,12 +99,12 @@ func TestObjectSchema_NestedFieldPaths_MultipleErrors(t *testing.T) {}func TestObjectSchema_OpenAPI(t *testing.T) {- var name string- var email string+ var name Required[string]+ var email Required[string]schema := Object(map[string]Schema{- "name": String(&name).Required().MinLength(1),- "email": String(&email).Required().Email(),+ "name": Str(&name).MinLength(1),+ "email": Str(&email).Email(),}).Title("User").Description("A user object").AdditionalProperties(false)openapi := schema.OpenAPI()@@ -155,8 +150,7 @@ func TestObjectSchema_Discriminator(t *testing.T) {// --- Array Schema Tests ---func TestArraySchema_OpenAPI(t *testing.T) {- var itemVal string- itemSchema := String(&itemVal)+ itemSchema := StringElem(nil)schema := Array(itemSchema).MinItems(1).@@ -202,8 +196,7 @@ func TestArraySchema_Required(t *testing.T) {// --- Map Schema Tests ---func TestMapSchema_OpenAPI(t *testing.T) {- var val string- valueSchema := String(&val)+ valueSchema := StringElem(nil)schema := Map(valueSchema).MinProperties(1).@@ -235,24 +228,24 @@ func TestMapSchema_ValidateFn(t *testing.T) {// --- OneOf Schema Tests ---type testDogSchema struct {- Breed string+ Breed Required[string]}func (d *testDogSchema) Schema() *ObjectSchema {return Object(map[string]Schema{"type": Const("dog"), // discriminator - OpenAPI only, not validated- "breed": String(&d.Breed).Required(),+ "breed": Str(&d.Breed),})}type testCatSchema struct {- Color string+ Color Required[string]}func (c *testCatSchema) Schema() *ObjectSchema {return Object(map[string]Schema{"type": Const("cat"), // discriminator - OpenAPI only, not validated- "color": String(&c.Color).Required(),+ "color": Str(&c.Color),})}@@ -283,7 +276,7 @@ func TestOneOfSchema_ValidateFn(t *testing.T) {}func TestOneOfSchema_DiscriminatedValidation(t *testing.T) {- dog := &testDogSchema{Breed: "Labrador"}+ dog := &testDogSchema{Breed: NewRequired("Labrador")}cat := &testCatSchema{} // Color not set - will fail validationt.Run("validates active variant - valid", func(t *testing.T) {@@ -342,7 +335,7 @@ func TestOneOfSchema_DiscriminatedValidation(t *testing.T) {}func TestOneOfSchema_DiscriminatedIsPresent(t *testing.T) {- dog := &testDogSchema{Breed: "Labrador"}+ dog := &testDogSchema{Breed: NewRequired("Labrador")}cat := &testCatSchema{}t.Run("present when active variant set and has values", func(t *testing.T) {@@ -367,11 +360,11 @@ func TestOneOfSchema_DiscriminatedIsPresent(t *testing.T) {// --- AnyOf Schema Tests ---func TestAnyOfSchema_OpenAPI(t *testing.T) {- var strVal string- var intVal int+ var strVal Required[string]+ var intVal Required[int]schema := AnyOf(- String(&strVal),+ Str(&strVal),Int(&intVal),).Title("StringOrInt").Description("Can be string or integer")@@ -395,11 +388,11 @@ func TestAnyOfSchema_Required(t *testing.T) {// --- AllOf Schema Tests ---func TestAllOfSchema_OpenAPI(t *testing.T) {- var name string- var age int+ var name Required[string]+ var age Required[int]schema := AllOf(- Object(map[string]Schema{"name": String(&name)}),+ Object(map[string]Schema{"name": Str(&name)}),Object(map[string]Schema{"age": Int(&age)}),).Title("Combined").Description("Combined schema")@@ -411,25 +404,19 @@ func TestAllOfSchema_OpenAPI(t *testing.T) {}func TestAllOfSchema_Validate(t *testing.T) {- var name string- var age *int+ var name Required[string]+ var age Required[int]schema := AllOf(- Object(map[string]Schema{"name": String(&name).Required()}),- Object(map[string]Schema{"age": Int(age).Required()}), // nil pointer = missing+ Object(map[string]Schema{"name": Str(&name)}),+ Object(map[string]Schema{"age": Int(&age)}),)errs := schema.Validate()require.Len(t, errs, 2)- name = "John"- ageVal := 25- age = &ageVal- // Rebuild schema with new pointer- schema = AllOf(- Object(map[string]Schema{"name": String(&name).Required()}),- Object(map[string]Schema{"age": Int(age).Required()}),- )+ name.Set("John")+ age.Set(25)errs = schema.Validate()assert.Empty(t, errs)}diff --git a/backend-go/pkg/chita/schema_request.go b/backend-go/pkg/chita/schema_request.goindex 624b48766f..5126f0555d 100644--- a/backend-go/pkg/chita/schema_request.go+++ b/backend-go/pkg/chita/schema_request.go@@ -14,63 +14,54 @@ type ValueGetter interface {// GetValue returns the bound string value.func (s *StringSchema) GetValue() any {- if s.ptr == nil {+ if !s.IsSet() {return nil}- return *s.ptr+ return s.Get()}-// IsZero returns true if the value is zero/empty.+// IsZero returns true if the value is not set or empty.func (s *StringSchema) IsZero() bool {- return s.ptr == nil || *s.ptr == ""+ return !s.IsSet() || s.Get() == ""}// GetValue returns the bound int value.func (s *IntSchema) GetValue() any {- if s.ptr != nil {- return *s.ptr- }- if s.ptr64 != nil {- return *s.ptr64+ if !s.IsSet() {+ return nil}- return nil+ return s.GetInt64()}-// IsZero returns true if the value is zero/empty.+// IsZero returns true if the value is not set.func (s *IntSchema) IsZero() bool {- if s.ptr != nil {- return *s.ptr == 0- }- if s.ptr64 != nil {- return *s.ptr64 == 0- }- return true+ return !s.IsSet()}// GetValue returns the bound float value.func (s *FloatSchema) GetValue() any {- if s.ptr == nil {+ if !s.IsSet() {return nil}- return *s.ptr+ return s.Get()}-// IsZero returns true if the value is zero/empty.+// IsZero returns true if the value is not set.func (s *FloatSchema) IsZero() bool {- return s.ptr == nil || *s.ptr == 0+ return !s.IsSet()}// GetValue returns the bound bool value.func (s *BoolSchema) GetValue() any {- if s.ptr == nil {+ if !s.IsSet() {return nil}- return *s.ptr+ return s.Get()}-// IsZero returns true if the value is zero/empty.+// IsZero returns true if the value is not set.func (s *BoolSchema) IsZero() bool {- return s.ptr == nil+ return !s.IsSet()}// GetValue returns the bound UUID value.diff --git a/backend-go/pkg/chita/schema_test.go b/backend-go/pkg/chita/schema_test.goindex da05fa3649..fc61bd498f 100644--- a/backend-go/pkg/chita/schema_test.go+++ b/backend-go/pkg/chita/schema_test.go@@ -13,8 +13,8 @@ import (// --- String Schema Tests ---func TestStringSchema_Required(t *testing.T) {- var val string- schema := String(&val).Required()+ var val Required[string]+ schema := Str(&val)assert.True(t, schema.IsRequired())@@ -24,8 +24,8 @@ func TestStringSchema_Required(t *testing.T) {}func TestStringSchema_Optional(t *testing.T) {- var val string- schema := String(&val).Optional()+ var val Optional[string]+ schema := OptStr(&val)assert.False(t, schema.IsRequired())@@ -34,144 +34,143 @@ func TestStringSchema_Optional(t *testing.T) {}func TestStringSchema_MinLength(t *testing.T) {- val := "ab"- schema := String(&val).MinLength(3)+ val := NewRequired("ab")+ schema := Str(&val).MinLength(3)errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "min_length", errs[0].Code)- val = "abc"+ val.Set("abc")errs = schema.Validate()assert.Empty(t, errs)}func TestStringSchema_MaxLength(t *testing.T) {- val := "abcdef"- schema := String(&val).MaxLength(5)+ val := NewRequired("abcdef")+ schema := Str(&val).MaxLength(5)errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "max_length", errs[0].Code)- val = "abcde"+ val.Set("abcde")errs = schema.Validate()assert.Empty(t, errs)}func TestStringSchema_Length(t *testing.T) {- val := "ab"- schema := String(&val).Length(3, 5)+ val := NewRequired("ab")+ schema := Str(&val).Length(3, 5)errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "min_length", errs[0].Code)- val = "abcdef"+ val.Set("abcdef")errs = schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "max_length", errs[0].Code)- val = "abcd"+ val.Set("abcd")errs = schema.Validate()assert.Empty(t, errs)}func TestStringSchema_Pattern(t *testing.T) {- val := "abc123"- schema := String(&val).Pattern(`^[a-z]+$`)+ val := NewRequired("abc123")+ schema := Str(&val).Pattern(`^[a-z]+$`)errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "pattern", errs[0].Code)- val = "abc"+ val.Set("abc")errs = schema.Validate()assert.Empty(t, errs)}func TestStringSchema_Enum(t *testing.T) {- val := "invalid"- schema := String(&val).Enum("foo", "bar", "baz")+ val := NewRequired("invalid")+ schema := Str(&val).Enum("foo", "bar", "baz")errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "enum", errs[0].Code)- val = "bar"+ val.Set("bar")errs = schema.Validate()assert.Empty(t, errs)}func TestStringSchema_FormatEmail(t *testing.T) {- val := "not-an-email"- schema := String(&val).Email()+ val := NewRequired("not-an-email")+ schema := Str(&val).Email()errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "format", errs[0].Code)- val = "[email protected]"+ val.Set("[email protected]")errs = schema.Validate()assert.Empty(t, errs)}func TestStringSchema_FormatUUID(t *testing.T) {- val := "not-a-uuid"- schema := String(&val).UUID()+ val := NewRequired("not-a-uuid")+ schema := Str(&val).UUID()errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "format", errs[0].Code)- val = "550e8400-e29b-41d4-a716-446655440000"+ val.Set("550e8400-e29b-41d4-a716-446655440000")errs = schema.Validate()assert.Empty(t, errs)}func TestStringSchema_FormatURI(t *testing.T) {- val := "not a uri"- schema := String(&val).URI()+ val := NewRequired("not a uri")+ schema := Str(&val).URI()errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "format", errs[0].Code)- val = "https://example.com/path"+ val.Set("https://example.com/path")errs = schema.Validate()assert.Empty(t, errs)}func TestStringSchema_FormatDateTime(t *testing.T) {- val := "not-a-date"- schema := String(&val).DateTime()+ val := NewRequired("not-a-date")+ schema := Str(&val).DateTime()errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "format", errs[0].Code)- val = "2024-01-15T10:30:00Z"+ val.Set("2024-01-15T10:30:00Z")errs = schema.Validate()assert.Empty(t, errs)}func TestStringSchema_FormatDate(t *testing.T) {- val := "not-a-date"- schema := String(&val).Date()+ val := NewRequired("not-a-date")+ schema := Str(&val).Date()errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "format", errs[0].Code)- val = "2024-01-15"+ val.Set("2024-01-15")errs = schema.Validate()assert.Empty(t, errs)}func TestStringSchema_OpenAPI(t *testing.T) {- var val string- schema := String(&val).- Required().+ var val Required[string]+ schema := Str(&val).MinLength(1).MaxLength(100).Pattern(`^[a-z]+$`).@@ -201,8 +200,8 @@ func TestStringSchema_OpenAPI(t *testing.T) {}func TestStringSchema_OpenAPI_Enum(t *testing.T) {- var val string- schema := String(&val).Enum("a", "b", "c")+ var val Required[string]+ schema := Str(&val).Enum("a", "b", "c")openapi := schema.OpenAPI()@@ -211,9 +210,9 @@ func TestStringSchema_OpenAPI_Enum(t *testing.T) {// --- Int Schema Tests ----func TestIntSchema_Required_NilPointer(t *testing.T) {- // nil pointer means value was not provided- schema := Int(nil).Required()+func TestIntSchema_Required_NotSet(t *testing.T) {+ var val Required[int]+ schema := Int(&val)errs := schema.Validate()require.Len(t, errs, 1)@@ -222,119 +221,119 @@ func TestIntSchema_Required_NilPointer(t *testing.T) {func TestIntSchema_Required_ZeroValue(t *testing.T) {// Zero is a valid provided value, not "missing"- val := 0- schema := Int(&val).Required()+ val := NewRequired(0)+ schema := Int(&val)errs := schema.Validate()- assert.Empty(t, errs) // 0 is valid when ptr is non-nil+ assert.Empty(t, errs) // 0 is valid when isSet is true}func TestIntSchema_Required_NonZeroValue(t *testing.T) {- val := 42- schema := Int(&val).Required()+ val := NewRequired(42)+ schema := Int(&val)errs := schema.Validate()assert.Empty(t, errs)}func TestIntSchema_Min(t *testing.T) {- val := 5+ val := NewRequired(5)schema := Int(&val).Min(10)errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "minimum", errs[0].Code)- val = 10+ val.Set(10)errs = schema.Validate()assert.Empty(t, errs)}func TestIntSchema_Max(t *testing.T) {- val := 15+ val := NewRequired(15)schema := Int(&val).Max(10)errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "maximum", errs[0].Code)- val = 10+ val.Set(10)errs = schema.Validate()assert.Empty(t, errs)}func TestIntSchema_Range(t *testing.T) {- val := 5+ val := NewRequired(5)schema := Int(&val).Range(10, 20)errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "minimum", errs[0].Code)- val = 25+ val.Set(25)errs = schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "maximum", errs[0].Code)- val = 15+ val.Set(15)errs = schema.Validate()assert.Empty(t, errs)}func TestIntSchema_ExclusiveMin(t *testing.T) {- val := 10+ val := NewRequired(10)schema := Int(&val).ExclusiveMin(10)errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "exclusive_minimum", errs[0].Code)- val = 11+ val.Set(11)errs = schema.Validate()assert.Empty(t, errs)}func TestIntSchema_ExclusiveMax(t *testing.T) {- val := 10+ val := NewRequired(10)schema := Int(&val).ExclusiveMax(10)errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "exclusive_maximum", errs[0].Code)- val = 9+ val.Set(9)errs = schema.Validate()assert.Empty(t, errs)}func TestIntSchema_MultipleOf(t *testing.T) {- val := 7+ val := NewRequired(7)schema := Int(&val).MultipleOf(3)errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "multiple_of", errs[0].Code)- val = 9+ val.Set(9)errs = schema.Validate()assert.Empty(t, errs)}func TestIntSchema_Enum(t *testing.T) {- val := 5+ val := NewRequired(5)schema := Int(&val).Enum(1, 2, 3)errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "enum", errs[0].Code)- val = 2+ val.Set(2)errs = schema.Validate()assert.Empty(t, errs)}func TestInt64Schema(t *testing.T) {- var val int64 = 100+ val := NewRequired[int64](100)schema := Int64(&val).Min(50).Max(200)errs := schema.Validate()@@ -346,7 +345,7 @@ func TestInt64Schema(t *testing.T) {}func TestIntSchema_OpenAPI(t *testing.T) {- var val int+ var val Required[int]schema := Int(&val).Min(0).Max(100).@@ -375,9 +374,9 @@ func TestIntSchema_OpenAPI(t *testing.T) {// --- Float Schema Tests ----func TestFloatSchema_Required_NilPointer(t *testing.T) {- // nil pointer means value was not provided- schema := Float(nil).Required()+func TestFloatSchema_Required_NotSet(t *testing.T) {+ var val Required[float64]+ schema := Float(&val)errs := schema.Validate()require.Len(t, errs, 1)@@ -386,61 +385,61 @@ func TestFloatSchema_Required_NilPointer(t *testing.T) {func TestFloatSchema_Required_ZeroValue(t *testing.T) {// Zero is a valid provided value, not "missing"- val := 0.0- schema := Float(&val).Required()+ val := NewRequired(0.0)+ schema := Float(&val)errs := schema.Validate()- assert.Empty(t, errs) // 0.0 is valid when ptr is non-nil+ assert.Empty(t, errs) // 0.0 is valid when isSet is true}func TestFloatSchema_Required_NonZeroValue(t *testing.T) {- val := 3.14- schema := Float(&val).Required()+ val := NewRequired(3.14)+ schema := Float(&val)errs := schema.Validate()assert.Empty(t, errs)}func TestFloatSchema_Min(t *testing.T) {- val := 1.5+ val := NewRequired(1.5)schema := Float(&val).Min(2.0)errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "minimum", errs[0].Code)- val = 2.5+ val.Set(2.5)errs = schema.Validate()assert.Empty(t, errs)}func TestFloatSchema_Max(t *testing.T) {- val := 5.5+ val := NewRequired(5.5)schema := Float(&val).Max(5.0)errs := schema.Validate()require.Len(t, errs, 1)assert.Equal(t, "maximum", errs[0].Code)- val = 4.5+ val.Set(4.5)errs = schema.Validate()assert.Empty(t, errs)}func TestFloatSchema_Range(t *testing.T) {- val := 0.5+ val := NewRequired(0.5)schema := Float(&val).Range(1.0, 10.0)errs := schema.Validate()require.Len(t, errs, 1)- val = 5.0+ val.Set(5.0)errs = schema.Validate()assert.Empty(t, errs)}func TestFloatSchema_ExclusiveMinMax(t *testing.T) {- val := 5.0+ val := NewRequired(5.0)schema := Float(&val).ExclusiveMin(5.0)errs := schema.Validate()@@ -454,7 +453,7 @@ func TestFloatSchema_ExclusiveMinMax(t *testing.T) {}func TestFloatSchema_OpenAPI(t *testing.T) {- var val float64+ var val Required[float64]schema := Float(&val).Min(0.0).Max(1.0).Title("Ratio")openapi := schema.OpenAPI()@@ -468,9 +467,9 @@ func TestFloatSchema_OpenAPI(t *testing.T) {// --- Bool Schema Tests ----func TestBoolSchema_Required_NilPointer(t *testing.T) {- // nil pointer means value was not provided- schema := Bool(nil).Required()+func TestBoolSchema_Required_NotSet(t *testing.T) {+ var val Required[bool]+ schema := Bool(&val)errs := schema.Validate()require.Len(t, errs, 1)@@ -479,23 +478,23 @@ func TestBoolSchema_Required_NilPointer(t *testing.T) {func TestBoolSchema_Required_FalseValue(t *testing.T) {// false is a valid provided value, not "missing"- val := false- schema := Bool(&val).Required()+ val := NewRequired(false)+ schema := Bool(&val)errs := schema.Validate()- assert.Empty(t, errs) // false is valid when ptr is non-nil+ assert.Empty(t, errs) // false is valid when isSet is true}func TestBoolSchema_Required_TrueValue(t *testing.T) {- val := true- schema := Bool(&val).Required()+ val := NewRequired(true)+ schema := Bool(&val)errs := schema.Validate()assert.Empty(t, errs)}func TestBoolSchema_OpenAPI(t *testing.T) {- var val bool+ var val Required[bool]schema := Bool(&val).Default(true).Example(false).@@ -708,8 +707,8 @@ func TestRawSchema_OpenAPI(t *testing.T) {// --- Multiple Validation Errors ---func TestStringSchema_MultipleErrors(t *testing.T) {- val := "ab"- schema := String(&val).MinLength(5).Pattern(`^[0-9]+$`)+ val := NewRequired("ab")+ schema := Str(&val).MinLength(5).Pattern(`^[0-9]+$`)errs := schema.Validate()require.Len(t, errs, 2)diff --git a/backend-go/pkg/chita/union.go b/backend-go/pkg/chita/union.goindex 5b6a73129b..716b3095f5 100644--- a/backend-go/pkg/chita/union.go+++ b/backend-go/pkg/chita/union.go@@ -451,27 +451,20 @@ func applySchemaDefaults(schema *ObjectSchema) {for _, fieldSchema := range schema.properties {switch s := fieldSchema.(type) {case *IntSchema:- if s.defaultVal != nil {- val, _ := s.value()- if val == 0 {- if s.ptr != nil {- *s.ptr = int(*s.defaultVal)- }- if s.ptr64 != nil {- *s.ptr64 = *s.defaultVal- }- }+ if s.defaultVal != nil && !s.IsSet() {+ s.SetInt64(*s.defaultVal)}case *StringSchema:- if s.defaultVal != nil && s.ptr != nil && *s.ptr == "" {- *s.ptr = *s.defaultVal+ if s.defaultVal != nil && !s.IsSet() {+ s.Set(*s.defaultVal)}case *BoolSchema:- // For bool, only apply default if we have a way to track "not set"- // Since false is a valid value, we skip this for now+ if s.defaultVal != nil && !s.IsSet() {+ s.Set(*s.defaultVal)+ }case *FloatSchema:- if s.defaultVal != nil && s.ptr != nil && *s.ptr == 0 {- *s.ptr = *s.defaultVal+ if s.defaultVal != nil && !s.IsSet() {+ s.Set(*s.defaultVal)}}}diff --git a/backend-go/pkg/chita/union_helpers_test.go b/backend-go/pkg/chita/union_helpers_test.goindex b226f07931..9e2186c911 100644--- a/backend-go/pkg/chita/union_helpers_test.go+++ b/backend-go/pkg/chita/union_helpers_test.go@@ -39,7 +39,7 @@ func TestParseUnionField_InRequest(t *testing.T) {dog, ok := req.Pet.(*Dog)require.True(t, ok)- assert.Equal(t, "Golden Retriever", dog.Breed)+ assert.Equal(t, "Golden Retriever", dog.Breed.Get())}func TestParseUnionField_InRequest_NullPet(t *testing.T) {@@ -72,14 +72,14 @@ type NestedAuthMethod interface {}type PasswordPayload struct {- Username string `json:"username"`- Password string `json:"password"`+ Username Required[string] `json:"username"`+ Password Required[string] `json:"password"`}func (p *PasswordPayload) Schema() *ObjectSchema {return Object(map[string]Schema{- "username": String(&p.Username).Required().MinLength(1),- "password": String(&p.Password).Required().MinLength(8),+ "username": Str(&p.Username).MinLength(1),+ "password": Str(&p.Password).MinLength(8),})}@@ -87,14 +87,14 @@ func (p *PasswordPayload) unionMarker() {}func (p *PasswordPayload) nestedAuthMarker() {}type OAuthPayload struct {- Provider string `json:"provider"`- AccessToken string `json:"accessToken"`+ Provider Required[string] `json:"provider"`+ AccessToken Required[string] `json:"accessToken"`}func (o *OAuthPayload) Schema() *ObjectSchema {return Object(map[string]Schema{- "provider": String(&o.Provider).Required().Enum("google", "github"),- "accessToken": String(&o.AccessToken).Required(),+ "provider": Str(&o.Provider).Enum("google", "github"),+ "accessToken": Str(&o.AccessToken),})}@@ -125,7 +125,7 @@ func TestNestedUnionDef_Parse(t *testing.T) {verify: func(t *testing.T, auth NestedAuthMethod) {pwd, ok := auth.(*PasswordPayload)require.True(t, ok)- assert.Equal(t, "john", pwd.Username)+ assert.Equal(t, "john", pwd.Username.Get())},},{@@ -134,7 +134,7 @@ func TestNestedUnionDef_Parse(t *testing.T) {verify: func(t *testing.T, auth NestedAuthMethod) {oauth, ok := auth.(*OAuthPayload)require.True(t, ok)- assert.Equal(t, "github", oauth.Provider)+ assert.Equal(t, "github", oauth.Provider.Get())},},{name: "null", data: json.RawMessage(`null`), wantNil: true},@@ -175,7 +175,7 @@ func TestNestedUnionDef_ParseWithType(t *testing.T) {require.NoError(t, err)pwd, ok := auth.(*PasswordPayload)require.True(t, ok)- assert.Equal(t, "jane", pwd.Username)+ assert.Equal(t, "jane", pwd.Username.Get())})t.Run("unknown type", func(t *testing.T) {@@ -244,7 +244,7 @@ func TestParseNestedUnionField_InRequest(t *testing.T) {pwd, ok := req.Auth.(*PasswordPayload)require.True(t, ok)- assert.Equal(t, "john", pwd.Username)+ assert.Equal(t, "john", pwd.Username.Get())}func TestParseNestedUnionField_NullOrMissingDiscriminator(t *testing.T) {@@ -269,14 +269,14 @@ func TestParseNestedUnionField_NullOrMissingDiscriminator(t *testing.T) {type DogWithDefault struct {UnionBase- Type string `json:"type"`- Breed string `json:"breed"`+ Type Required[string] `json:"type"`+ Breed Required[string] `json:"breed"`}func (d *DogWithDefault) Schema() *ObjectSchema {return Object(map[string]Schema{"type": Const("dog"),- "breed": String(&d.Breed).Required().Default("Unknown"),+ "breed": Str(&d.Breed).Default("Unknown"),})}@@ -302,7 +302,7 @@ func TestUnionFromSchema_DefaultVariant(t *testing.T) {dog, ok := animal.(*DogWithDefault)require.True(t, ok)- assert.Equal(t, "Unknown", dog.Breed)+ assert.Equal(t, "Unknown", dog.Breed.Get())})t.Run("overridden by present value", func(t *testing.T) {@@ -315,7 +315,7 @@ func TestUnionFromSchema_DefaultVariant(t *testing.T) {cat, ok := animal.(*Cat)require.True(t, ok)- assert.Equal(t, "black", cat.Color)+ assert.Equal(t, "black", cat.Color.Get())})t.Run("invalid name errors", func(t *testing.T) {diff --git a/backend-go/pkg/chita/union_test.go b/backend-go/pkg/chita/union_test.goindex 9d24ee7be3..2ad2bd2bde 100644--- a/backend-go/pkg/chita/union_test.go+++ b/backend-go/pkg/chita/union_test.go@@ -16,14 +16,14 @@ type Animal interface {}type Dog struct {- Type string `json:"type"`- Breed string `json:"breed"`+ Type Required[string] `json:"type"`+ Breed Required[string] `json:"breed"`}func (d *Dog) Schema() *ObjectSchema {return Object(map[string]Schema{- "type": String(&d.Type).Required(),- "breed": String(&d.Breed).Required().MinLength(1),+ "type": Str(&d.Type),+ "breed": Str(&d.Breed).MinLength(1),})}@@ -31,14 +31,14 @@ func (d *Dog) unionMarker() {}func (d *Dog) animalMarker() {}type Cat struct {- Type string `json:"type"`- Color string `json:"color"`+ Type Required[string] `json:"type"`+ Color Required[string] `json:"color"`}func (c *Cat) Schema() *ObjectSchema {return Object(map[string]Schema{- "type": String(&c.Type).Required(),- "color": String(&c.Color).Required().MinLength(1),+ "type": Str(&c.Type),+ "color": Str(&c.Color).MinLength(1),})}@@ -64,8 +64,8 @@ func TestUnionDef_Parse_Dog(t *testing.T) {dog, ok := animal.(*Dog)require.True(t, ok)- assert.Equal(t, "dog", dog.Type)- assert.Equal(t, "Labrador", dog.Breed)+ assert.Equal(t, "dog", dog.Type.Get())+ assert.Equal(t, "Labrador", dog.Breed.Get())}func TestUnionDef_Parse_Cat(t *testing.T) {@@ -77,8 +77,8 @@ func TestUnionDef_Parse_Cat(t *testing.T) {cat, ok := animal.(*Cat)require.True(t, ok)- assert.Equal(t, "cat", cat.Type)- assert.Equal(t, "orange", cat.Color)+ assert.Equal(t, "cat", cat.Type.Get())+ assert.Equal(t, "orange", cat.Color.Get())}func TestUnionDef_Parse_UnknownType(t *testing.T) {@@ -129,14 +129,14 @@ type Vehicle interface {}type Car struct {- Kind string `json:"kind"`- Doors int `json:"doors"`+ Kind Required[string] `json:"kind"`+ Doors Required[int] `json:"doors"`}func (c *Car) Schema() *ObjectSchema {return Object(map[string]Schema{- "kind": String(&c.Kind).Required(),- "doors": Int(&c.Doors).Required(),+ "kind": Str(&c.Kind),+ "doors": Int(&c.Doors),})}@@ -144,14 +144,14 @@ func (c *Car) unionMarker() {}func (c *Car) vehicleMarker() {}type Bike struct {- Kind string `json:"kind"`- Gears int `json:"gears"`+ Kind Required[string] `json:"kind"`+ Gears Required[int] `json:"gears"`}func (b *Bike) Schema() *ObjectSchema {return Object(map[string]Schema{- "kind": String(&b.Kind).Required(),- "gears": Int(&b.Gears).Required(),+ "kind": Str(&b.Kind),+ "gears": Int(&b.Gears),})}@@ -174,8 +174,8 @@ func TestUnionDef_Parse_CustomDiscriminator(t *testing.T) {car, ok := vehicle.(*Car)require.True(t, ok)- assert.Equal(t, "car", car.Kind)- assert.Equal(t, 4, car.Doors)+ assert.Equal(t, "car", car.Kind.Get())+ assert.Equal(t, 4, car.Doors.Get())}// --- ParseUnions Helper Tests ---@@ -210,7 +210,7 @@ func TestParseUnions_SingleField(t *testing.T) {dog, ok := req.Animal.(*Dog)require.True(t, ok)- assert.Equal(t, "Golden Retriever", dog.Breed)+ assert.Equal(t, "Golden Retriever", dog.Breed.Get())}func TestParseUnions_NullField(t *testing.T) {@@ -278,11 +278,11 @@ func TestParseUnions_MultipleFields(t *testing.T) {cat, ok := req.Pet.(*Cat)require.True(t, ok)- assert.Equal(t, "black", cat.Color)+ assert.Equal(t, "black", cat.Color.Get())bike, ok := req.Vehicle.(*Bike)require.True(t, ok)- assert.Equal(t, 21, bike.Gears)+ assert.Equal(t, 21, bike.Gears.Get())}// --- UnionDef.OpenAPI Tests ---@@ -322,7 +322,7 @@ func TestUnionSchema_Validate_Optional(t *testing.T) {}func TestUnionSchema_Validate_WithValue(t *testing.T) {- dog := &Dog{Type: "dog", Breed: "Poodle"}+ dog := &Dog{Type: NewRequired("dog"), Breed: NewRequired("Poodle")}var animal Animal = dogschema := UnionField(&animal, AnimalParser).Required()@@ -331,7 +331,7 @@ func TestUnionSchema_Validate_WithValue(t *testing.T) {}func TestUnionSchema_Validate_InvalidValue(t *testing.T) {- dog := &Dog{Type: "dog", Breed: ""} // Breed is required, minlength 1+ dog := &Dog{Type: NewRequired("dog")} // Breed is required but not setvar animal Animal = dogschema := UnionField(&animal, AnimalParser).Required()@@ -376,16 +376,16 @@ type NestedAnimal interface {}type WildDog struct {- Type string `json:"type"`- Breed string `json:"breed"`- Region string `json:"region"`+ Type Required[string] `json:"type"`+ Breed Required[string] `json:"breed"`+ Region Required[string] `json:"region"`}func (w *WildDog) Schema() *ObjectSchema {return Object(map[string]Schema{- "type": String(&w.Type).Required(),- "breed": String(&w.Breed).Required(),- "region": String(&w.Region).Required(),+ "type": Str(&w.Type),+ "breed": Str(&w.Breed),+ "region": Str(&w.Region),})}@@ -393,16 +393,16 @@ func (w *WildDog) unionMarker() {}func (w *WildDog) nestedAnimalMarker() {}type DomesticDog struct {- Type string `json:"type"`- Breed string `json:"breed"`- Owner string `json:"owner"`+ Type Required[string] `json:"type"`+ Breed Required[string] `json:"breed"`+ Owner Required[string] `json:"owner"`}func (d *DomesticDog) Schema() *ObjectSchema {return Object(map[string]Schema{- "type": String(&d.Type).Required(),- "breed": String(&d.Breed).Required(),- "owner": String(&d.Owner).Required(),+ "type": Str(&d.Type),+ "breed": Str(&d.Breed),+ "owner": Str(&d.Owner),})}@@ -446,6 +446,6 @@ func TestNestedUnion_Parse(t *testing.T) {wild, ok := shelter.Animal.(*WildDog)require.True(t, ok)- assert.Equal(t, "Wolf", wild.Breed)- assert.Equal(t, "Alaska", wild.Region)+ assert.Equal(t, "Wolf", wild.Breed.Get())+ assert.Equal(t, "Alaska", wild.Region.Get())}