summaryrefslogtreecommitdiffstats
path: root/cmd/binapi-generator
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2019-07-02 11:56:56 +0200
committerOndrej Fabry <ofabry@cisco.com>2019-07-02 11:56:56 +0200
commitd3b84969e8ec5dabfd5fd3038d0fe67309c63168 (patch)
tree7f2cc9cc7ff98fdca0823ccf2d3e4bc15cec27da /cmd/binapi-generator
parenta27ced54ee2fce0f0247f5e04d911f44038a99db (diff)
Fix duplicate types
- .api.json input files from VPP now sometimes contain duplicate objects - parsing is skipped if type is already known Change-Id: Ibf28f5baa68f6cfb40aeb75e1bde72241120ac23 Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'cmd/binapi-generator')
-rw-r--r--cmd/binapi-generator/parse.go50
1 files changed, 37 insertions, 13 deletions
diff --git a/cmd/binapi-generator/parse.go b/cmd/binapi-generator/parse.go
index 0e4f3ad..8852ae2 100644
--- a/cmd/binapi-generator/parse.go
+++ b/cmd/binapi-generator/parse.go
@@ -98,7 +98,7 @@ func parsePackage(ctx *context, jsonRoot *jsongo.JSONNode) (*Package, error) {
// parse enums
enums := jsonRoot.Map(objEnums)
- pkg.Enums = make([]Enum, enums.Len())
+ pkg.Enums = make([]Enum, 0)
for i := 0; i < enums.Len(); i++ {
enumNode := enums.At(i)
@@ -106,8 +106,14 @@ func parsePackage(ctx *context, jsonRoot *jsongo.JSONNode) (*Package, error) {
if err != nil {
return nil, err
}
- pkg.Enums[i] = *enum
- pkg.RefMap[toApiType(enum.Name)] = enum.Name
+
+ enumApi := toApiType(enum.Name)
+ if _, ok := pkg.RefMap[enumApi]; ok {
+ logf("enum %v already known", enumApi)
+ continue
+ }
+ pkg.RefMap[enumApi] = enum.Name
+ pkg.Enums = append(pkg.Enums, *enum)
}
// sort enums
sort.SliceStable(pkg.Enums, func(i, j int) bool {
@@ -117,16 +123,22 @@ func parsePackage(ctx *context, jsonRoot *jsongo.JSONNode) (*Package, error) {
// parse aliases
aliases := jsonRoot.Map(objAliases)
if aliases.GetType() == jsongo.TypeMap {
- pkg.Aliases = make([]Alias, aliases.Len())
- for i, key := range aliases.GetKeys() {
+ pkg.Aliases = make([]Alias, 0)
+ for _, key := range aliases.GetKeys() {
aliasNode := aliases.At(key)
alias, err := parseAlias(ctx, key.(string), aliasNode)
if err != nil {
return nil, err
}
- pkg.Aliases[i] = *alias
- pkg.RefMap[toApiType(alias.Name)] = alias.Name
+
+ aliasApi := toApiType(alias.Name)
+ if _, ok := pkg.RefMap[aliasApi]; ok {
+ logf("alias %v already known", aliasApi)
+ continue
+ }
+ pkg.RefMap[aliasApi] = alias.Name
+ pkg.Aliases = append(pkg.Aliases, *alias)
}
}
// sort aliases to ensure consistent order
@@ -136,7 +148,7 @@ func parsePackage(ctx *context, jsonRoot *jsongo.JSONNode) (*Package, error) {
// parse types
types := jsonRoot.Map(objTypes)
- pkg.Types = make([]Type, types.Len())
+ pkg.Types = make([]Type, 0)
for i := 0; i < types.Len(); i++ {
typNode := types.At(i)
@@ -144,8 +156,14 @@ func parsePackage(ctx *context, jsonRoot *jsongo.JSONNode) (*Package, error) {
if err != nil {
return nil, err
}
- pkg.Types[i] = *typ
- pkg.RefMap[toApiType(typ.Name)] = typ.Name
+
+ typApi := toApiType(typ.Name)
+ if _, ok := pkg.RefMap[typApi]; ok {
+ logf("type %v already known", typApi)
+ continue
+ }
+ pkg.RefMap[typApi] = typ.Name
+ pkg.Types = append(pkg.Types, *typ)
}
// sort types
sort.SliceStable(pkg.Types, func(i, j int) bool {
@@ -154,7 +172,7 @@ func parsePackage(ctx *context, jsonRoot *jsongo.JSONNode) (*Package, error) {
// parse unions
unions := jsonRoot.Map(objUnions)
- pkg.Unions = make([]Union, unions.Len())
+ pkg.Unions = make([]Union, 0)
for i := 0; i < unions.Len(); i++ {
unionNode := unions.At(i)
@@ -162,8 +180,14 @@ func parsePackage(ctx *context, jsonRoot *jsongo.JSONNode) (*Package, error) {
if err != nil {
return nil, err
}
- pkg.Unions[i] = *union
- pkg.RefMap[toApiType(union.Name)] = union.Name
+
+ unionApi := toApiType(union.Name)
+ if _, ok := pkg.RefMap[unionApi]; ok {
+ logf("union %v already known", unionApi)
+ continue
+ }
+ pkg.RefMap[unionApi] = union.Name
+ pkg.Unions = append(pkg.Unions, *union)
}
// sort unions
sort.SliceStable(pkg.Unions, func(i, j int) bool {