Skip to content

Commit 9edc991

Browse files
pgcartermduesterhoeft
authored andcommitted
Add optional description attributes for Open API (#67)
Open API plugin will accept an optional description attribute to populate the description attribute in the Info Object of the generated specification Implements issue #66
1 parent 5409de8 commit 9edc991

File tree

12 files changed

+27
-3
lines changed

12 files changed

+27
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,15 @@ openapi { //6
111111
host = 'localhost:8080'
112112
basePath = '/api'
113113
title = 'My API'
114+
description = 'My API description'
114115
version = '1.0.0'
115116
format = 'json'
116117
}
117118
118119
openapi3 {
119120
server = 'https://localhost:8080'
120121
title = 'My API'
122+
description = 'My API description'
121123
version = '0.1.0'
122124
format = 'yaml'
123125
}
@@ -329,6 +331,7 @@ The `restdocs-api-spec-gradle-plugin` takes the following configuration options
329331
Name | Description | Default value
330332
---- | ----------- | -------------
331333
title | The title of the application. Used for the `title` attribute in the [Info object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#info-object) | `API documentation`
334+
description | A description of the application. Used for the `description` attribute in the [Info object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#info-object) | empty
332335
version | The version of the api. Used for the `version` attribute in the [Info object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#info-object) | project version
333336
format | The format of the output OpenAPI file - supported values are `json` and `yaml` | `json`
334337
separatePublicApi | Should the plugin generate an additional OpenAPI specification file that does not contain the resources marked as private | `false`

restdocs-api-spec-gradle-plugin/src/main/kotlin/com/epages/restdocs/apispec/gradle/OpenApi3Task.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ open class OpenApi3Task : OpenApiBaseTask() {
2222
resources = resourceModels,
2323
servers = servers,
2424
title = title,
25+
description = apiDescription,
2526
version = apiVersion,
2627
oauth2SecuritySchemeDefinition = oauth2SecuritySchemeDefinition,
2728
format = format

restdocs-api-spec-gradle-plugin/src/main/kotlin/com/epages/restdocs/apispec/gradle/OpenApiBaseTask.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ abstract class OpenApiBaseTask : ApiSpecTask() {
88
@Optional
99
lateinit var title: String
1010

11+
@Input
12+
@Optional
13+
var apiDescription: String? = null
14+
1115
@Input
1216
@Optional
1317
lateinit var apiVersion: String
@@ -26,6 +30,7 @@ abstract class OpenApiBaseTask : ApiSpecTask() {
2630
format = extension.format
2731
oauth2SecuritySchemeDefinition = extension.oauth2SecuritySchemeDefinition
2832
title = extension.title
33+
apiDescription = extension.description
2934
apiVersion = extension.version
3035
}
3136
}

restdocs-api-spec-gradle-plugin/src/main/kotlin/com/epages/restdocs/apispec/gradle/OpenApiExtension.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ abstract class OpenApiBaseExtension(project: Project) : ApiSpecExtension(project
1616

1717
var title = "API documentation"
1818
var version = project.version as? String ?: "1.0.0"
19+
var description: String? = null
1920

2021
var format = "json"
2122

restdocs-api-spec-gradle-plugin/src/main/kotlin/com/epages/restdocs/apispec/gradle/OpenApiTask.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ open class OpenApiTask : OpenApiBaseTask() {
3131
host = host,
3232
schemes = schemes.toList(),
3333
title = title,
34+
description = apiDescription,
3435
version = apiVersion,
3536
oauth2SecuritySchemeDefinition = oauth2SecuritySchemeDefinition,
3637
format = format

restdocs-api-spec-gradle-plugin/src/test/kotlin/com/epages/restdocs/apispec/gradle/RestdocsOpenApi3TaskTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class RestdocsOpenApi3TaskTest : RestdocsOpenApiTaskTestBase() {
108108
openapi3 {
109109
servers = [ { url = "http://some.api" } ]
110110
title = '$title'
111+
description = '$description'
111112
version = '$version'
112113
format = '$format'
113114
separatePublicApi = $separatePublicApi

restdocs-api-spec-gradle-plugin/src/test/kotlin/com/epages/restdocs/apispec/gradle/RestdocsOpenApiTaskTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class RestdocsOpenApiTaskTest : RestdocsOpenApiTaskTestBase() {
1717
basePath = '$basePath'
1818
schemes = ${schemes.joinToString(",", "['", "']")}
1919
title = '$title'
20+
description = '$description'
2021
version = '$version'
2122
format = '$format'
2223
separatePublicApi = $separatePublicApi

restdocs-api-spec-gradle-plugin/src/test/kotlin/com/epages/restdocs/apispec/gradle/RestdocsOpenApiTaskTestBase.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ abstract class RestdocsOpenApiTaskTestBase {
2929
var schemes: Array<String> = arrayOf("http")
3030

3131
var title = "API documentation"
32+
var description = "the description for the API"
3233
var version = "1.0.0"
3334

3435
var format = "json"

restdocs-api-spec-openapi-generator/src/main/kotlin/com/epages/restdocs/apispec/openapi2/OpenApi20Generator.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ object OpenApi20Generator {
4343
host: String = "localhost",
4444
schemes: List<String> = listOf("http"),
4545
title: String = "API",
46+
description: String? = null,
4647
version: String = "1.0.0",
4748
oauth2SecuritySchemeDefinition: Oauth2Configuration? = null
4849
): Swagger {
@@ -53,6 +54,7 @@ object OpenApi20Generator {
5354
this.schemes(schemes.map { Scheme.forValue(it) })
5455
info = Info().apply {
5556
this.title = title
57+
this.description = description
5658
this.version = version
5759
}
5860
paths = generatePaths(
@@ -75,11 +77,12 @@ object OpenApi20Generator {
7577
host: String = "localhost",
7678
schemes: List<String> = listOf("http"),
7779
title: String = "API",
80+
description: String? = null,
7881
version: String = "1.0.0",
7982
oauth2SecuritySchemeDefinition: Oauth2Configuration? = null,
8083
format: String
8184
): String {
82-
val specification = generate(resources, basePath, host, schemes, title, version, oauth2SecuritySchemeDefinition)
85+
val specification = generate(resources, basePath, host, schemes, title, description, version, oauth2SecuritySchemeDefinition)
8386
return ApiSpecificationWriter.serialize(format, specification)
8487
}
8588

restdocs-api-spec-openapi-generator/src/test/kotlin/com/epages/restdocs/apispec/openapi2/OpenApi20GeneratorTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ class OpenApi20GeneratorTest {
142142
"http://example.com/token",
143143
"http://example.com/authorize",
144144
arrayOf("application", "accessCode")
145-
)
145+
),
146+
description = "API description"
146147
)
147148

148149
println(ApiSpecificationWriter.serialize("yaml", openapi))

0 commit comments

Comments
 (0)