Skip to content

Commit a862b73

Browse files
authored
Merge pull request #183 from Backbase/issues/directory-inputSpec-#179
feature: allows generate::Doc to accept inputSpec as a directory
2 parents 5a87ba2 + 358394b commit a862b73

File tree

7 files changed

+746
-1
lines changed

7 files changed

+746
-1
lines changed

boat-maven-plugin/src/main/java/com/backbase/oss/boat/GenerateDocMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
@Mojo(name = "doc", threadSafe = true)
88
@Slf4j
9-
public class GenerateDocMojo extends GenerateMojo {
9+
public class GenerateDocMojo extends GenerateFromDirectoryDocMojo {
1010

1111
@Override
1212
public void execute() throws MojoExecutionException {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.backbase.oss.boat;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.apache.maven.plugin.MojoExecutionException;
5+
6+
import java.io.File;
7+
8+
/**
9+
* Allows generate::Doc to accept inputSpec as a directory
10+
* Output docs will be placed in separate folders for each spec
11+
*/
12+
@Slf4j
13+
public class GenerateFromDirectoryDocMojo extends GenerateMojo {
14+
15+
@Override
16+
public void execute() throws MojoExecutionException {
17+
18+
File inputSpecFile = new File(inputSpec);
19+
20+
if (inputSpecFile.isDirectory()){
21+
log.info("inputSpec is being read as a directory");
22+
23+
File[] inputSpecs;
24+
File outPutDirectory = output;
25+
26+
inputSpecs = inputSpecFile.listFiles(pathname -> pathname.getName().endsWith(".yaml"));
27+
28+
if (inputSpecs == null || inputSpecs.length == 0) {
29+
throw new MojoExecutionException("No OpenAPI specs found in: " + inputSpec);
30+
}
31+
32+
for(File f : inputSpecs){
33+
inputSpec = f.getPath();
34+
output = new File(outPutDirectory.getPath(),f.getName().substring(0,f.getName().lastIndexOf(".")).concat("-docs"));
35+
36+
if(!output.exists()){
37+
output.mkdir();
38+
}
39+
40+
log.info(" Generating docs for spec {} in directory", f.getName());
41+
super.execute();
42+
}
43+
44+
}else {
45+
46+
log.info("inputSpec being read as a single file");
47+
super.execute();
48+
49+
}
50+
}
51+
}

boat-maven-plugin/src/test/java/com/backbase/oss/boat/GeneratorTests.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,36 @@ void testBoatDocs() throws MojoExecutionException {
8585
assertThat(output.list()).containsExactlyInAnyOrder("index.html", ".openapi-generator-ignore", ".openapi-generator");
8686
}
8787

88+
@Test
89+
void testBoatDocsWithDirectory() throws MojoExecutionException {
90+
91+
String spec = System.getProperty("spec", getClass().getResource("/boat-doc-oas-examples").getFile());
92+
93+
log.info("Generating docs for: {}", spec);
94+
95+
GenerateDocMojo mojo = new GenerateDocMojo();
96+
File input = new File(spec);
97+
File output = new File("target/boat-docs-directory");
98+
if (!output.exists()) {
99+
output.mkdirs();
100+
}
101+
102+
DefaultBuildContext defaultBuildContext = new DefaultBuildContext();
103+
defaultBuildContext.enableLogging(new ConsoleLogger());
104+
105+
mojo.getLog();
106+
mojo.buildContext = defaultBuildContext;
107+
mojo.project = new MavenProject();
108+
mojo.inputSpec = input.getAbsolutePath();
109+
mojo.output = output;
110+
mojo.skip = false;
111+
mojo.skipIfSpecIsUnchanged = false;
112+
mojo.bundleSpecs = true;
113+
mojo.dereferenceComponents = true;
114+
mojo.execute();
115+
assertThat(output.list()).containsExactlyInAnyOrder("link-docs", "petstore-docs", "petstore-new-non-breaking-docs", "upto-docs");
116+
}
117+
88118
@Test
89119
void testBundledBoatDocs() throws MojoExecutionException, MojoFailureException {
90120

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
openapi: "3.0.0"
2+
info:
3+
title: Link Example
4+
version: 1.0.0
5+
paths:
6+
/2.0/users/{username}:
7+
get:
8+
operationId: getUserByName
9+
parameters:
10+
- name: username
11+
in: path
12+
required: true
13+
schema:
14+
type: string
15+
responses:
16+
'200':
17+
description: The User
18+
content:
19+
application/json:
20+
schema:
21+
$ref: '#/components/schemas/user'
22+
links:
23+
userRepositories:
24+
$ref: '#/components/links/UserRepositories'
25+
/2.0/repositories/{username}:
26+
get:
27+
operationId: getRepositoriesByOwner
28+
parameters:
29+
- name: username
30+
in: path
31+
required: true
32+
schema:
33+
type: string
34+
responses:
35+
'200':
36+
description: repositories owned by the supplied user
37+
content:
38+
application/json:
39+
schema:
40+
type: array
41+
items:
42+
$ref: '#/components/schemas/repository'
43+
links:
44+
userRepository:
45+
$ref: '#/components/links/UserRepository'
46+
/2.0/repositories/{username}/{slug}:
47+
get:
48+
operationId: getRepository
49+
parameters:
50+
- name: username
51+
in: path
52+
required: true
53+
schema:
54+
type: string
55+
- name: slug
56+
in: path
57+
required: true
58+
schema:
59+
type: string
60+
responses:
61+
'200':
62+
description: The repository
63+
content:
64+
application/json:
65+
schema:
66+
$ref: '#/components/schemas/repository'
67+
links:
68+
repositoryPullRequests:
69+
$ref: '#/components/links/RepositoryPullRequests'
70+
/2.0/repositories/{username}/{slug}/pullrequests:
71+
get:
72+
operationId: getPullRequestsByRepository
73+
parameters:
74+
- name: username
75+
in: path
76+
required: true
77+
schema:
78+
type: string
79+
- name: slug
80+
in: path
81+
required: true
82+
schema:
83+
type: string
84+
- name: state
85+
in: query
86+
schema:
87+
type: string
88+
enum:
89+
- open
90+
- merged
91+
- declined
92+
responses:
93+
'200':
94+
description: an array of pull request objects
95+
content:
96+
application/json:
97+
schema:
98+
type: array
99+
items:
100+
$ref: '#/components/schemas/pullrequest'
101+
/2.0/repositories/{username}/{slug}/pullrequests/{pid}:
102+
get:
103+
operationId: getPullRequestsById
104+
parameters:
105+
- name: username
106+
in: path
107+
required: true
108+
schema:
109+
type: string
110+
- name: slug
111+
in: path
112+
required: true
113+
schema:
114+
type: string
115+
- name: pid
116+
in: path
117+
required: true
118+
schema:
119+
type: string
120+
responses:
121+
'200':
122+
description: a pull request object
123+
content:
124+
application/json:
125+
schema:
126+
$ref: '#/components/schemas/pullrequest'
127+
links:
128+
pullRequestMerge:
129+
$ref: '#/components/links/PullRequestMerge'
130+
/2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge:
131+
post:
132+
operationId: mergePullRequest
133+
parameters:
134+
- name: username
135+
in: path
136+
required: true
137+
schema:
138+
type: string
139+
- name: slug
140+
in: path
141+
required: true
142+
schema:
143+
type: string
144+
- name: pid
145+
in: path
146+
required: true
147+
schema:
148+
type: string
149+
responses:
150+
'204':
151+
description: the PR was successfully merged
152+
components:
153+
links:
154+
UserRepositories:
155+
# returns array of '#/components/schemas/repository'
156+
operationId: getRepositoriesByOwner
157+
parameters:
158+
username: $response.body#/username
159+
UserRepository:
160+
# returns '#/components/schemas/repository'
161+
operationId: getRepository
162+
parameters:
163+
username: $response.body#/owner/username
164+
slug: $response.body#/slug
165+
RepositoryPullRequests:
166+
# returns '#/components/schemas/pullrequest'
167+
operationId: getPullRequestsByRepository
168+
parameters:
169+
username: $response.body#/owner/username
170+
slug: $response.body#/slug
171+
PullRequestMerge:
172+
# executes /2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge
173+
operationId: mergePullRequest
174+
parameters:
175+
username: $response.body#/author/username
176+
slug: $response.body#/repository/slug
177+
pid: $response.body#/id
178+
schemas:
179+
user:
180+
type: object
181+
properties:
182+
username:
183+
type: string
184+
uuid:
185+
type: string
186+
repository:
187+
type: object
188+
properties:
189+
slug:
190+
type: string
191+
owner:
192+
$ref: '#/components/schemas/user'
193+
pullrequest:
194+
type: object
195+
properties:
196+
id:
197+
type: integer
198+
title:
199+
type: string
200+
repository:
201+
$ref: '#/components/schemas/repository'
202+
author:
203+
$ref: '#/components/schemas/user'

0 commit comments

Comments
 (0)