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

Fix copypasta in JacksonGenerator causing maps to be lists #281

Merged
merged 1 commit into from
May 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mainClass in assembly := Some("com.twilio.guardrail.CLI")
// (filename, prefix, tracing)
def sampleResource(name: String): java.io.File = file(s"modules/sample/src/main/resources/${name}")
val exampleCases: List[(java.io.File, String, Boolean, List[String])] = List(
(sampleResource("additional-properties.yaml"), "additionalProperties", false, List.empty),
(sampleResource("alias.yaml"), "alias", false, List.empty),
(sampleResource("contentType-textPlain.yaml"), "tests.contentTypes.textPlain", false, List.empty),
(sampleResource("custom-header-type.yaml"), "tests.customTypes.customHeader", false, List.empty),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,15 @@ object JacksonGenerator {
}
tpe.map((_, Option.empty))
case SwaggerUtil.DeferredArray(tpeName) =>
safeParseType(s"java.util.List<${tpeName}>").map((_, Option.empty))
for {
fqListType <- safeParseClassOrInterfaceType("java.util.List")
innerType <- safeParseType(tpeName)
} yield (fqListType.setTypeArguments(innerType), Option.empty)
case SwaggerUtil.DeferredMap(tpeName) =>
safeParseType(s"java.util.List<${tpeName}>").map((_, Option.empty))
for {
fqMapType <- safeParseClassOrInterfaceType("java.util.Map")
innerType <- safeParseType(tpeName)
} yield (fqMapType.setTypeArguments(STRING_TYPE, innerType), Option.empty)
}
(tpe, classDep) = tpeClassDep

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package core.Jackson

import additionalProperties.client.dropwizard.definitions.{Foo, FooMapValues}
import java.util
import org.scalatest.{FreeSpec, Matchers}

class Issue263 extends FreeSpec with Matchers {
"additionalProperties with a $ref should emit a Map" in {
val stuff = new util.HashMap[String, FooMapValues]
stuff.put("yeah", new FooMapValues.Builder("no", 42).build())
val foo = new Foo.Builder().withStuff(stuff).build()
assert(classOf[util.Map[String, FooMapValues]].isAssignableFrom(foo.getStuff.getClass))
}
}
28 changes: 28 additions & 0 deletions modules/sample/src/main/resources/additional-properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
openapi: 3.0.1
info:
title: Whatever
version: 1.0.0
paths: {}
components:
schemas:
FooMapValues:
type: object
required:
- foo
- bar
properties:
foo:
type: string
bar:
type: integer
format: int32
Foo:
type: object
required:
- stuff
properties:
stuff:
type: object
additionalProperties:
$ref: "#/components/schemas/FooMapValues"