Skip to content

Commit

Permalink
order metaattribute when serializing the model
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Davis <[email protected]>
  • Loading branch information
duglin committed Jan 1, 2025
1 parent 40d13de commit 9e9f306
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 129 deletions.
17 changes: 14 additions & 3 deletions registry/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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}),
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions tests/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,12 @@ func TestHTTPModel(t *testing.T) {
}
},
"metaattributes": {
"fileid": {
"name": "fileid",
"type": "string",
"immutable": true,
"serverrequired": true
},
"self": {
"name": "self",
"type": "url",
Expand Down Expand Up @@ -546,12 +552,6 @@ func TestHTTPModel(t *testing.T) {
"name": "defaultversionsticky",
"type": "boolean",
"readonly": true
},
"fileid": {
"name": "fileid",
"type": "string",
"immutable": true,
"serverrequired": true
}
}
}
Expand Down Expand Up @@ -786,6 +786,12 @@ func TestHTTPModel(t *testing.T) {
}
},
"metaattributes": {
"fileid": {
"name": "fileid",
"type": "string",
"immutable": true,
"serverrequired": true
},
"self": {
"name": "self",
"type": "url",
Expand Down Expand Up @@ -832,12 +838,6 @@ func TestHTTPModel(t *testing.T) {
"name": "defaultversionsticky",
"type": "boolean",
"readonly": true
},
"fileid": {
"name": "fileid",
"type": "string",
"immutable": true,
"serverrequired": true
}
}
}
Expand Down Expand Up @@ -1079,6 +1079,12 @@ func TestHTTPModel(t *testing.T) {
}
},
"metaattributes": {
"fileid": {
"name": "fileid",
"type": "string",
"immutable": true,
"serverrequired": true
},
"self": {
"name": "self",
"type": "url",
Expand Down Expand Up @@ -1125,12 +1131,6 @@ func TestHTTPModel(t *testing.T) {
"name": "defaultversionsticky",
"type": "boolean",
"readonly": true
},
"fileid": {
"name": "fileid",
"type": "string",
"immutable": true,
"serverrequired": true
}
}
}
Expand Down
Loading

0 comments on commit 9e9f306

Please sign in to comment.