Skip to content

Commit 6670deb

Browse files
committed
Update restdocs-api-spec to 0.8.0
support configuring description & tag descriptions from pom.xml
1 parent 18638c7 commit 6670deb

File tree

9 files changed

+53
-8
lines changed

9 files changed

+53
-8
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.cnsgithub.restdocs-spec</groupId>
88
<artifactId>restdocs-spec</artifactId>
9-
<version>0.10.3-cns</version>
9+
<version>0.10.4-cns</version>
1010
<packaging>pom</packaging>
1111

1212
<name>${project.groupId}:${project.artifactId}</name>
@@ -72,7 +72,7 @@
7272
<maven.compiler.target>1.8</maven.compiler.target>
7373
<maven.version>3.3.1</maven.version>
7474
<maven-plugin-tools.version>3.5.2</maven-plugin-tools.version>
75-
<restdocs-api-spec.version>0.5.0</restdocs-api-spec.version>
75+
<restdocs-api-spec.version>0.8.0</restdocs-api-spec.version>
7676
<junit.version>5.2.0</junit.version>
7777
<assertj.version>3.11.0</assertj.version>
7878
<mockito.version>2.21.0</mockito.version>

restdocs-spec-generator/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.github.cnsgithub.restdocs-spec</groupId>
88
<artifactId>restdocs-spec</artifactId>
9-
<version>0.10.3-cns</version>
9+
<version>0.10.4-cns</version>
1010
</parent>
1111

1212
<artifactId>restdocs-spec-generator</artifactId>

restdocs-spec-generator/src/main/java/com/berkleytechnologyservices/restdocs/spec/ApiDetails.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.berkleytechnologyservices.restdocs.spec;
22

33
import java.util.Collections;
4+
import java.util.HashMap;
45
import java.util.List;
6+
import java.util.Map;
57

