Skip to content

Commit b604668

Browse files
committed
open-api: support 3.1.0
- fix #3759
1 parent 6611bc7 commit b604668

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

modules/jooby-gradle-plugin/src/main/java/io/jooby/gradle/OpenAPITask.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class OpenAPITask extends BaseTask {
3535

3636
private String excludes;
3737

38+
private String specVersion;
39+
3840
/**
3941
* Generate OpenAPI files from Jooby application.
4042
*
@@ -67,6 +69,7 @@ public void generate() throws Throwable {
6769
tool.setClassLoader(classLoader);
6870
tool.setOutputDir(outputDir);
6971
tool.setSources(sources);
72+
tool.setSpecVersion(specVersion);
7073
trim(includes).ifPresent(tool::setIncludes);
7174
trim(excludes).ifPresent(tool::setExcludes);
7275

@@ -157,6 +160,22 @@ public void setExcludes(@Nullable String excludes) {
157160
this.excludes = excludes;
158161
}
159162

163+
164+
/**
165+
* Get the OpenAPI spec version. One of <code>3.0.1</code>, <code>3.1.0</code>.
166+
*
167+
* @return The OpenAPI spec version. One of <code>3.0.1</code>, <code>3.1.0</code>.
168+
*/
169+
@Input
170+
@org.gradle.api.tasks.Optional
171+
public String getSpecVersion() {
172+
return specVersion;
173+
}
174+
175+
public void setSpecVersion(String specVersion) {
176+
this.specVersion = specVersion;
177+
}
178+
160179
private Optional<String> trim(String value) {
161180
if (value == null || value.trim().length() == 0) {
162181
return Optional.empty();

modules/jooby-maven-plugin/src/main/java/io/jooby/maven/OpenAPIMojo.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public class OpenAPIMojo extends BaseMojo {
4444
@Parameter(property = "openAPI.excludes")
4545
private String excludes;
4646

47+
@Parameter(property = "openAPI.specVersion")
48+
private String specVersion;
49+
4750
@Override
4851
protected void doExecute(@NonNull List<MavenProject> projects, @NonNull String mainClass)
4952
throws Exception {
@@ -61,6 +64,9 @@ protected void doExecute(@NonNull List<MavenProject> projects, @NonNull String m
6164
getLog().debug("Source directories: " + sources);
6265

6366
OpenAPIGenerator tool = new OpenAPIGenerator();
67+
if (specVersion != null) {
68+
tool.setSpecVersion(specVersion);
69+
}
6470
tool.setClassLoader(classLoader);
6571
tool.setOutputDir(outputDir);
6672
tool.setSources(sources);
@@ -117,4 +123,12 @@ public void setIncludes(@Nullable String includes) {
117123
public void setExcludes(@Nullable String excludes) {
118124
this.excludes = excludes;
119125
}
126+
127+
public String getSpecVersion() {
128+
return specVersion;
129+
}
130+
131+
public void setSpecVersion(String specVersion) {
132+
this.specVersion = specVersion;
133+
}
120134
}

modules/jooby-openapi/src/main/java/io/jooby/openapi/OpenAPIGenerator.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,20 @@ public void setSpecVersion(SpecVersion specVersion) {
442442
this.specVersion = specVersion;
443443
}
444444

445+
public void setSpecVersion(String version) {
446+
if (specVersion != null) {
447+
switch (version) {
448+
case "v3.1", "v3.1.0", "3.1", "3.1.0":
449+
setSpecVersion(SpecVersion.V31);
450+
case "v3.0", "v3.0.0", "3.0", "3.0.0", "v3.0.1", "3.0.1":
451+
setSpecVersion(SpecVersion.V30);
452+
default:
453+
throw new IllegalArgumentException(
454+
"Invalid spec version: " + version + ". Supported version: [3.0.1, 3.1.0]");
455+
}
456+
}
457+
}
458+
445459
private String appname(String classname) {
446460
String name = classname;
447461
int i = name.lastIndexOf('.');

0 commit comments

Comments
 (0)