Skip to content

Commit 34056df

Browse files
authored
Merge pull request #221 from Shun-Arahata/feature/add-x-displayname-support
Add support for Redoc's x-displayName extension to tag configuration
2 parents 5f5c8c9 + b229a7f commit 34056df

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

examples/src/main/kotlin/io/github/smiley4/ktoropenapi/examples/CompleteConfig.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ private fun Application.myModule() {
9595
description = "routes to manage users"
9696
externalDocUrl = "example.com"
9797
externalDocDescription = "Users documentation"
98+
displayName = "User Management" // Redoc's x-displayName extension
9899
}
99100
tag("documents") {
100101
description = "routes to manage documents"
101102
externalDocUrl = "example.com"
102103
externalDocDescription = "Document documentation"
104+
displayName = "Document Management" // Redoc's x-displayName extension
103105
}
104106
}
105107
schemas {

ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi/builder/openapi/TagBuilder.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ internal class TagBuilder(
1818
if(tag.externalDocUrl != null && tag.externalDocDescription != null) {
1919
it.externalDocs = tagExternalDocumentationBuilder.build(tag.externalDocUrl, tag.externalDocDescription)
2020
}
21+
if(tag.displayName != null) {
22+
it.extensions = mapOf("x-displayName" to tag.displayName)
23+
}
2124
}
2225

2326
}

ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi/config/TagConfig.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,19 @@ class TagConfig internal constructor(
2929
*/
3030
var externalDocUrl: String? = null
3131

32+
/**
33+
* Custom display name for the tag. Maps to Redoc's x-displayName extension.
34+
* When defined, this name is used instead of the default name in the navigation sidebar and section headings.
35+
*/
36+
var displayName: String? = null
37+
3238

3339
internal fun build(base: TagData) = TagData(
3440
name = name,
3541
description = merge(base.description, description),
3642
externalDocDescription = merge(base.externalDocDescription, externalDocDescription),
37-
externalDocUrl = merge(base.externalDocUrl, externalDocUrl)
43+
externalDocUrl = merge(base.externalDocUrl, externalDocUrl),
44+
displayName = merge(base.displayName, displayName)
3845
)
3946

4047
}

ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi/data/TagData.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@ internal data class TagData(
77
val name: String,
88
val description: String?,
99
val externalDocDescription: String?,
10-
val externalDocUrl: String?
10+
val externalDocUrl: String?,
11+
/**
12+
* Custom display name for the tag. Maps to Redoc's x-displayName extension.
13+
* When defined, this name is used instead of the default name in the navigation sidebar and section headings.
14+
*/
15+
val displayName: String?
1116
) {
1217

1318
companion object {
1419
val DEFAULT = TagData(
1520
name = "",
1621
description = null,
1722
externalDocDescription = null,
18-
externalDocUrl = null
23+
externalDocUrl = null,
24+
displayName = null
1925
)
2026
}
2127
}

ktor-openapi/src/test/kotlin/io/github/smiley4/ktorswaggerui/builder/TagsBuilderTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ class TagsBuilderTest : StringSpec({
4040
}
4141
}
4242

43+
"tag object with x-displayName" {
44+
buildTagObject("test-tag-123") {
45+
description = "Description of tag"
46+
displayName = "Custom Display Name"
47+
}.also { tag ->
48+
tag.name shouldBe "test-tag-123"
49+
tag.description shouldBe "Description of tag"
50+
tag.extensions.shouldNotBeNull()
51+
tag.extensions["x-displayName"] shouldBe "Custom Display Name"
52+
}
53+
}
54+
4355
}) {
4456

4557
companion object {

0 commit comments

Comments
 (0)