Enum string validator fails
gipeshka opened this issue · 3 comments
gipeshka commented
Hi guys,
We currently face an issue with string enum fields.
swagger file:
paths:
/vendor:
post:
description: Common vendor search
parameters:
- name: query
description: Complex query object
in: body
required: true
schema:
"$ref": "#/definitions/VendorQuery"
...
definitions:
VendorQuery:
type: object
properties:
opening_type:
type: string
enum:
- delivery
- pickup
- open
- closed
We have a resulting type Option[VendorQueryOpening_typeOpt]
where VendorQueryOpening_typeOpt
has the following definition:
case class VendorQueryOpening_typeOpt(value: String) extends AnyVal {
override def toString = value.toString
}
We of course have a companion object as well:
object VendorQueryOpening_typeOpt {
val Delivery = new VendorQueryOpening_typeOpt("delivery")
val Pickup = new VendorQueryOpening_typeOpt("pickup")
val Open = new VendorQueryOpening_typeOpt("open")
val Closed = new VendorQueryOpening_typeOpt("closed")
implicit def stringToVendorQueryOpening_typeOpt: String => VendorQueryOpening_typeOpt = {
case "delivery" => Delivery
case "pickup" => Pickup
case "open" => Open
case "closed" => Closed
case other =>
throw new IllegalArgumentException("Couldn't parse parameter " + other)
}
}
But when one passes this opening_type
in request we see the following error:
[ClassCastException: java.lang.String cannot be cast to swagger.yaml.VendorQueryOpening_typeOpt]
In /target/scala-2.11/routes/main/validators/swagger.yaml.scala:132
class VendorQueryOpening_typeValidator(instance: VendorQueryOpening_type) extends RecursiveValidator {
override val validators = instance.toSeq.map { new VendorQueryOpening_typeOptValidator(_) }
}
When trying to instantiate VendorQueryOpening_typeOpt we get the following:
scala> import swagger.yaml.VendorQueryVendor_filter_policyOpt
import swagger.yaml.VendorQueryVendor_filter_policyOpt
scala> new VendorQueryVendor_filter_policyOpt("aaa")
java.lang.NoSuchMethodError: swagger.yaml.package$VendorQueryVendor_filter_policyOpt$.toString$extension(Ljava/lang/String;)Ljava/lang/String;
at swagger.yaml.VendorQueryVendor_filter_policyOpt.toString(swagger.yaml.scala:70)
We use scala 2.11.8 and play 2.5.10 currently.
gipeshka commented
Apparently it was fixed with df7039e#diff-0ed5297fb8a3755d03f4416dd565d273R15, wasn't it?
alexec commented
+1
slavaschmidt commented
@gipeshka yep, this should be fixed as you mentioned, just waiting for couple of other issues to make it's way into the main branch.