Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions arkruntime/internal/ogenjson/time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2026 ByteDance Ltd. and/or its affiliates.
// SPDX-License-Identifier: Apache-2.0

// Package json provides the ogen date-time codecs used by generated models
// without importing the ogen module (whose Go floor exceeds this SDK's).
package json

import (
"time"

"github.com/go-faster/jx"
)

// DecodeDateTime decodes an RFC3339 string, preserving fractional seconds and
// offsets accepted by time.Parse, matching ogen v1.20.3.
func DecodeDateTime(d *jx.Decoder) (time.Time, error) {
s, err := d.Str()
if err != nil {
return time.Time{}, err
}
return time.Parse(time.RFC3339, s)
}

// EncodeDateTime uses RFC3339, intentionally omitting fractional seconds like
// ogen v1.20.3. Use of RFC3339Nano would change the generated wire format.
func EncodeDateTime(e *jx.Encoder, v time.Time) {
var buf [64]byte
e.ByteStr(v.AppendFormat(buf[:0], time.RFC3339))
}
47 changes: 47 additions & 0 deletions arkruntime/internal/ogenjson/time_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2026 ByteDance Ltd. and/or its affiliates.
// SPDX-License-Identifier: Apache-2.0

package json

import (
"testing"
"time"

"github.com/go-faster/jx"
)

func TestDateTimeWireFormat(t *testing.T) {
for _, tc := range []struct{ input, output string }{
{`"2026-09-28T10:20:30Z"`, `"2026-09-28T10:20:30Z"`},
{`"2026-09-28T10:20:30.123456789+08:00"`, `"2026-09-28T10:20:30+08:00"`},
{`"2026-09-28T10:20:30-05:30"`, `"2026-09-28T10:20:30-05:30"`},
{`"0001-01-01T00:00:00Z"`, `"0001-01-01T00:00:00Z"`},
} {
t.Run(tc.input, func(t *testing.T) {
got, err := DecodeDateTime(jx.DecodeStr(tc.input))
if err != nil {
t.Fatal(err)
}
want, err := time.Parse(time.RFC3339, tc.input[1:len(tc.input)-1])
if err != nil || !got.Equal(want) || got.Nanosecond() != want.Nanosecond() {
t.Fatalf("decoded %v, want %v: %v", got, want, err)
}
e := jx.GetEncoder()
defer jx.PutEncoder(e)
EncodeDateTime(e, got)
if e.String() != tc.output {
t.Fatalf("encoded %s, want %s", e.String(), tc.output)
}
})
}
}

func TestDateTimeRejectsInvalidValues(t *testing.T) {
for _, input := range []string{`null`, `123`, `{}`, `[]`, `""`, `"2026-09-28"`, `"2026-02-30T10:20:30Z"`, `"2026-09-28T10:20:30"`, `"unterminated`} {
t.Run(input, func(t *testing.T) {
if _, err := DecodeDateTime(jx.DecodeStr(input)); err == nil {
t.Fatal("expected decode error")
}
})
}
}
1 change: 0 additions & 1 deletion arkruntime/internal/ogenregex/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
//
// Adapted from github.com/ogen-go/ogen v1.20.3 (Apache-2.0).
// See ../validate/README.md for provenance.

package ogenregex

Expand Down
1 change: 0 additions & 1 deletion arkruntime/internal/ogenregex/ogenregex.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
//
// Adapted from github.com/ogen-go/ogen v1.20.3 (Apache-2.0).
// See ../validate/README.md for provenance.

// Package ogenregex provides an interface to the regex engine.
//
Expand Down
29 changes: 0 additions & 29 deletions arkruntime/internal/validate/README.md

This file was deleted.

1 change: 0 additions & 1 deletion arkruntime/internal/validate/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
//
// Adapted from github.com/ogen-go/ogen v1.20.3 (Apache-2.0).
// See README.md for provenance and compatibility scope.

