diff --git a/pkg/concepts/type.go b/pkg/concepts/type.go index f155455..2679619 100644 --- a/pkg/concepts/type.go +++ b/pkg/concepts/type.go @@ -17,7 +17,6 @@ limitations under the License. package concepts import ( - "log" "sort" "github.com/openshift-online/ocm-api-metamodel/pkg/names" @@ -193,7 +192,6 @@ func (t *Type) RemoveAttribute(name *names.Name) { } for i, attribute := range t.attributes { if attribute.Name().Equals(name) { - log.Printf("---------- Deleting attribute %s", name.String()) t.attributes = append(t.attributes[:i], t.attributes[i+1:]...) } } diff --git a/pkg/language/checks.go b/pkg/language/checks.go index e3cbe4b..31fc7f9 100644 --- a/pkg/language/checks.go +++ b/pkg/language/checks.go @@ -520,8 +520,8 @@ func (r *Reader) checkParameter(parameter *concepts.Parameter) { } if typ != nil && typ != parameter.Type() { r.reporter.Errorf( - "Type of default value of parameter '%s' should be '%s', instead it was %s", - parameter, parameter.Type(), typ.Name().String(), + "Type of default value of parameter '%s' should be '%s'", + parameter, parameter.Type(), ) } } diff --git a/pkg/language/reader.go b/pkg/language/reader.go index 8836f66..d673a79 100644 --- a/pkg/language/reader.go +++ b/pkg/language/reader.go @@ -22,6 +22,7 @@ package language import ( "fmt" "io/ioutil" + "log" "os" "path/filepath" "strconv" @@ -422,14 +423,6 @@ func (r *Reader) ExitClassDecl(ctx *ClassDeclContext) { // Add the annotations: r.addAnnotations(typ, ctx.GetAnnotations()) - // Add the attributes: - memberCtxs := ctx.GetMembers() - if len(memberCtxs) > 0 { - for _, memberCtx := range ctx.GetMembers() { - typ.AddAttribute(memberCtx.GetResult()) - } - } - if path := annotations.ReferencePath(typ); path != "" { if len(r.inputs) > 1 { panic("refernced service with multiple inputs in undefined") @@ -445,7 +438,7 @@ func (r *Reader) ExitClassDecl(ctx *ClassDeclContext) { components := strings.Split(path, "/") referencedServiceName := components[0] referencedVersion := components[1] - referencedType := components[2] + referencedTypeName := components[2] // Create an ad-hoc reader and model for the specific referenced service. refReader := NewReader(). @@ -462,31 +455,47 @@ func (r *Reader) ExitClassDecl(ctx *ClassDeclContext) { refVersion := refReader.service.FindVersion(names.ParseUsingSeparator(referencedVersion, "_")) // Once loading the service, we find the reference type // then recursively iterate the type tree and add the types to the current version. - for _, currType := range refVersion.Types() { - if strings.Compare(currType.Name().String(), referencedType) == 0 { - r.recursivelyAddTypeToVersion(currVersion, currType) + for _, referencedType := range refVersion.Types() { + if strings.Compare(referencedType.Name().String(), referencedTypeName) == 0 { + r.recursivelyAddTypeToVersion(currVersion, typ, referencedType) } } } + + // Add the attributes: + memberCtxs := ctx.GetMembers() + if len(memberCtxs) > 0 { + for _, memberCtx := range ctx.GetMembers() { + typ.AddAttribute(memberCtx.GetResult()) + } + } } // A helper function to recursively add types to a version -func (r *Reader) recursivelyAddTypeToVersion(version *concepts.Version, typ *concepts.Type) { +func (r *Reader) recursivelyAddTypeToVersion(version *concepts.Version, currType *concepts.Type, + referencedType *concepts.Type) { var attributesToRemove concepts.AttributeSlice - for _, attribute := range typ.Attributes() { + for _, attribute := range referencedType.Attributes() { // We wish to define links explicitly and not inherint them // only the attribute fields. + if currType.FindAttribute(attribute.Name()) != nil { + log.Printf("Found common attribute %s, skipping", attribute.Name().String()) + continue + } if version.FindType(attribute.Type().Name()) == nil && !attribute.Link() { - r.recursivelyAddTypeToVersion(version, attribute.Type()) + r.recursivelyAddTypeToVersion(version, currType, attribute.Type()) } if attribute.Link() { attributesToRemove = append(attributesToRemove, attribute) } } for _, attribute := range attributesToRemove { - typ.RemoveAttribute(attribute.Name()) + referencedType.RemoveAttribute(attribute.Name()) } - version.AddType(typ) + + log.Printf("Adding type %s from version %s to version %s", + referencedType.Name().String(), referencedType.Owner().Name().String(), version.Name().String()) + version.AddType(referencedType) } func (r *Reader) ExitStructDecl(ctx *StructDeclContext) {