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

nillable complex type used as SOAP header generates broken code (Digikey WSDL) #229

Closed
joescii opened this Issue Dec 5, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@joescii
Contributor

joescii commented Dec 5, 2013

I have a WSDL that causes scalaxb to generate code which doesn't compile.

steps

$ git clone https://github.com/barnesjd/digikey-WSDL
$ cd digikey-WSDL/
$ sbt compile
    <wsdl:message name="IService_CreateBillOfMaterials_InputMessage_Headers">
        <wsdl:part name="Security" element="tns:Security"/>
        <wsdl:part name="Locale" element="tns:Locale"/>
    </wsdl:message>
    <xs:complexType name="Security">
        <xs:sequence>
            <xs:element name="AuthenticationToken" nillable="true" type="xs:string"/>
            <xs:element name="PartnerID" nillable="true" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    <xs:element name="Security" nillable="true" type="tns:Security"/>

problems

It generates six expressions in xmlprotocol.scala which should be wrapped as an Option:

[error] C:\Users\jbarnes\code\pcb-poc\target\scala-2.10\src_managed\main\sbt-scalaxb\com\digikey\xmlprotocol.scala:99: type mismatch;
[error]  found   : com.digikey.Security
[error]  required: Option[com.digikey.Security]
[error]               scalaxb.fromXML[com.digikey.Security]((<x>{header}</x> \ "Security").head),
[error]                                                    ^
[error] C:\Users\jbarnes\code\pcb-poc\target\scala-2.10\src_managed\main\sbt-scalaxb\com\digikey\xmlprotocol.scala:109: type mismatch;
[error]  found   : com.digikey.Security
[error]  required: Option[com.digikey.Security]
[error]               scalaxb.fromXML[com.digikey.Security]((<x>{header}</x> \ "Security").head),
[error]                                                    ^
[error] C:\Users\jbarnes\code\pcb-poc\target\scala-2.10\src_managed\main\sbt-scalaxb\com\digikey\xmlprotocol.scala:119: type mismatch;
[error]  found   : com.digikey.Security
[error]  required: Option[com.digikey.Security]
[error]               scalaxb.fromXML[com.digikey.Security]((<x>{header}</x> \ "Security").head),
[error]                                                    ^
[error] C:\Users\jbarnes\code\pcb-poc\target\scala-2.10\src_managed\main\sbt-scalaxb\com\digikey\xmlprotocol.scala:129: type mismatch;
[error]  found   : com.digikey.Security
[error]  required: Option[com.digikey.Security]
[error]               scalaxb.fromXML[com.digikey.Security]((<x>{header}</x> \ "Security").head),
[error]                                                    ^
[error] C:\Users\jbarnes\code\pcb-poc\target\scala-2.10\src_managed\main\sbt-scalaxb\com\digikey\xmlprotocol.scala:145: type mismatch;
[error]  found   : com.digikey.Security
[error]  required: Option[com.digikey.Security]
[error]               scalaxb.fromXML[com.digikey.Security]((<x>{header}</x> \ "Security").head)))
[error]                                                    ^
[error] C:\Users\jbarnes\code\pcb-poc\target\scala-2.10\src_managed\main\sbt-scalaxb\com\digikey\xmlprotocol.scala:154: type mismatch;
[error]  found   : com.digikey.Security
[error]  required: Option[com.digikey.Security]
[error]               scalaxb.fromXML[com.digikey.Security]((<x>{header}</x> \ "Security").head),
[error]                                                    ^

notes

The WSDL is located at the following URL, but beware that it is under development and may not match what is in the previous git repo: https://servicestest.digikey.com/DKServices/?wsdl

Here's one of the errors:

      def createBillOfMaterials(value: com.digikey.CreateBillOfMaterials, security: Option[com.digikey.Security], locale: Option[com.digikey.Locale]): Either[scalaxb.Soap11Fault[Any], com.digikey.CreateBillOfMaterialsOutput] = 
....
          case Right((header, body)) =>
            Right(com.digikey.CreateBillOfMaterialsOutput(scalaxb.fromXML[com.digikey.CreateBillOfMaterialsResponse](body.headOption getOrElse {body}),
              scalaxb.fromXML[com.digikey.Security]((<x>{header}</x> \ "Security").head),
              scalaxb.fromXML[com.digikey.Locale]((<x>{header}</x> \ "Locale").head)))
        }

This conflicts with the definition of CreateBillOfMaterialsOutput.

case class CreateBillOfMaterialsOutput(value: com.digikey.CreateBillOfMaterialsResponse, security: Option[com.digikey.Security], locale: Option[com.digikey.Locale])

@ghost ghost assigned eed3si9n Jan 5, 2014

@eed3si9n eed3si9n closed this in 9c4ad3c Jan 5, 2014

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Jan 5, 2014

Owner

1.1.3-SNAPSHOT now produces:

      def createBillOfMaterials(value: com.digikey.CreateBillOfMaterials, security: Option[com.digikey.Security], locale: Option[com.digikey.Locale]): Either[scalaxb.Soap11Fault[Any], com.digikey.CreateBillOfMaterialsOutput] = 
....
          case Right((header, body)) =>
            Right(com.digikey.CreateBillOfMaterialsOutput(scalaxb.fromXML[com.digikey.CreateBillOfMaterialsResponse]((body.headOption getOrElse {body}), Nil),
              (<x>{header}</x> \ "Security").head.nilOption map { scalaxb.fromXML[com.digikey.Security](_, Nil) },
              (<x>{header}</x> \ "Locale").head.nilOption map { scalaxb.fromXML[com.digikey.Locale](_, Nil) }))
        }
Owner

eed3si9n commented Jan 5, 2014

1.1.3-SNAPSHOT now produces:

      def createBillOfMaterials(value: com.digikey.CreateBillOfMaterials, security: Option[com.digikey.Security], locale: Option[com.digikey.Locale]): Either[scalaxb.Soap11Fault[Any], com.digikey.CreateBillOfMaterialsOutput] = 
....
          case Right((header, body)) =>
            Right(com.digikey.CreateBillOfMaterialsOutput(scalaxb.fromXML[com.digikey.CreateBillOfMaterialsResponse]((body.headOption getOrElse {body}), Nil),
              (<x>{header}</x> \ "Security").head.nilOption map { scalaxb.fromXML[com.digikey.Security](_, Nil) },
              (<x>{header}</x> \ "Locale").head.nilOption map { scalaxb.fromXML[com.digikey.Locale](_, Nil) }))
        }
@joescii

This comment has been minimized.

Show comment
Hide comment
@joescii

joescii Jan 10, 2014

Contributor

You rock as always, Eugene. Drinks are on me if we ever run into one another.

BTW, did you notice that a lot of stuff in the generated code are typed Option[Option[T]]? Obviously I can work with it, but just thought I'd point that out to ya.

Contributor

joescii commented Jan 10, 2014

You rock as always, Eugene. Drinks are on me if we ever run into one another.

BTW, did you notice that a lot of stuff in the generated code are typed Option[Option[T]]? Obviously I can work with it, but just thought I'd point that out to ya.

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Jan 11, 2014

Owner

To encode optional and nillable type, Option[Option[T]] is unavoidable so that it can round trip back to the identical XML document as absurd as it looks in Scala. The alternative would be to implement nillable optional.

Owner

eed3si9n commented Jan 11, 2014

To encode optional and nillable type, Option[Option[T]] is unavoidable so that it can round trip back to the identical XML document as absurd as it looks in Scala. The alternative would be to implement nillable optional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment