diff --git a/rest/.jvm/src/test/resources/RestTestApi.json b/rest/.jvm/src/test/resources/RestTestApi.json index e0c98d5b0..8f7e08210 100644 --- a/rest/.jvm/src/test/resources/RestTestApi.json +++ b/rest/.jvm/src/test/resources/RestTestApi.json @@ -267,6 +267,56 @@ } } }, + "/groupPrefix/subget/{p1}": { + "get": { + "tags": [ + "GroupPrefix" + ], + "operationId": "groupPrefix_subget", + "parameters": [ + { + "name": "p1", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "format": "int32" + } + }, + { + "name": "X-H1", + "in": "header", + "required": true, + "schema": { + "type": "integer", + "format": "int32" + } + }, + { + "name": "q1", + "in": "query", + "required": true, + "explode": false, + "schema": { + "type": "integer", + "format": "int32" + } + } + ], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + } + } + } + } + }, "/jsonFailingGet": { "get": { "operationId": "jsonFailingGet", @@ -956,6 +1006,9 @@ "name": "Prefix", "description": "example API subgroup" }, + { + "name": "GroupPrefix" + }, { "name": "TrivialGroup" }, diff --git a/rest/src/main/scala/io/udash/rest/openapi/OpenApiMetadata.scala b/rest/src/main/scala/io/udash/rest/openapi/OpenApiMetadata.scala index ef645e03b..a656dedbc 100644 --- a/rest/src/main/scala/io/udash/rest/openapi/OpenApiMetadata.scala +++ b/rest/src/main/scala/io/udash/rest/openapi/OpenApiMetadata.scala @@ -54,12 +54,13 @@ final case class OpenApiMetadata[T]( // collect all tags private lazy val openApiTags: List[Tag] = { - def createTags(method: OpenApiMethod[_]): List[Tag] = - method.groupAnnot.fold[List[Tag]](Nil) { group => - List(method.tagAdjusters.foldLeft(Tag(group.groupName))({ case (tag, adjuster) => adjuster.adjustTag(tag) })) + def createTag(method: OpenApiMethod[_]): Opt[Tag] = + method.groupAnnot.map { group => + method.tagAdjusters.foldLeft(Tag(group.groupName))({ case (tag, adjuster) => adjuster.adjustTag(tag) }) } - prefixes.flatMap(prefix => createTags(prefix) ++ prefix.result.value.openApiTags) ++ httpMethods.flatMap(createTags) + (prefixes.iterator.flatMap(prefix => createTag(prefix).iterator ++ prefix.result.value.openApiTags.iterator) ++ + httpMethods.iterator.flatMap(createTag)).toList } def operations(resolver: SchemaResolver): Iterator[PathOperation] = diff --git a/rest/src/test/scala/io/udash/rest/RestTestApi.scala b/rest/src/test/scala/io/udash/rest/RestTestApi.scala index 8deaf1b61..492fdab4a 100644 --- a/rest/src/test/scala/io/udash/rest/RestTestApi.scala +++ b/rest/src/test/scala/io/udash/rest/RestTestApi.scala @@ -131,6 +131,9 @@ trait RestTestApi { @Query @example("q0example") q0: String ): RestTestSubApi + @group + def groupPrefix: RestTestSubApi + @Prefix("") def transparentPrefix: RestTestSubApi def complexParams( @@ -172,6 +175,7 @@ object RestTestApi extends DefaultRestApiCompanion[RestTestApi] { Future.successful(s"$q1-$p1-$p2") def prefix(p0: String, h0: String, q0: String): RestTestSubApi = RestTestSubApi.impl(s"$p0-$h0-$q0") + def groupPrefix: RestTestSubApi = RestTestSubApi.impl("") def transparentPrefix: RestTestSubApi = RestTestSubApi.impl("") def complexParams(baseEntity: BaseEntity, flatBaseEntity: Opt[FlatBaseEntity]): Future[Unit] = Future.unit def complexParams(flatBaseEntity: FlatBaseEntity, baseEntity: Opt[BaseEntity]): Future[Unit] = Future.unit