package validate

Expand Down
1 change: 0 additions & 1 deletion arkruntime/internal/validate/constraints_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
//
// Adapted from github.com/ogen-go/ogen v1.20.3 (Apache-2.0).
// See README.md for provenance and compatibility scope.

package validate

Expand Down
1 change: 0 additions & 1 deletion arkruntime/internal/validate/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
//
// Adapted from github.com/ogen-go/ogen v1.20.3 (Apache-2.0).
// See README.md for provenance and compatibility scope.

package validate

Expand Down
1 change: 0 additions & 1 deletion arkruntime/internal/validate/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
//
// Adapted from github.com/ogen-go/ogen v1.20.3 (Apache-2.0).
// See README.md for provenance and compatibility scope.

package validate

Expand Down
62 changes: 62 additions & 0 deletions arkruntime/internal/validate/object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) 2026 ByteDance Ltd. and/or its affiliates.
// SPDX-License-Identifier: Apache-2.0
//
// Adapted from github.com/ogen-go/ogen v1.20.3 (Apache-2.0).

package validate

import "github.com/go-faster/errors"

// Object validates map length.
type Object struct {
MinProperties int
MinPropertiesSet bool
MaxProperties int
MaxPropertiesSet bool
// TODO: add validate to gen
MinLength int
MinLengthSet bool
MaxLength int
MaxLengthSet bool
}

// SetMinProperties sets MinProperties validation.
func (o *Object) SetMinProperties(v int) {
o.MinPropertiesSet = true
o.MinProperties = v
}

// SetMaxProperties sets MaxProperties validation.
func (o *Object) SetMaxProperties(v int) {
o.MaxPropertiesSet = true
o.MaxProperties = v
}

// SetMinLength sets MinLength validation.
func (o *Object) SetMinLength(v int) {
o.MinLengthSet = true
o.MinLength = v
}

// SetMaxLength sets MaxLength validation.
func (o *Object) SetMaxLength(v int) {
o.MaxLengthSet = true
o.MaxLength = v
}

// Set reports whether any validations are set.
func (o Object) Set() bool {
return o.MaxPropertiesSet || o.MinPropertiesSet
}

// ValidateProperties returns error if object length (properties number) v is invalid.
func (o Object) ValidateProperties(v int) error {
if o.MaxPropertiesSet && v > o.MaxProperties {
return errors.Errorf("object properties number %d greater than maximum %d", v, o.MaxProperties)
}
if o.MinPropertiesSet && v < o.MinProperties {
return errors.Errorf("object properties number %d less than minimum %d", v, o.MinProperties)
}

return nil
}
32 changes: 32 additions & 0 deletions arkruntime/internal/validate/object_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2026 ByteDance Ltd. and/or its affiliates.
// SPDX-License-Identifier: Apache-2.0
package validate

import "testing"

func TestObjectPropertyBounds(t *testing.T) {
var v Object
if v.Set() || v.ValidateProperties(100) != nil {
t.Fatal("unset object should be unconstrained")
}
v.SetMinProperties(1)
v.SetMaxProperties(16)
if !v.Set() {
t.Fatal("bounds not set")
}
for _, n := range []int{1, 16} {
if err := v.ValidateProperties(n); err != nil {
t.Fatal(err)
}
}
for _, n := range []int{0, 17} {
if v.ValidateProperties(n) == nil {
t.Fatalf("accepted %d properties", n)
}
}
v.SetMaxProperties(0)
v.MinPropertiesSet = false
if v.ValidateProperties(0) != nil || v.ValidateProperties(1) == nil {
t.Fatal("zero maximum must be enforced")
}
}
1 change: 0 additions & 1 deletion arkruntime/internal/validate/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
//
// Adapted from github.com/ogen-go/ogen v1.20.3 (Apache-2.0).
// See README.md for provenance and compatibility scope.

package validate

Expand Down
Loading
Loading