From 6472fe3a2e642b2f219271829996265a7b61d40d Mon Sep 17 00:00:00 2001 From: ko_oler <kooler89@gmail.com> Date: Sat, 1 Jul 2023 13:18:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BB=D0=B5=20Metadata=20=D0=B2=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=20Schema=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8=20=D0=BE=D1=82=D0=BB=D0=B8=D1=87=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D1=81=D0=BA=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BB=D0=BB?= =?UTF-8?q?=D0=B5=D0=BA=D1=86=D0=B8=D0=B8=20=D0=BE=D1=82=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BB=D0=BB=D0=B5=D0=BA=D1=86=D0=B8=D0=B9=20=D1=83=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D1=80=D0=B0=D1=81=D1=88=D0=B8=D1=80=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=BF=D1=80=D0=B8=20=D0=B8=D1=85=20=D0=BE=D0=B1=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8,=20=D0=B2=20=D1=81?= =?UTF-8?q?=D0=BB=D1=83=D1=87=D0=B0=D0=B5=20=D0=B5=D1=81=D0=BB=D0=B8=20?= =?UTF-8?q?=D0=B8=D1=85=20id=20=D1=81=D0=BE=D0=B2=D0=BF=D0=B0=D0=B4=D0=B0?= =?UTF-8?q?=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/schema/schema.go | 8 +++++--- pkg/schema/schema_json.go | 18 +++++------------- pkg/schema/test/object_test.go | 5 ++++- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index e0eca6b6..ab9b7e95 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -12,7 +12,8 @@ import ( type Schema struct { field.Field - Loaded bool `json:"loaded"` + Loaded bool `json:"loaded"` + Metadata map[string]string `json:"metadata"` } func New(kv ...interface{}) *Schema { @@ -33,8 +34,9 @@ var ( func (s *Schema) Clone(reset bool) *Schema { return &Schema{ - Field: *s.Field.Clone(reset), - Loaded: s.Loaded, + Field: *s.Field.Clone(reset), + Loaded: s.Loaded, + Metadata: s.Metadata, } } diff --git a/pkg/schema/schema_json.go b/pkg/schema/schema_json.go index 906acb5d..72b4ac25 100644 --- a/pkg/schema/schema_json.go +++ b/pkg/schema/schema_json.go @@ -6,8 +6,8 @@ import ( ) type jsonSchema struct { - //Field json.RawMessage `json:"field,inline"` - Loaded bool `json:"loaded"` + Loaded bool `json:"loaded"` + Metadata map[string]string `json:"metadata"` } func (s *Schema) UnmarshalJSON(b []byte) error { @@ -17,20 +17,12 @@ func (s *Schema) UnmarshalJSON(b []byte) error { return errors.Wrapf(err, "error unmarshal json into field") } s.Loaded = j.Loaded + s.Metadata = j.Metadata if err := s.Field.UnmarshalJSON(b); err != nil { return err } - //if len(j.Field) > 0 { - // if err := s.Field.UnmarshalJSON(j.Field); err != nil { - // return err - // } - // //if err := jsoniter.Unmarshal(j.Field, &s.Field); err != nil { - // // return err - // //} - //} - return nil } @@ -42,8 +34,8 @@ func (s *Schema) MarshalJSON() ([]byte, error) { } jsonSch, err := jsoniter.Marshal(jsonSchema{ - //Field: b, - Loaded: s.Loaded, + Loaded: s.Loaded, + Metadata: s.Metadata, }) if err != nil { return nil, err diff --git a/pkg/schema/test/object_test.go b/pkg/schema/test/object_test.go index e5af975c..e70aa6a3 100644 --- a/pkg/schema/test/object_test.go +++ b/pkg/schema/test/object_test.go @@ -110,10 +110,13 @@ func TestSchema_JSON(t *testing.T) { "evaluatedField", field.String(modify.Value("stringField2 + '_' ")), ) sch.Loaded = true + sch.Metadata = map[string]string{ + "extension": "perxisweb", + } b, err := json.MarshalIndent(sch, "", " ") require.NoError(t, err) - //fmt.Println(string(b)) + fmt.Println(string(b)) res := schema.New() err = json.Unmarshal(b, res) -- GitLab