From 4a78a15682ba192d397a51116d67e3e96c244c35 Mon Sep 17 00:00:00 2001 From: javakky Date: Wed, 13 Jul 2022 16:02:08 +0900 Subject: [PATCH] fix: Can include comments after NoDocsEnd --- README.md | 3 +++ .../iheart/playSwagger/SwaggerSpecGenerator.scala | 12 ++++++++++-- core/src/test/resources/liveMeta.routes | 3 +++ .../playSwagger/SwaggerSpecGeneratorSpec.scala | 7 ++++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 54c523c3..f6f3bce7 100644 --- a/README.md +++ b/README.md @@ -292,6 +292,9 @@ GET /api/hidden/a controllers.hiddenEndPointA() GET /api/hidden/b controllers.hiddenEndPointB() ### NoDocsEnd ### +### +# summary: I'm not hiding! +### GET /api/hidden/c controllers.hiddenEndPointC() ``` diff --git a/core/src/main/scala/com/iheart/playSwagger/SwaggerSpecGenerator.scala b/core/src/main/scala/com/iheart/playSwagger/SwaggerSpecGenerator.scala index 4f5c13d0..ea411e9a 100644 --- a/core/src/main/scala/com/iheart/playSwagger/SwaggerSpecGenerator.scala +++ b/core/src/main/scala/com/iheart/playSwagger/SwaggerSpecGenerator.scala @@ -17,6 +17,7 @@ import play.routes.compiler._ object SwaggerSpecGenerator { private val marker = "##" + private val noDocsEnd = s"$marker\\s*NoDocsEnd\\s*$marker#" val customMappingsFileName = "swagger-custom-mappings" val baseSpecFileName = "swagger" @@ -428,6 +429,7 @@ final case class SwaggerSpecGenerator( skipping: Boolean ): (Option[(String, JsObject)], Boolean) = { import SwaggerSpecGenerator.marker + import SwaggerSpecGenerator.noDocsEnd val comments = route.comments.map(_.comment).mkString("\n") @@ -437,7 +439,7 @@ final case class SwaggerSpecGenerator( // NoDocsStart ならスキップを開始する (None, true) } else { - val docsEnd = s"$marker\\s*NoDocsEnd\\s*$marker".r.findFirstIn(comments).isDefined + val docsEnd = noDocsEnd.r.findFirstIn(comments).isDefined // スキップ中かつ、 NoDocsEnd が指定されていないならスキップする if (!docsEnd && skipping) { (None, skipping) @@ -511,11 +513,17 @@ final case class SwaggerSpecGenerator( val jsonFromComment = { import SwaggerSpecGenerator.marker + import SwaggerSpecGenerator.noDocsEnd val comments = route.comments.map(_.comment) val commentDocLines = comments match { case `marker` +: docs :+ `marker` ⇒ docs - case _ ⇒ Nil + case first +: `marker` +: docs :+ `marker` if first.matches(noDocsEnd) ⇒ + println(docs) + docs + case docs ⇒ + println(docs) + Nil } for { diff --git a/core/src/test/resources/liveMeta.routes b/core/src/test/resources/liveMeta.routes index ba48e816..07d44df3 100644 --- a/core/src/test/resources/liveMeta.routes +++ b/core/src/test/resources/liveMeta.routes @@ -43,4 +43,7 @@ GET /api/station/hidden/a controllers.LiveMeta.hiddenEndPoi GET /api/station/hidden/b controllers.LiveMeta.hiddenEndPointB() ### NoDocsEnd ### +### +# summary: I'm not hiding! +### GET /api/station/hidden/c controllers.LiveMeta.hiddenEndPointC() diff --git a/core/src/test/scala/com/iheart/playSwagger/SwaggerSpecGeneratorSpec.scala b/core/src/test/scala/com/iheart/playSwagger/SwaggerSpecGeneratorSpec.scala index 4774cd0a..d1a2c45a 100644 --- a/core/src/test/scala/com/iheart/playSwagger/SwaggerSpecGeneratorSpec.scala +++ b/core/src/test/scala/com/iheart/playSwagger/SwaggerSpecGeneratorSpec.scala @@ -307,7 +307,12 @@ class SwaggerSpecGeneratorIntegrationSpec extends Specification { } "does generate for end points marked as finished hidden" >> { - (pathJson \ "/api/station/hidden/c" \ "get").toOption must not(beEmpty) + "not hidden" >> { + (pathJson \ "/api/station/hidden/c" \ "get").toOption must not(beEmpty) + } + "readable summary" >> { + (pathJson \ "/api/station/hidden/c" \ "get" \ "summary").asOpt[String] === Some("I'm not hiding!") + } } "generate path correctly with missing type (String by default) in controller description" >> {