Skip to content

Commit

Permalink
[FABCAG-31] update to use only first part of JSON tag
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Hurt <andrew.hurt1@ibm.com>
  • Loading branch information
awjh-ibm authored and jt-nti committed Oct 21, 2020
1 parent 188bfec commit 4f4fb4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 6 additions & 0 deletions metadata/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ func getField(field reflect.StructField, schema *ObjectMetadata, components *Com
name = field.Tag.Get("json")
}

if strings.Contains(name, ",") {
spl := strings.Split(name, ",")

name = spl[0]
}

if name == "" || name == "-" {
name = field.Name
}
Expand Down
16 changes: 9 additions & 7 deletions metadata/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ type simpleStruct struct {
Prop6 string `metadata:"-"`
Prop7 string `metadata:",optional"`
Prop8 string `metadata:"prop8, optional"`
Prop9 string `json:"jsonname2,omitempty"`
}

var simpleStructPropertiesMap = map[string]spec.Schema{
"Prop1": *spec.StringProperty(),
"propname": *spec.StringProperty(),
"jsonname": *spec.StringProperty(),
"Prop5": *spec.StringProperty(),
"Prop7": *spec.StringProperty(),
"prop8": *spec.StringProperty(),
"Prop1": *spec.StringProperty(),
"propname": *spec.StringProperty(),
"jsonname": *spec.StringProperty(),
"Prop5": *spec.StringProperty(),
"Prop7": *spec.StringProperty(),
"prop8": *spec.StringProperty(),
"jsonname2": *spec.StringProperty(),
}

var simpleStructMetadata = ObjectMetadata{
ID: "simpleStruct",
Properties: simpleStructPropertiesMap,
Required: []string{"Prop1", "propname", "Prop5"},
Required: []string{"Prop1", "propname", "Prop5", "jsonname2"},
AdditionalProperties: false,
}

Expand Down

0 comments on commit 4f4fb4d

Please sign in to comment.