I'm trying to make version dynamic in below annotation.
@SpringBootApplication
@OpenAPIDefinition(info = @Info(title = "Test APIs", version = "${project.version}", description = "Testing APIs"))
public class DemoApplication {
}
Here I want to make version dynamic so it will take value from pom.xml file.
Do I need to have any configuration for that? TIA.
You can define the OpenAPIDefinition programatically and use the BuildProperties to set OpenAPIDefinition.info data like this:
@SpringBootApplication
public class ApiApplication {
@Autowired
private BuildProperties buildProperties;
public static void main(String[] args) {
SpringApplication.run(ApiApplication.class, args);
}
@Bean
OpenAPI customOpenAPI() {
return new OpenAPI()
.components(new Components())
.info(new Info()
.title(buildProperties.getArtifact() + " API")
.version(buildProperties.getVersion())
.description(buildProperties.getArtifact() + " - API Swagger documentation")
.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
}
You'll need add the 'build-info' goal in the 'spring-boot-maven-plugin' into pom.xml file in order to use de BuildProperties component in your code:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With