package seatdef import ( "reflect" "testing" ) // A verb's schema has its named types in place (the seat list's readers take one schema, not a schema and its types). func TestResolveRefsPutsNamedTypesInPlace(t *testing.T) { defs := map[string]map[string]any{ "id": {"type": "string"}, "row": {"type": "object", "properties": map[string]any{"id": map[string]any{"$ref": "#/defs/id"}}}, } cases := []struct { name string schema, want map[string]any }{ {"nothing", nil, nil}, {"a type nested in a type", map[string]any{"type": "array", "items": map[string]any{"$ref": "#/defs/row"}}, map[string]any{"type": "array", "items": map[string]any{"type": "object", "properties": map[string]any{"id": map[string]any{"type": "string"}}}}}, {"a name it does not define stays", map[string]any{"$ref": "#/defs/gone"}, map[string]any{"$ref": "#/defs/gone"}}, {"a list of schemas", map[string]any{"oneOf": []any{map[string]any{"$ref": "#/defs/id"}}}, map[string]any{"oneOf": []any{map[string]any{"type": "string"}}}}, } for _, c := range cases { if got := ResolveRefs(c.schema, defs); !reflect.DeepEqual(got, c.want) { t.Errorf("%s: %v, want %v", c.name, got, c.want) } } }