Skip to content

Commit

Permalink
Merge pull request #525 from kchaitanya1195/default-tag-70
Browse files Browse the repository at this point in the history
Remove default tags from global level
  • Loading branch information
Javakky-pxv authored Mar 10, 2023
2 parents b947d9c + b58f7ac commit de25a72
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ lazy val playSwagger = project.in(file("core"))
Dependencies.yaml ++ Seq(
"com.github.takezoe" %% "runtime-scaladoc-reader" % "1.0.3",
"org.scalameta" %% "scalameta" % "4.7.5",
"net.steppschuh.markdowngenerator" % "markdowngenerator" % "1.3.1.1"
"net.steppschuh.markdowngenerator" % "markdowngenerator" % "1.3.1.1",
"joda-time" % "joda-time" % "2.10.6" % Test,
"com.google.errorprone" % "error_prone_annotations" % "2.17.0" % Test
),
addCompilerPlugin("com.github.takezoe" %% "runtime-scaladoc-reader" % "1.0.3"),
scalaVersion := scalaV,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,7 @@ final case class SwaggerSpecGenerator(

val definitionsJson = JsObject(definitions.map(d => d.name -> Json.toJson(d)))

// TODO: remove hardcoded path
val generatedTagsJson = JsArray(
paths.keys
// .filterNot(_ == RoutesFileReader.rootRoute)
.map(tag => Json.obj("name" -> tag)).toSeq
)

val tagsJson = mergeByName(generatedTagsJson, (baseJson \ "tags").asOpt[JsArray].getOrElse(JsArray()))

val tagsJson = (baseJson \ "tags").asOpt[JsArray].getOrElse(JsArray())
val pathsAndDefinitionsJson = Json.obj(
"paths" -> pathsJson,
if (swaggerV3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class SwaggerSpecGeneratorIntegrationSpec extends Specification {
val json = defaultRoutesFile.get
(json \ "paths" \ "/player/{pid}/context/{bid}").asOpt[JsObject] must beSome
}
"Default routes tag must not be present" >> {
val json = defaultRoutesFile.get
(json \ "tags").asOpt[JsObject] must beNone
}

lazy val json = SwaggerSpecGenerator(false, false, false, "com.iheart").generate("test.routes").get
lazy val pathJson = json \ "paths"
Expand Down Expand Up @@ -329,11 +333,29 @@ class SwaggerSpecGeneratorIntegrationSpec extends Specification {
"generate tags definition" >> {
val tags = (json \ "tags").asOpt[Seq[JsObject]]
tags must beSome[Seq[JsObject]]
tags.get.map(tO => (tO \ "name").as[String]).sorted must containAllOf(Seq(
tags.get.map(tO => (tO \ "name").as[String]).sorted must contain(exactly("player"))

val allTags =
pathJson.as[JsObject].value.values.flatMap { pathObj =>
pathObj.as[JsObject].value.values.flatMap { opObj =>
val tag = (opObj \ "tags").asOpt[Seq[String]]

tag must beSome[Seq[String]]
tag.get must have size 1
tag.get
}
}.toSet

allTags must containAllOf(Seq(
"test",
"students",
"player",
"resource",
"level2",
"customResource",
"liveMeta",
"player",
"resource"
"referencing",
"zoo"
))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ TaskKey[Unit]("check") := {
| "title":"Poweramp API",
| "description":"My API is the best"
| },
| "tags":[
| {
| "name":"${swaggerRoutesFile.value}"
| }
| ]
| "tags":[]
|}
""".stripMargin
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,7 @@ TaskKey[Unit]("check") := {
| "title":"Poweramp API",
| "description":"My API is the best"
| },
| "tags":[
| {
| "name":"${swaggerRoutesFile.value}"
| }
| ]
| "tags":[]
|}
""".stripMargin
)
Expand Down

0 comments on commit de25a72

Please sign in to comment.