Files
dtoro febc153b7f
Some checks failed
ci / build-test (push) Has been cancelled
ci / docker-build (push) Has been cancelled
ci / web (push) Has been cancelled
Desktop App / Build Linux (amd64) (push) Has been cancelled
Desktop App / Attach to Release (push) Has been cancelled
fix: add involves edge from task to agent:nomos at creation
Plus sync vendor directory for Docker build compatibility.
2026-08-11 22:03:12 +02:00

63 lines
2.0 KiB
Cheetah

// Code generated by go generate; DO NOT EDIT.
package {{ .Package }}_test
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/getkin/kin-openapi/openapi3"
)
{{ range $type := .Types }}
func Test{{ $type.Name }}Ref_Extensions(t *testing.T) {
data := []byte(`{"$ref":"#/components/schemas/Pet","something":"integer","x-order":1}`)
expectMarshalJson := []byte(`{"$ref":"#/components/schemas/Pet","x-order":1}`)
ref := openapi3.{{ $type.Name }}Ref{}
err := json.Unmarshal(data, &ref)
assert.NoError(t, err)
// captures extension
assert.Equal(t, "#/components/schemas/Pet", ref.Ref)
assert.Equal(t, float64(1), ref.Extensions["x-order"])
// does not capture non-extensions
assert.Nil(t, ref.Extensions["something"])
// validation
err = ref.Validate(t.Context())
require.EqualError(t, err, "extra sibling fields: [something]")
err = ref.Validate(t.Context(), openapi3.ProhibitExtensionsWithRef())
require.EqualError(t, err, "extra sibling fields: [something x-order]")
err = ref.Validate(t.Context(), openapi3.AllowExtraSiblingFields("something"))
assert.ErrorContains(t, err, "found unresolved ref") // expected since value not defined
// Verify round trip JSON
// Compare as string to make error message more readable if different
outJson, err := ref.MarshalJSON()
assert.NoError(t, err)
assert.Equal(t, string(outJson), string(expectMarshalJson), "MarshalJSON output is not the same as input data")
// non-extension not json lookable
_, err = ref.JSONLookup("something")
assert.Error(t, err)
{{ if ne $type.Name "Header" }}
t.Run("extentions in value", func(t *testing.T) {
ref.Value = &openapi3.{{ $type.Name }}{Extensions: map[string]any{}}
ref.Value.Extensions["x-order"] = 2.0
// prefers the value next to the \$ref over the one in the \$ref.
v, err := ref.JSONLookup("x-order")
assert.NoError(t, err)
assert.Equal(t, float64(1), v)
})
{{ else }}
// Header does not have its own extensions.
{{ end -}}
}
{{ end -}}