diff --git a/tools/maven-plugin/src/main/java/io/smallrye/openapi/mavenplugin/GenerateSchemaMojo.java b/tools/maven-plugin/src/main/java/io/smallrye/openapi/mavenplugin/GenerateSchemaMojo.java index 664f58544..072356fe4 100644 --- a/tools/maven-plugin/src/main/java/io/smallrye/openapi/mavenplugin/GenerateSchemaMojo.java +++ b/tools/maven-plugin/src/main/java/io/smallrye/openapi/mavenplugin/GenerateSchemaMojo.java @@ -23,10 +23,11 @@ import java.util.Set; import java.util.stream.Stream; +import javax.inject.Inject; + import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -190,7 +191,7 @@ public class GenerateSchemaMojo extends AbstractMojo { /** * To specify a custom OpenAPI version. */ - @Parameter(defaultValue = SmallRyeOASConfig.Defaults.VERSION, property = "openApiVersion") + @Parameter(property = "openApiVersion") private String openApiVersion; @Parameter(property = "infoTitle") @@ -272,15 +273,18 @@ enum OutputFileFilter { @Parameter(property = "outputFileTypeFilter", defaultValue = "ALL") private String outputFileTypeFilter; - @Component private MavenDependencyIndexCreator mavenDependencyIndexCreator; - - @Component - MavenProjectHelper mavenProjectHelper; + private MavenProjectHelper mavenProjectHelper; @Parameter(defaultValue = "${project}", required = true, readonly = true) private MavenProject mavenProject; + @Inject + public GenerateSchemaMojo(MavenProjectHelper helper, MavenDependencyIndexCreator indexCreator) { + mavenDependencyIndexCreator = indexCreator; + mavenProjectHelper = helper; + } + @Override public void execute() throws MojoExecutionException { if (!skip) { diff --git a/tools/maven-plugin/src/test/java/io/smallrye/openapi/mavenplugin/BasicIT.java b/tools/maven-plugin/src/test/java/io/smallrye/openapi/mavenplugin/BasicIT.java index b08bb7848..e004b2cde 100644 --- a/tools/maven-plugin/src/test/java/io/smallrye/openapi/mavenplugin/BasicIT.java +++ b/tools/maven-plugin/src/test/java/io/smallrye/openapi/mavenplugin/BasicIT.java @@ -98,6 +98,16 @@ void outputFileTypeFilter_Json(MavenExecutionResult result) throws IOException { deleteDirectory(OUTPUT_FILE_TYPE_FILTER_GENERATION_PATH); } + @MavenTest + void versionFromProperties(MavenExecutionResult result) throws IOException { + + assertThat(result).isSuccessful(); + + testSchema(result, (schema) -> { + assertEquals("3.1.1", schema.getOpenapi()); + }); + } + private static final Path OUTPUT_FILE_TYPE_FILTER_GENERATION_PATH = Paths.get(System.getProperty("java.io.tmpdir"), "smallrye-openapi", "maven-plugin", "it"); diff --git a/tools/maven-plugin/src/test/resources-its/io/smallrye/openapi/mavenplugin/BasicIT/versionFromProperties/pom.xml b/tools/maven-plugin/src/test/resources-its/io/smallrye/openapi/mavenplugin/BasicIT/versionFromProperties/pom.xml new file mode 100644 index 000000000..1c9e52b89 --- /dev/null +++ b/tools/maven-plugin/src/test/resources-its/io/smallrye/openapi/mavenplugin/BasicIT/versionFromProperties/pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + + io.smallrye.openapi.mavenplugin + versionFromProperties + 1.0 + jar + + + Smallrye OpenAPI + 2.1.15 + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + generate-schema + + + ${infoTitle} + ${infoVersion} + UTF-8 + ${basedir}/src/main/resources/application.properties + + + + + diff --git a/tools/maven-plugin/src/test/resources-its/io/smallrye/openapi/mavenplugin/BasicIT/versionFromProperties/src/main/resources/META-INF/openapi.yaml b/tools/maven-plugin/src/test/resources-its/io/smallrye/openapi/mavenplugin/BasicIT/versionFromProperties/src/main/resources/META-INF/openapi.yaml new file mode 100644 index 000000000..af86d05c3 --- /dev/null +++ b/tools/maven-plugin/src/test/resources-its/io/smallrye/openapi/mavenplugin/BasicIT/versionFromProperties/src/main/resources/META-INF/openapi.yaml @@ -0,0 +1,3 @@ +openapi: "3.0.3" +info: + x-custom-extension: My Custom Extension diff --git a/tools/maven-plugin/src/test/resources-its/io/smallrye/openapi/mavenplugin/BasicIT/versionFromProperties/src/main/resources/application.properties b/tools/maven-plugin/src/test/resources-its/io/smallrye/openapi/mavenplugin/BasicIT/versionFromProperties/src/main/resources/application.properties new file mode 100644 index 000000000..3378e8470 --- /dev/null +++ b/tools/maven-plugin/src/test/resources-its/io/smallrye/openapi/mavenplugin/BasicIT/versionFromProperties/src/main/resources/application.properties @@ -0,0 +1 @@ +mp.openapi.extensions.smallrye.openapi=3.1.1