membrane / soa-model

Toolkit and Java API for WSDL, WADL and XML Schema.
http://www.membrane-soa.org/soa-model/
Apache License 2.0
94 stars 73 forks source link

SimpleType (and others?) equals isn't comprehensive #266

Open er1c opened 6 years ago

er1c commented 6 years ago

I'm still trying to understand if it's defined this way for a reason: https://github.com/membrane/soa-model/blob/062ddf7c379ca190f9d901b80dc0d48e288556b7/core/src/main/groovy/com/predic8/schema/SimpleType.groovy#L67-L73

But the equals method is ignoring the 'qname' which can cause bad evaluations...Ran into a nasty bug when trying to do a .distinct on the SimpleType collections and getting back different sizes each execution...

import com.predic8.{wsdl => w}
import scala.collection.JavaConverters._

// A good problematic API
val parsed = new w.WSDLParser().parse("http://wss.hpi.co.uk/TradeSoap/services/CoreEnquiryV1?wsdl")
val all = parsed.getSchemas.asScala.toIndexedSeq.map{ _.getAllSchemas.asScala }.head.toIndexedSeq.head.getSimpleTypes.asScala.toIndexedSeq

// Example bad equals

scala> all(0) == all(2)
res79: Boolean = true

scala> all(0)
res80: com.predic8.schema.SimpleType = SimpleType[qname={http://webservices.hpi.co.uk/CoreEnquiryV1}CustomerCodeType,restriction=Restriction[base={http://www.w3.org/2001/XMLSchema}string,facets=[com.predic8.schema.restriction.facet.MinLengthFacet@771c60a6]]]

scala> all(2)
res81: com.predic8.schema.SimpleType = SimpleType[qname={http://webservices.hpi.co.uk/CoreEnquiryV1}PasswordType,restriction=Restriction[base={http://www.w3.org/2001/XMLSchema}string,facets=[com.predic8.schema.restriction.facet.MinLengthFacet@5a9a021b]]]

I have a branch here to add (all?) of the other inherited members to the equals: https://github.com/er1c/soa-model/commit/099e1292714b6d1f5340375eecd56abc89d785d3

I'm not really sure if I should be adding all of the attributes or just the qname...the ComplexType equals is seems to be pretty light too: https://github.com/membrane/soa-model/blob/master/core/src/main/groovy/com/predic8/schema/ComplexType.groovy#L132-L146 but it's equals logic seems significantly divergent from the SimpleType