File tree Expand file tree Collapse file tree 11 files changed +195
-13
lines changed
restdocs-spec-maven-plugin/src
main/java/com/berkleytechnologyservices/restdocs Expand file tree Collapse file tree 11 files changed +195
-13
lines changed Original file line number Diff line number Diff line change @@ -76,13 +76,54 @@ There are several other aspects you can optionally configure. Here is the full
7676 <skip >false</skip >
7777 <format >JSON</format >
7878 <filename >openapi-2.0</filename >
79+ <oauth2 />
7980 </configuration >
8081 </execution >
8182 </executions >
8283 </plugin >
8384```
8485
85- # Still in development
86+ ### OAuth2 Configuration
87+
88+ By default the plugin will not generate any security information. You can optionally provide
89+ it using the ` <oauth2 /> ` element. Here is an example:
90+
91+ ``` xml
92+ <plugin >
93+ <groupId >com.github.berkleytechnologyservices.restdocs-spec</groupId >
94+ <artifactId >restdocs-spec-maven-plugin</artifactId >
95+ <version >${restdocs-spec.version}</version >
96+ <executions >
97+ <execution >
98+ <goals >
99+ <goal >generate</goal >
100+ </goals >
101+ <configuration >
102+ <oauth >
103+ <tokenUrl >http://example.com/uaa/token</tokenUrl >
104+ <authorizationUrl >http://example.com/uaa/authorize</authorizationUrl >
105+ <flows >
106+ <flow >accessCode</flow >
107+ <flow >implicit</flow >
108+ </flows >
109+ <scopes >
110+ <scope >
111+ <name >read</name >
112+ <description >Access to read operations.</description >
113+ </scope >
114+ <scope >
115+ <name >write</name >
116+ <description >Access to write operations.</description >
117+ </scope >
118+ </scopes >
119+ </oauth >
120+ </configuration >
121+ </execution >
122+ </executions >
123+ </plugin >
124+ ```
125+
126+ ## Still in development
86127
87128* Support for additional specification formats is currently in development. We plan to add
88129 support for OpenAPI 3.0 and Postman Collections.
Original file line number Diff line number Diff line change 3131 <maven .compiler.target>1.8</maven .compiler.target>
3232 <maven .version>3.3.1</maven .version>
3333 <maven-plugin-tools .version>3.5.2</maven-plugin-tools .version>
34- <restdocs-openapi .version>0.2.5 </restdocs-openapi .version>
34+ <restdocs-openapi .version>0.2.8 </restdocs-openapi .version>
3535 <junit .version>5.2.0</junit .version>
3636 <assertj .version>3.11.0</assertj .version>
3737 <mockito .version>2.21.0</mockito .version>
Original file line number Diff line number Diff line change 33 xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
44 <modelVersion >4.0.0</modelVersion >
55
6- <groupId >com.berkleytechnologyservices.restdocs.it</groupId >
7- <artifactId >simple -it</artifactId >
6+ <groupId >com.github. berkleytechnologyservices.restdocs-spec .it</groupId >
7+ <artifactId >default-settings -it</artifactId >
88 <version >1.0-SNAPSHOT</version >
99
10- <description >A simple IT verifying the basic use case .</description >
10+ <description >Verify the default settings .</description >
1111
1212 <properties >
1313 <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
Original file line number Diff line number Diff line change 44 <modelVersion >4.0.0</modelVersion >
55
66 <groupId >com.berkleytechnologyservices.restdocs.it</groupId >
7- <artifactId >simple -it</artifactId >
7+ <artifactId >json-format -it</artifactId >
88 <version >1.0-SNAPSHOT</version >
99
10- <description >A simple IT verifying the basic use case .</description >
10+ <description >Verify using json as the specification format .</description >
1111
1212 <properties >
1313 <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
5050 <snippetsDirectory >${project.basedir} /snippets</snippetsDirectory >
5151 <filename >sample-api-spec</filename >
5252 <format >JSON</format >
53+ <oauth2 >
54+ <tokenUrl >https://example.org/uaa/token</tokenUrl >
55+ <authorizationUrl >https://example.org/uaa/authorize</authorizationUrl >
56+ <flows >
57+ <flow >accessCode</flow >
58+ <flow >password</flow >
59+ </flows >
60+ <scopes >
61+ <scope >
62+ <name >write:cart</name >
63+ <description >Write cart to the database.</description >
64+ </scope >
65+ <scope >
66+ <name >read:cart</name >
67+ <description >Read cart from the database.</description >
68+ </scope >
69+ </scopes >
70+ </oauth2 >
5371 </configuration >
5472 </execution >
5573 </executions >
Original file line number Diff line number Diff line change 1919 "requestParameters" : [ ],
2020 "requestFields" : [ ],
2121 "example" : null ,
22- "securityRequirements" : null
22+ "securityRequirements" : {
23+ "type" : " OAUTH2" ,
24+ "requiredScopes" : [
25+ " read:cart"
26+ ]
27+ }
2328 },
2429 "response" : {
2530 "status" : 200 ,
Original file line number Diff line number Diff line change 1313 "requestParameters" : [ ],
1414 "requestFields" : [ ],
1515 "example" : null ,
16- "securityRequirements" : null
16+ "securityRequirements" : {
17+ "type" : " OAUTH2" ,
18+ "requiredScopes" : [
19+ " write:cart"
20+ ]
21+ }
1722 },
1823 "response" : {
1924 "status" : 201 ,
Original file line number Diff line number Diff line change 11package com .berkleytechnologyservices .restdocs .mojo ;
22
33import com .berkleytechnologyservices .restdocs .spec .ApiDetails ;
4+ import com .berkleytechnologyservices .restdocs .spec .AuthConfig ;
45import com .berkleytechnologyservices .restdocs .spec .Specification ;
56import com .berkleytechnologyservices .restdocs .spec .SpecificationFormat ;
67import com .berkleytechnologyservices .restdocs .spec .generator .SpecificationGeneratorException ;
@@ -100,6 +101,9 @@ public class GenerateMojo extends AbstractMojo {
100101 @ Parameter
101102 private List <SpecificationOptions > specifications = Collections .emptyList ();
102103
104+ @ Parameter
105+ private AuthConfig oauth2 = new AuthConfig ();
106+
103107 private final SnippetReader snippetReader ;
104108 private final SpecificationGeneratorFactory specificationGeneratorFactory ;
105109
@@ -188,7 +192,8 @@ private ApiDetails createApiDetails(SpecificationOptions options) {
188192 .host (host )
189193 .basePath (basePath )
190194 .schemes (schemes )
191- .format (options .getFormat ());
195+ .format (options .getFormat ())
196+ .authConfig (oauth2 );
192197 }
193198
194199 private List <SpecificationOptions > getAllSpecificationOptions () {
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ public class ApiDetails {
1717 private String basePath ;
1818 private List <String > schemes ;
1919 private SpecificationFormat format ;
20+ private AuthConfig authConfig ;
2021
2122 public ApiDetails () {
2223 this .name = DEFAULT_NAME ;
@@ -25,6 +26,7 @@ public ApiDetails() {
2526 this .basePath = null ;
2627 this .schemes = DEFAULT_SCHEMES ;
2728 this .format = DEFAULT_FORMAT ;
29+ this .authConfig = new AuthConfig ();
2830 }
2931
3032 public String getName () {
@@ -80,4 +82,13 @@ public ApiDetails format(SpecificationFormat format) {
8082 this .format = format != null ? format : DEFAULT_FORMAT ;
8183 return this ;
8284 }
85+
86+ public AuthConfig getAuthConfig () {
87+ return this .authConfig ;
88+ }
89+
90+ public ApiDetails authConfig (AuthConfig authConfig ) {
91+ this .authConfig = authConfig != null ? authConfig : new AuthConfig ();
92+ return this ;
93+ }
8394}
Original file line number Diff line number Diff line change 1+ package com .berkleytechnologyservices .restdocs .spec ;
2+
3+ import java .util .Collections ;
4+ import java .util .List ;
5+
6+ public class AuthConfig {
7+
8+ private String tokenUrl ;
9+ private String authorizationUrl ;
10+ private List <String > flows ;
11+ private List <Scope > scopes ;
12+
13+ public AuthConfig () {
14+ this .flows = Collections .emptyList ();
15+ this .scopes = Collections .emptyList ();
16+ }
17+
18+ public String getTokenUrl () {
19+ return tokenUrl ;
20+ }
21+
22+ public void setTokenUrl (String tokenUrl ) {
23+ this .tokenUrl = tokenUrl ;
24+ }
25+
26+ public String getAuthorizationUrl () {
27+ return authorizationUrl ;
28+ }
29+
30+ public void setAuthorizationUrl (String authorizationUrl ) {
31+ this .authorizationUrl = authorizationUrl ;
32+ }
33+
34+ public List <String > getFlows () {
35+ return flows ;
36+ }
37+
38+ public void setFlows (List <String > flows ) {
39+ this .flows = flows != null ? Collections .unmodifiableList (flows ) : Collections .emptyList ();
40+ }
41+
42+ public List <Scope > getScopes () {
43+ return scopes ;
44+ }
45+
46+ public void setScopes (List <Scope > scopes ) {
47+ this .scopes = scopes != null ? Collections .unmodifiableList (scopes ) : Collections .emptyList ();
48+ }
49+ }
Original file line number Diff line number Diff line change 1+ package com .berkleytechnologyservices .restdocs .spec ;
2+
3+ public class Scope {
4+
5+ private String name ;
6+ private String description ;
7+
8+ public String getName () {
9+ return name ;
10+ }
11+
12+ public void setName (String name ) {
13+ this .name = name ;
14+ }
15+
16+ public String getDescription () {
17+ return description ;
18+ }
19+
20+ public void setDescription (String description ) {
21+ this .description = description ;
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments