From 9e9f306d7ad0fc87233848c6da702ac1f701d822 Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Wed, 1 Jan 2025 01:52:51 +0000 Subject: [PATCH] order metaattribute when serializing the model Signed-off-by: Doug Davis --- registry/model.go | 17 +++- tests/http_test.go | 36 ++++---- tests/model_test.go | 216 ++++++++++++++++++++++---------------------- 3 files changed, 140 insertions(+), 129 deletions(-) diff --git a/registry/model.go b/registry/model.go index d69f6c5d..95e59ff1 100644 --- a/registry/model.go +++ b/registry/model.go @@ -256,7 +256,7 @@ func (m *Model) SetSingular() { m.Attributes["$type"] = &Attribute{ Name: "$type", Type: STRING, - Description: "0", + Description: string([]rune{'0' + ENTITY_REGISTRY}), } for _, gm := range m.Groups { @@ -268,7 +268,7 @@ func (m *Model) SetSingular() { gm.Attributes["$type"] = &Attribute{ Name: "$type", Type: STRING, - Description: "1", + Description: string([]rune{'0' + ENTITY_GROUP}), } for _, rm := range gm.Resources { @@ -280,7 +280,18 @@ func (m *Model) SetSingular() { rm.Attributes["$type"] = &Attribute{ Name: "$type", Type: STRING, - Description: "2", + Description: string([]rune{'0' + ENTITY_RESOURCE}), + } + + rm.MetaAttributes["$singular"] = &Attribute{ + Name: "$singular", + Type: STRING, + Description: rm.Singular, + } + rm.MetaAttributes["$type"] = &Attribute{ + Name: "$type", + Type: STRING, + Description: string([]rune{'0' + ENTITY_META}), } } } diff --git a/tests/http_test.go b/tests/http_test.go index 6c1041c7..74ab228b 100644 --- a/tests/http_test.go +++ b/tests/http_test.go @@ -500,6 +500,12 @@ func TestHTTPModel(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -546,12 +552,6 @@ func TestHTTPModel(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -786,6 +786,12 @@ func TestHTTPModel(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -832,12 +838,6 @@ func TestHTTPModel(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -1079,6 +1079,12 @@ func TestHTTPModel(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -1125,12 +1131,6 @@ func TestHTTPModel(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } } diff --git a/tests/model_test.go b/tests/model_test.go index cf7c9a76..34d2cea4 100644 --- a/tests/model_test.go +++ b/tests/model_test.go @@ -793,6 +793,12 @@ func TestResourceModelCreate(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -839,12 +845,6 @@ func TestResourceModelCreate(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -985,6 +985,12 @@ func TestResourceModelCreate(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -1031,12 +1037,6 @@ func TestResourceModelCreate(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -1245,6 +1245,12 @@ func TestResourceModelCreate(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -1291,12 +1297,6 @@ func TestResourceModelCreate(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -1562,6 +1562,12 @@ func TestResourceModelCreate(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -1608,12 +1614,6 @@ func TestResourceModelCreate(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -1880,6 +1880,12 @@ func TestResourceModelCreate(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -1926,12 +1932,6 @@ func TestResourceModelCreate(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -2139,6 +2139,12 @@ func TestResourceModelCreate(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -2185,12 +2191,6 @@ func TestResourceModelCreate(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -2428,6 +2428,12 @@ func TestResourceModelCreate(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -2474,12 +2480,6 @@ func TestResourceModelCreate(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -2721,6 +2721,12 @@ func TestResourceModelCreate(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -2767,12 +2773,6 @@ func TestResourceModelCreate(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -3042,6 +3042,12 @@ func TestResourceModelCreate(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -3088,12 +3094,6 @@ func TestResourceModelCreate(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -3648,6 +3648,12 @@ func TestMultModelCreate(t *testing.T) { } }, "metaattributes": { + "rm1id": { + "name": "rm1id", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -3694,12 +3700,6 @@ func TestMultModelCreate(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "rm1id": { - "name": "rm1id", - "type": "string", - "immutable": true, - "serverrequired": true } } }, @@ -3780,6 +3780,12 @@ func TestMultModelCreate(t *testing.T) { } }, "metaattributes": { + "rm2id": { + "name": "rm2id", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -3826,12 +3832,6 @@ func TestMultModelCreate(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "rm2id": { - "name": "rm2id", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -3972,6 +3972,12 @@ func TestMultModelCreate(t *testing.T) { } }, "metaattributes": { + "rm1id": { + "name": "rm1id", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -4018,12 +4024,6 @@ func TestMultModelCreate(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "rm1id": { - "name": "rm1id", - "type": "string", - "immutable": true, - "serverrequired": true } } }, @@ -4104,6 +4104,12 @@ func TestMultModelCreate(t *testing.T) { } }, "metaattributes": { + "rm2id": { + "name": "rm2id", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -4150,12 +4156,6 @@ func TestMultModelCreate(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "rm2id": { - "name": "rm2id", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -4416,6 +4416,12 @@ func TestMultModel2Create(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -4462,12 +4468,6 @@ func TestMultModel2Create(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -4608,6 +4608,12 @@ func TestMultModel2Create(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -4654,12 +4660,6 @@ func TestMultModel2Create(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -5097,6 +5097,12 @@ func TestModelLabels(t *testing.T) { } }, "metaattributes": { + "rmid": { + "name": "rmid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -5143,12 +5149,6 @@ func TestModelLabels(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "rmid": { - "name": "rmid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -5366,6 +5366,12 @@ func TestModelLabels(t *testing.T) { } }, "metaattributes": { + "rmid": { + "name": "rmid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -5412,12 +5418,6 @@ func TestModelLabels(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "rmid": { - "name": "rmid", - "type": "string", - "immutable": true, - "serverrequired": true } } } @@ -5656,6 +5656,12 @@ func TestModelLabels(t *testing.T) { } }, "metaattributes": { + "fileid": { + "name": "fileid", + "type": "string", + "immutable": true, + "serverrequired": true + }, "self": { "name": "self", "type": "url", @@ -5702,12 +5708,6 @@ func TestModelLabels(t *testing.T) { "name": "defaultversionsticky", "type": "boolean", "readonly": true - }, - "fileid": { - "name": "fileid", - "type": "string", - "immutable": true, - "serverrequired": true } } }