From f41001a5460a162be30107036acd78feebeebd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Luka=C5=A1=C3=ADk?= Date: Sat, 15 Jan 2022 15:53:01 +0100 Subject: [PATCH] Refactor: Extact method: isElementInlined --- pkg/xsd/schema.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/xsd/schema.go b/pkg/xsd/schema.go index 7e2af6c..9c2ed4e 100644 --- a/pkg/xsd/schema.go +++ b/pkg/xsd/schema.go @@ -264,6 +264,16 @@ func (sch *Schema) registerImportedModule(module *Schema) { // Some elements are not defined at the top-level, rather these are inlined in the complexType definitions func (sch *Schema) registerInlinedElement(el *Element, parentElement *Element) { + if sch.isElementInlined(el) { + if el.Name == "" { + panic("Not implemented: found inlined xsd:element without @name attribute") + } + el.prefixNameWithParent(parentElement) + sch.inlinedElements = append(sch.inlinedElements, *el) + } +} + +func (sch *Schema) isElementInlined(el *Element) bool { found := false for idx := range sch.Elements { e := &sch.Elements[idx] @@ -272,13 +282,7 @@ func (sch *Schema) registerInlinedElement(el *Element, parentElement *Element) { break } } - if !found { - if el.Name == "" { - panic("Not implemented: found inlined xsd:element without @name attribute") - } - el.prefixNameWithParent(parentElement) - sch.inlinedElements = append(sch.inlinedElements, *el) - } + return !found } type Import struct {