From c557b0a3be4d6c50e2610a34b114d2acc7aa4959 Mon Sep 17 00:00:00 2001 From: zoncoen Date: Mon, 23 Dec 2024 01:29:25 +0900 Subject: [PATCH] fix: keep orders of protocol options --- schema/config_test.go | 12 +++--------- schema/testdata/config/valid-with-comment.yaml | 8 ++------ schema/testdata/config/valid.yaml | 4 ++-- schema/yaml.go | 2 +- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/schema/config_test.go b/schema/config_test.go index 89c3f61f..c6a8c453 100644 --- a/schema/config_test.go +++ b/schema/config_test.go @@ -38,12 +38,6 @@ func TestLoadConfig(t *testing.T) { Position: yaml.CommentLinePosition, }, }, - "$.protocols.grpc.request.auth": { - { - Texts: []string{" TODO: fix order issue", " proto:", " imports:", " - proto"}, - Position: yaml.CommentHeadPosition, - }, - }, }, }, } @@ -100,11 +94,11 @@ func TestLoadConfig(t *testing.T) { { Key: "grpc", Value: RawMessage(`request: - auth: - insecure: true proto: imports: - - proto`), + - proto + auth: + insecure: true`), }, }, }, diff --git a/schema/testdata/config/valid-with-comment.yaml b/schema/testdata/config/valid-with-comment.yaml index e701cccb..2da9dab2 100644 --- a/schema/testdata/config/valid-with-comment.yaml +++ b/schema/testdata/config/valid-with-comment.yaml @@ -15,15 +15,11 @@ plugins: protocols: grpc: request: - # TODO: fix order issue - # proto: - # imports: - # - proto - auth: - insecure: true proto: imports: - proto + auth: + insecure: true input: excludes: - .ytt.yaml$ diff --git a/schema/testdata/config/valid.yaml b/schema/testdata/config/valid.yaml index 108f0fe2..32996d52 100644 --- a/schema/testdata/config/valid.yaml +++ b/schema/testdata/config/valid.yaml @@ -13,11 +13,11 @@ plugins: protocols: grpc: request: - auth: - insecure: true proto: imports: - proto + auth: + insecure: true input: excludes: - .ytt.yaml$ diff --git a/schema/yaml.go b/schema/yaml.go index 9049b9a4..5778228e 100644 --- a/schema/yaml.go +++ b/schema/yaml.go @@ -91,7 +91,7 @@ func (m OrderedMap[K, V]) ToSlice() []OrderedMapItem[K, V] { // UnmarshalYAML implements yaml.BytesUnmarshaler interface. func (m *OrderedMap[K, V]) UnmarshalYAML(b []byte) error { var s yaml.MapSlice - if err := yaml.Unmarshal(b, &s); err != nil { + if err := yaml.UnmarshalWithOptions(b, &s, yaml.UseOrderedMap()); err != nil { return err } if len(s) == 0 {