-
Notifications
You must be signed in to change notification settings - Fork 131
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
ParametricTypeNamesTransformer doesn't update $ref fields in body parameters #355
Comments
Assuming I've identified an actual bug in the impl, I went ahead and made a locally modified version which seems to solve my issue: class MyParametricTypeNamesTransformer extends OutputTransformer with LazyLogging {
override def apply(obj: JsObject): Try[JsObject] = Success(tf(obj))
private def tf(obj: JsObject): JsObject = {
val normalizedFields = obj.fields.map {
case (key, obj: JsObject) => (normalize(key), tf(obj))
case (key, JsString(value)) => (normalize(key), JsString(normalize(value)))
case (key, ary: JsArray) => (normalize(key), normalizeAry(ary))
case (key, other) => (normalize(key), other)
case e => e
}
JsObject( normalizedFields )
}
private def normalizeAry(ary: JsArray): JsArray = {
val normalized: Seq[JsValue] = ary.value.map {
case o: JsObject => tf(o)
case a: JsArray => normalizeAry(a)
case JsString(s) => JsString(normalize(s))
case other => other
}.toSeq
JsArray(normalized)
}
private final def normalize(s: String): String = {
logger.info(s"normalize: ${s}")
s match {
case ParametricType.ParametricTypeClassName(className, argsGroup) =>
val normalizedArgs =
argsGroup
.split(",")
.iterator
.map(_.trim)
.map(normalize)
.mkString("_")
s"$className-$normalizedArgs"
case n => n
}
}
}
With this change, my swagger UI seems to be happy and all my models appear to be rendering correctly. I can submit a pull request for this if I'm not misunderstanding something. |
+1, I see the same issue with play-java. In my case, it is not able to generate any parameters for GET.
sbt.build
@gavares |
you can submit PR directly :) |
Sure, I suppose I was worried because there is the explicit test to ensure that arrays are ignored in ParametricTypeNamesTransformerSpec. I'll create a PR. |
@gavares |
play-swagger version: 0.10.2-PLAY2.8
Given a routes file like:
The generated swagger.json does not properly replace the parameterized
CustomResource[model.MySpec]
in the body parameter. The generated schema definition does have the parameterized definition rendered properly. The output looks like:I've looked into the code for ParametricTypeNamesTransformer the
tf
function is defined as:Because the parameters section is defined as an array, they will never get
normalize
ed by the tf function as defined above. This seems to be the desired behavior as specified in ParametricTypeNamesTransformerSpec.The result is swagger that cannot be rendered by the swagger ui and, I suspect, won't be useable by code generators as well.
The text was updated successfully, but these errors were encountered: