Skip to content

Commit

Permalink
fix: Can include comments after NoDocsEnd
Browse files Browse the repository at this point in the history
  • Loading branch information
Javakky-pxv committed Jul 13, 2022
1 parent 08d129a commit 4a78a15
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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")

Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions core/src/test/resources/liveMeta.routes
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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" >> {
Expand Down

0 comments on commit 4a78a15

Please sign in to comment.