68
public class ApiDetails {
79

@@ -13,11 +15,13 @@ public class ApiDetails {
1315

1416
private String name;
1517
private String version;
18+
private String description;
1619
private String host;
1720
private String basePath;
1821
private List<String> schemes;
1922
private SpecificationFormat format;
2023
private AuthConfig authConfig;
24+
private Map<String, String> tagDescriptions;
2125

2226
public ApiDetails() {
2327
this.name = DEFAULT_NAME;
@@ -27,6 +31,7 @@ public ApiDetails() {
2731
this.schemes = DEFAULT_SCHEMES;
2832
this.format = DEFAULT_FORMAT;
2933
this.authConfig = new AuthConfig();
34+
this.tagDescriptions = Collections.emptyMap();
3035
}
3136

3237
public String getName() {
@@ -47,6 +52,15 @@ public ApiDetails version(String version) {
4752
return this;
4853
}
4954

55+
public String getDescription() {
56+
return description;
57+
}
58+
59+
public ApiDetails description(String description){
60+
this.description = description;
61+
return this;
62+
}
63+
5064
public String getHost() {
5165
return host;
5266
}
@@ -91,4 +105,13 @@ public ApiDetails authConfig(AuthConfig authConfig) {
91105
this.authConfig = authConfig != null ? authConfig : new AuthConfig();
92106
return this;
93107
}
108+
109+
public Map<String, String> getTagDescriptions() {
110+
return tagDescriptions;
111+
}
112+
113+
public ApiDetails tagDescriptions(Map<String, String> tagDescriptions) {
114+
this.tagDescriptions = tagDescriptions;
115+
return this;
116+
}
94117
}

restdocs-spec-generator/src/main/java/com/berkleytechnologyservices/restdocs/spec/generator/openapi_v2/OpenApi20SpecificationGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.epages.restdocs.apispec.openapi2.OpenApi20Generator;
1212

1313
import javax.inject.Named;
14+
import java.util.HashMap;
1415
import java.util.List;
1516
import java.util.stream.Collectors;
1617

@@ -40,6 +41,8 @@ public String generate(ApiDetails details, List<ResourceModel> models) {
4041
details.getHost(),
4142
details.getSchemes(),
4243
details.getName(),
44+
details.getDescription(),
45+
details.getTagDescriptions(),
4346
details.getVersion(),
4447
SpecificationGeneratorUtils.createOauth2Configuration(details.getAuthConfig()),
4548
details.getFormat().name().toLowerCase()

restdocs-spec-generator/src/main/java/com/berkleytechnologyservices/restdocs/spec/generator/openapi_v3/OpenApi30SpecificationGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
import javax.inject.Named;
1515
import java.net.MalformedURLException;
1616
import java.net.URL;
17-
import java.util.ArrayList;
18-
import java.util.Arrays;
19-
import java.util.List;
17+
import java.util.*;
2018
import java.util.stream.Collectors;
2119

2220
@Named
@@ -52,6 +50,8 @@ public String generate(ApiDetails details, List<ResourceModel> models) {
5250
models,
5351
servers,
5452
details.getName(),
53+
details.getDescription(),
54+
details.getTagDescriptions(),
5555
details.getVersion(),
5656
SpecificationGeneratorUtils.createOauth2Configuration(details.getAuthConfig()),
5757
details.getFormat().name().toLowerCase()

restdocs-spec-generator/src/test/resources/mock-specs/default-settings-openapi3.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ info:
44
version: 1.0.0
55
servers:
66
- url: http://localhost
7+
tags: []
78
paths:
89
/book/{id}:
910
get:
@@ -17,6 +18,8 @@ paths:
1718
in: path
1819
description: The unique identifier for the book.
1920
required: true
21+
schema:
22+
type: string
2023
responses:
2124
200:
2225
description: "200"

restdocs-spec-generator/src/test/resources/mock-specs/default-settings.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ info:
33
version: 1.0.0
44
title: API Documentation
55
host: localhost
6+
tags: []
67
schemes:
78
- http
89
paths:

restdocs-spec-maven-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<parent>
99
<groupId>com.github.cnsgithub.restdocs-spec</groupId>
1010
<artifactId>restdocs-spec</artifactId>
11-
<version>0.10.3-cns</version>
11+
<version>0.10.4-cns</version>
1212
</parent>
1313

1414
<artifactId>restdocs-spec-maven-plugin</artifactId>

restdocs-spec-maven-plugin/src/main/java/com/berkleytechnologyservices/restdocs/mojo/GenerateMojo.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.ArrayList;
2222
import java.util.Collections;
2323
import java.util.List;
24+
import java.util.Map;
2425
import java.util.stream.Collectors;
2526

2627
/**
@@ -43,6 +44,12 @@ public class GenerateMojo extends AbstractMojo {
4344
@Parameter(defaultValue = "${project.version}", required = true)
4445
private String version;
4546

47+
/**
48+
* Description of the API
49+
*/
50+
@Parameter(defaultValue = "${project.description}", required = true)
51+
private String description;
52+
4653
/**
4754
* Host
4855
*/
@@ -108,6 +115,12 @@ public class GenerateMojo extends AbstractMojo {
108115
@Parameter
109116
private AuthConfig oauth2 = new AuthConfig();
110117

118+
/**
119+
* Mapping of tag names to descriptions. These are populated into the top level. {@see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#tag-object} | no default - if not provided no tags created.
120+
*/
121+
@Parameter
122+
private Map<String, String> tagDescriptions;
123+
111124
private final SnippetReader snippetReader;
112125
private final SpecificationGeneratorFactory specificationGeneratorFactory;
113126

@@ -201,11 +214,13 @@ private ApiDetails createApiDetails(SpecificationOptions options) {
201214
return new ApiDetails()
202215
.name(name)
203216
.version(version)
217+
.description(description)
204218
.host(host)
205219
.basePath(basePath)
206220
.schemes(schemes)
207221
.format(options.getFormat())
208-
.authConfig(oauth2);
222+
.authConfig(oauth2)
223+
.tagDescriptions(tagDescriptions);
209224
}
210225

211226
private List<SpecificationOptions> getAllSpecificationOptions() {

0 commit comments

Comments
 (0)