Adding maven swagger plugin 38/142038/3 master
authormithun.menon@t-systems.com <mithun.menon@t-systems.com>
Wed, 17 Sep 2025 10:45:35 +0000 (12:45 +0200)
committermithun.menon@t-systems.com <mithun.menon@t-systems.com>
Wed, 17 Sep 2025 11:36:30 +0000 (13:36 +0200)
- To add swagger plugin for aai-babel
Issue-ID: AAI-4205
Change-Id: I10df04bc71abc236c44ae7856525f1931e57aaf3
Signed-off-by: mithun.menon@t-systems.com <mithun.menon@t-systems.com>
pom.xml
src/main/java/org/onap/aai/babel/BabelApplication.java
src/main/java/org/onap/aai/babel/service/GenerateArtifactsController.java
src/main/java/org/onap/aai/babel/service/InfoService.java

diff --git a/pom.xml b/pom.xml
index 9bffd77..265743a 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                <logback.version>1.4.14</logback.version>
                <logstash.logback.encoder.version>6.6</logstash.logback.encoder.version>
                <slf4j.api.version>2.0.9</slf4j.api.version>
                <logback.version>1.4.14</logback.version>
                <logstash.logback.encoder.version>6.6</logstash.logback.encoder.version>
                <slf4j.api.version>2.0.9</slf4j.api.version>
+               <swagger.version>2.2.35</swagger.version>
        </properties>
 
        <profiles>
        </properties>
 
        <profiles>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-server</artifactId>
                </dependency>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-server</artifactId>
                </dependency>
+               <dependency>
+                       <groupId>io.swagger.core.v3</groupId>
+                       <artifactId>swagger-jaxrs2-jakarta</artifactId>
+                       <version>${swagger.version}</version>
+               </dependency>
        </dependencies>
        <build>
                <plugins>
        </dependencies>
        <build>
                <plugins>
                                <groupId>org.sonarsource.scanner.maven</groupId>
                                <artifactId>sonar-maven-plugin</artifactId>
                        </plugin>
                                <groupId>org.sonarsource.scanner.maven</groupId>
                                <artifactId>sonar-maven-plugin</artifactId>
                        </plugin>
+                       <plugin>
+                               <groupId>io.swagger.core.v3</groupId>
+                               <artifactId>swagger-maven-plugin-jakarta</artifactId>
+                               <version>${swagger.version}</version>
+                               <executions>
+                                       <execution>
+                                               <id>generate-openapi</id>
+                                               <phase>prepare-package</phase>
+                                               <goals>
+                                                       <goal>resolve</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <attachSwaggerArtifact>false</attachSwaggerArtifact>
+                                                       <outputPath>${project.build.directory}/generated-swagger-docs</outputPath>
+                                                       <outputFileName>openapi</outputFileName>
+                                                       <outputFormat>JSON</outputFormat>
+                                                       <resourcePackages>
+                                                               <resourcePackage>org.onap.aai.babel</resourcePackage>
+                                                       </resourcePackages>
+                                                       <prettyPrint>true</prettyPrint>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+                       </plugin>
                        <!-- end removable sonar config, note the additional exclusion for babel above -->
                </plugins>
        </build>
 
                        <!-- end removable sonar config, note the additional exclusion for babel above -->
                </plugins>
        </build>
 
-</project>
\ No newline at end of file
+</project>
index 3270af5..66e2561 100644 (file)
@@ -28,12 +28,22 @@ import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.ImportResource;
 
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.ImportResource;
 
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.info.Info;
+
 @SpringBootApplication
 @ImportResource("classpath:babel-beans.xml")
 @ComponentScan(basePackages = {
         "org.onap.aai.aaf",
         "org.onap.aai.babel"
 })
 @SpringBootApplication
 @ImportResource("classpath:babel-beans.xml")
 @ComponentScan(basePackages = {
         "org.onap.aai.aaf",
         "org.onap.aai.babel"
 })
+@OpenAPIDefinition(
+  info = @Info(
+    title = "ONAP AAI Babel APIs",
+    description = "Generates AAI model XML from SDC TOSCA artifacts",
+    version = "1.0.0"
+  )
+)
 public class BabelApplication extends SpringBootServletInitializer {
 
     private static ConfigurableApplicationContext context;
 public class BabelApplication extends SpringBootServletInitializer {
 
     private static ConfigurableApplicationContext context;
index f45d2cc..69b3ef2 100644 (file)
@@ -29,14 +29,30 @@ import jakarta.ws.rs.core.Response;
 import org.onap.aai.auth.AAIAuthException;
 import org.onap.aai.babel.service.data.BabelRequest;
 
 import org.onap.aai.auth.AAIAuthException;
 import org.onap.aai.babel.service.data.BabelRequest;
 
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.parameters.RequestBody;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.tags.Tag;
+
 /** Generate artifacts from the specified request content */
 @Path("/app")
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 @FunctionalInterface
 /** Generate artifacts from the specified request content */
 @Path("/app")
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 @FunctionalInterface
+@Tag(name = "Babel Services", description = "APIs for generating artifacts from TOSCA models in AAI Babel")
 public interface GenerateArtifactsController {
 
     @POST
     @Path("/generateArtifacts")
 public interface GenerateArtifactsController {
 
     @POST
     @Path("/generateArtifacts")
-    Response generateArtifacts(BabelRequest babelRequest) throws AAIAuthException;
+    @Operation(summary = "Generate artifacts", description = "Takes a BabelRequest containing TOSCA service model artifacts and generates AAI-compatible artifacts.", responses = {
+            @ApiResponse(responseCode = "200", description = "Artifacts generated successfully", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Response.class))),
+            @ApiResponse(responseCode = "400", description = "Invalid request or malformed input"),
+            @ApiResponse(responseCode = "401", description = "Unauthorized (authentication failure)"),
+            @ApiResponse(responseCode = "500", description = "Internal server error during artifact generation")
+    })
+    Response generateArtifacts(
+            @RequestBody(required = true, description = "The BabelRequest containing TOSCA service model artifacts.", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = BabelRequest.class))) BabelRequest babelRequest)
+            throws AAIAuthException;
 }
 }
index 4621bad..409c17f 100644 (file)
@@ -33,13 +33,18 @@ import jakarta.ws.rs.Produces;
 import jakarta.ws.rs.QueryParam;
 import org.springframework.stereotype.Service;
 
 import jakarta.ws.rs.QueryParam;
 import org.springframework.stereotype.Service;
 
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+
 /**
 /**
- * Information service for the micro-service. Return status details to the caller.
+ * Information service for the micro-service. Return status details to the
+ * caller.
  *
  * @exclude
  */
 @Path("/core/core-service")
 @Service
  *
  * @exclude
  */
 @Path("/core/core-service")
 @Service
+@Tag(name = "Babel Info Service", description = "Provides uptime and status information for the Babel micro-service.")
 public class InfoService {
 
     private Clock clock = Clock.systemDefaultZone();
 public class InfoService {
 
     private Clock clock = Clock.systemDefaultZone();
@@ -53,6 +58,7 @@ public class InfoService {
     @GET
     @Path("/info")
     @Produces("text/plain")
     @GET
     @Path("/info")
     @Produces("text/plain")
+    @Operation(summary = "Get Babel service status", description = "Returns uptime, start time, and request count information for the Babel micro-service.")
     public String getInfo(@DefaultValue("text") @QueryParam("format") String format) {
         return "Status: Up\n" + statusReport(clock) + "\n";
     }
     public String getInfo(@DefaultValue("text") @QueryParam("format") String format) {
         return "Status: Up\n" + statusReport(clock) + "\n";
     }