Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to generate serializers for xs:choice generated code #659

Open
vidalgp opened this issue Aug 14, 2024 · 0 comments
Open

Unable to generate serializers for xs:choice generated code #659

vidalgp opened this issue Aug 14, 2024 · 0 comments

Comments

@vidalgp
Copy link

vidalgp commented Aug 14, 2024

Hi folks,

I have been trying to make this xsd schema work with no luck, and at this point I'm wondering if it is a bug or if i am missing something:

Repro Steps

define the xsd containing:

<xs:complexType name="Funky">
    <xs:sequence>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="AttributeA" type="ns:AttributeA" substitutionGroup="ns:Attribute" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="AttributeB" type="ns:AttributeB" substitutionGroup="ns:Attribute" minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
    </xs:sequence>
    <xs:attribute name="readOnly" type="xs:boolean" default="false"/>
</xs:complexType>

<xs:complexType name="AttributeA">
    <xs:complexContent>
        <xs:extension base="ns:Attribute">
            <xs:sequence>
                <xs:element name="field" type="xs:boolean"/>
            </xs:sequence>
            <xs:attribute name="uniqueForInstance" type="xs:boolean" default="false"/>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

<xs:complexType name="AttributeB">
    <xs:complexContent>
        <xs:extension base="ns:Attribute">
            <xs:sequence>
                <xs:element name="field" type="xs:boolean"/>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

<xs:complexType name="Attribute" abstract="true">
    <xs:attribute name="name" use="required" type="xs:string"/>
</xs:complexType>

Note that AttributeA and AttributeB are based on Attribute.

After running scalaxb I see this generates the following code:

case class Funky(funkyoption: Seq[scalaxb.DataRecord[model.FunkyOption]] = Nil, readOnly: Boolean = false)
trait FunkyOption
case class AttributeA(...) extends Attribute with FunkyOption
case class AttributeB(...) extends Attribute with FunkyOption

then when i go to the console I cannot reference FunkyOption getting error: not found: type FunkyOption

is this a problem?

In fact it seems that FunkyOption is completely skipped as its extended classes after a module import are defined as:

case class AttributeA(...) extends Attribute
case class AttributeB(...) extends Attribute

over xmlprotocol.scala i see this definition for Attribute parser (not sure if required for FunkyOption but it's missing):

  trait DefaultModel_FunkyFormat extends scalaxb.ElemNameParser[model.Funky] {
    ...
    override def typeName: Option[String] = Some("Funky")

    def parser(node: scala.xml.Node, stack: List[scalaxb.ElemName]): Parser[model.Funky] =
      phrase(safeRep(((scalaxb.ElemName(Some("my_ns"), "AttributeA")) ^^ 
      (x => scalaxb.DataRecord(x.namespace, Some(x.name), scalaxb.fromXML[model.AttributeA](x, scalaxb.ElemName(node) :: stack)))) | 
      ((scalaxb.ElemName(Some("my_ns"), "AttributeB")) ^^ 
      (x => scalaxb.DataRecord(x.namespace, Some(x.name), scalaxb.fromXML[model.AttributeB](x, scalaxb.ElemName(node) :: stack))))) ^^
      { case p1 =>
      model.Funky(p1,
        (node \ "@readOnly").headOption map { scalaxb.fromXML[Boolean](_, scalaxb.ElemName(node) :: stack) } getOrElse { scalaxb.fromXML[Boolean](scala.xml.Text("false"), scalaxb.ElemName(node) :: stack) }) })
    
    override def writesAttribute(__obj: model.Funky, __scope: scala.xml.NamespaceBinding): scala.xml.MetaData = {
      var attr: scala.xml.MetaData  = scala.xml.Null
      if (__obj.readOnly.toString != "false") attr = scala.xml.Attribute(null, "readOnly", __obj.readOnly.toString, attr)
      attr
    }

    def writesChildNodes(__obj: model.Funky, __scope: scala.xml.NamespaceBinding): Seq[scala.xml.Node] =
      (__obj.annotationoption flatMap { x => scalaxb.toXML[scalaxb.DataRecord[model.AnnotationOption]](x, x.namespace, x.key, __scope, false) })

  }

I saw this after a bit of debugging when I was unable to define circe codecs for my Funky case class, potentially because of missing implicit conversions, and my first clue at this point is the missing FunkyOption.

what i expect

That I have access to FunkyOption and its implicit conversions.

thanks in advance for the time and also for all the hard work with this tool!

cheers
Vidal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant