Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
Expand All @@ -34,7 +35,7 @@ public enum Format {JSON, YAML, JSONANDYAML}

@Input
@Optional
public final Property<String> outputFileName = getProject().getObjects().property(String.class);
public final Property<String> outputFileName = getProject().getObjects().property(String.class).convention("openapi");
@OutputDirectory
public final DirectoryProperty outputDir = getProject().getObjects().directoryProperty();
@InputFile
Expand All @@ -43,7 +44,7 @@ public enum Format {JSON, YAML, JSONANDYAML}
public final RegularFileProperty openApiFile = getProject().getObjects().fileProperty();
@Input
@Optional
public final Property<Format> outputFormat = getProject().getObjects().property(Format.class);
public final Property<Format> outputFormat = getProject().getObjects().property(Format.class).convention(Format.JSON);
@Input
@Optional
public final SetProperty<String> resourcePackages = getProject().getObjects().setProperty(String.class);
Expand All @@ -61,10 +62,10 @@ public enum Format {JSON, YAML, JSONANDYAML}
public final Property<String> scannerClass = getProject().getObjects().property(String.class);
@Input
@Optional
public final Property<Boolean> prettyPrint = getProject().getObjects().property(Boolean.class);
public final Property<Boolean> prettyPrint = getProject().getObjects().property(Boolean.class).convention(false);
@Input
@Optional
public final Property<Boolean> readAllResources = getProject().getObjects().property(Boolean.class);
public final Property<Boolean> readAllResources = getProject().getObjects().property(Boolean.class).convention(false);
@Input
@Optional
public final SetProperty<String> ignoredRoutes = getProject().getObjects().setProperty(String.class);
Expand All @@ -82,11 +83,11 @@ public enum Format {JSON, YAML, JSONANDYAML}
@Deprecated
@Input
@Optional
public final Property<Boolean> skip = getProject().getObjects().property(Boolean.class);
public final Property<Boolean> skip = getProject().getObjects().property(Boolean.class).convention(false);
@Input
@Optional

public final Property<String> encoding = getProject().getObjects().property(String.class);
public final Property<String> encoding = getProject().getObjects().property(String.class).convention(Charset.defaultCharset().name());
/**
* @since 2.0.6
*/
Expand All @@ -98,29 +99,29 @@ public enum Format {JSON, YAML, JSONANDYAML}
public final Property<String> objectMapperProcessorClass = getProject().getObjects().property(String.class);
@Input
@Optional
public final Property<Boolean> sortOutput = getProject().getObjects().property(Boolean.class);
public final Property<Boolean> sortOutput = getProject().getObjects().property(Boolean.class).convention(false);
@Input
@Optional

public final Property<Boolean> alwaysResolveAppPath = getProject().getObjects().property(Boolean.class);
public final Property<Boolean> alwaysResolveAppPath = getProject().getObjects().property(Boolean.class).convention(false);
@Input
@Optional


public final Property<Boolean> skipResolveAppPath = getProject().getObjects().property(Boolean.class);
public final Property<Boolean> skipResolveAppPath = getProject().getObjects().property(Boolean.class).convention(false);
@Input
@Optional
public final Property<String> contextId = getProject().getObjects().property(String.class);
@Input
@Optional
public final Property<Boolean> openAPI31 = getProject().getObjects().property(Boolean.class);
public final Property<Boolean> openAPI31 = getProject().getObjects().property(Boolean.class).convention(false);

/**
* @since 2.2.12
*/
@Input
@Optional
public final Property<Boolean> convertToOpenAPI31 = getProject().getObjects().property(Boolean.class);
public final Property<Boolean> convertToOpenAPI31 = getProject().getObjects().property(Boolean.class).convention(false);

/**
* @since 2.2.24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,74 @@ public void testSwaggerResolveWithOAS31OptionTask() throws IOException {
assertTrue(strContent.contains("\"openapi\" : \"3.0.1\""));
}

/**
* Tests that ResolveTask works with minimal configuration, relying on
* .convention() defaults for prettyPrint, sortOutput, encoding,
* readAllResources, alwaysResolveAppPath, skipResolveAppPath,
* openAPI31, convertToOpenAPI31, outputFormat, and skip.
* This validates Gradle 9 compatibility where Property.get() on an
* unset property without a convention throws an error.
*/
@Test
public void testSwaggerResolveTaskWithConventionDefaults() throws IOException {
outputDir = testProjectDir.toString() + "/target";
String resolveTask = "resolve";

String buildFileContent =
"plugins {\n" +
" id 'java'\n" +
" id 'io.swagger.core.v3.swagger-gradle-plugin'\n" +
"}\n" +
"sourceSets {\n" +
" test {\n" +
" java {\n" +
" srcDirs('" + toNormalizedPath(new File("src/test/java").getAbsolutePath()) + "')\n" +
" exclude('**/*Test.java')\n" +
" }\n" +
" }\n" +
"}\n" +
"repositories {\n" +
" mavenLocal()\n" +
" mavenCentral()\n" +
"}\n" +
"dependencies { \n" +
" implementation 'io.swagger.core.v3:swagger-jaxrs2:2.2.47-SNAPSHOT'\n" +
" implementation 'javax.ws.rs:javax.ws.rs-api:2.1'\n" +
" implementation 'javax.servlet:javax.servlet-api:3.1.0'\n" +
"}\n" +
resolveTask + " {\n" +
" outputFileName = 'PetStoreAPIDefaults'\n" +
" classpath = sourceSets.test.runtimeClasspath\n" +
" resourcePackages = ['io.swagger.v3.plugins.gradle.petstore']\n" +
" outputPath = \'" + toNormalizedPath(outputDir) + "\'\n" +
"}";

String settingsFileContent = "pluginManagement {\n" +
" repositories {\n" +
" maven {\n" +
" url mavenLocal().url\n" +
" }\n" +
" mavenCentral()\n" +
" gradlePluginPortal()\n" +
" }\n" +
"}\n" +
"rootProject.name = 'gradle-test'\n" +
"\n";
writeFile(buildFile, buildFileContent);
writeFile(settingsFile, settingsFileContent);

BuildResult result = GradleRunner.create()
.withPluginClasspath()
.withProjectDir(testProjectDir.toFile())
.withDebug(true)
.withArguments(resolveTask, "--stacktrace", "--info")
.forwardOutput()
.build();

assertTrue(result.taskPaths(SUCCESS).contains(format(":%s", resolveTask)));
assertTrue(new File(outputDir + "/PetStoreAPIDefaults.json").exists());
}

private static void writeFile(Path destination, String content) throws IOException {
try (BufferedWriter output = new BufferedWriter(new FileWriter(destination.toFile()))) {
output.write(content);
Expand Down