[AAI] implement OpenAPI definition of APIs aai-graphadmin module 81/140681/1 1.16.0
authoratul.m.singh <atul.m.singh@accenture.com>
Thu, 10 Apr 2025 11:09:45 +0000 (16:39 +0530)
committeratul.m.singh <atul.m.singh@accenture.com>
Thu, 10 Apr 2025 11:09:45 +0000 (16:39 +0530)
- Implemented OpenAPI definition of APIs for graphadmin module so that all Web Service requests and responses detailed specification will be specified

Issue-ID: AAI-4154
Change-Id: I55611f05dea3f95e18c5d82cc7e06143637d081c
Signed-off-by: atul.m.singh <atul.m.singh@accenture.com>
pom.xml
src/main/java/org/onap/aai/config/SecurityConfig.java
src/main/java/org/onap/aai/config/SwaggerConfig.java [new file with mode: 0644]
src/main/resources/application.properties
src/test/java/org/onap/aai/config/SwaggerConfigTest.java [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index 91dedea..f5d7dcd 100755 (executable)
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.16.0-SNAPSHOT</version>
+        <version>1.16.0</version>
     </parent>
     <groupId>org.onap.aai.graphadmin</groupId>
     <artifactId>aai-graphadmin</artifactId>
@@ -56,7 +56,7 @@
         <docker.push.registry>localhost:5000</docker.push.registry>
         <aai.docker.version>1.0.0</aai.docker.version>
         <aai.schema.service.version>1.12.7</aai.schema.service.version>
-        <aai.common.version>1.16.0-SNAPSHOT</aai.common.version>
+        <aai.common.version>1.16.0</aai.common.version>
         <aai.build.directory>${project.build.directory}/${project.artifactId}-${project.version}-build/
         </aai.build.directory>
         <aai.docker.namespace>onap</aai.docker.namespace>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-security</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
+            <version>2.0.2</version>
+        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-validation</artifactId>
index 6673f37..da1a620 100644 (file)
@@ -40,12 +40,12 @@ public class SecurityConfig {
     @Bean
     SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception{
         httpSecurity.csrf(csrf -> csrf.disable())
-            .authorizeHttpRequests(requests -> requests
-                .requestMatchers(antMatcher("/util/echo"), antMatcher("/actuator/**"))
-                .permitAll()
-                .anyRequest()
-                .authenticated())
-            .httpBasic();
+                .authorizeHttpRequests(requests -> requests
+                        .requestMatchers(antMatcher("/util/echo"), antMatcher("/actuator/**"), antMatcher("/graphadmin-api-docs/**"), antMatcher("/swagger-ui/**"), antMatcher("/swagger-ui.html"), antMatcher("/swagger-ui/index.html"))
+                        .permitAll()
+                        .anyRequest()
+                        .authenticated())
+                .httpBasic();
 
         return httpSecurity.build();
     }
@@ -53,13 +53,14 @@ public class SecurityConfig {
     @Bean
     InMemoryUserDetailsManager userDetailsService(AuthProperties userProperties) {
         UserDetails[] users = userProperties.getUsers().stream()
-            .map(user -> User.withDefaultPasswordEncoder()
-                .username(user.getUsername())
-                .password(user.getPassword())
-                .roles("someRole")
-                .build())
-            .toArray(UserDetails[]::new);
+                .map(user -> User.withDefaultPasswordEncoder()
+                        .username(user.getUsername())
+                        .password(user.getPassword())
+                        .roles("someRole")
+                        .build())
+                .toArray(UserDetails[]::new);
 
         return new InMemoryUserDetailsManager(users);
     }
 }
+
diff --git a/src/main/java/org/onap/aai/config/SwaggerConfig.java b/src/main/java/org/onap/aai/config/SwaggerConfig.java
new file mode 100644 (file)
index 0000000..48ca42e
--- /dev/null
@@ -0,0 +1,43 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2025 Deutsche Telekom. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai.config;
+
+import io.swagger.v3.oas.models.OpenAPI;
+import io.swagger.v3.oas.models.info.Contact;
+import io.swagger.v3.oas.models.info.Info;
+import io.swagger.v3.oas.models.info.License;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class SwaggerConfig {
+
+    @Bean
+    public OpenAPI customOpenAPI() {
+        return new OpenAPI()
+                .info(new Info()
+                .title("Graphadmin API - Schema Job Status")
+                .description("This API provides operations related to the schema job status for Graphadmin. " +
+                "It allows users to check if the schema has been initialized and other related tasks.")
+                .version("v1.0"));
+    }
+
+}
\ No newline at end of file
index 0c40eb2..c94b6e4 100644 (file)
@@ -98,3 +98,8 @@ aai.graph.properties.path=${server.local.startpath}/etc/appprops/janusgraph-real
 aai.basic-auth.enabled=true
 aai.basic-auth.users[0].username=AAI
 aai.basic-auth.users[0].password=AAI
+
+# Configure the path for Swagger UI
+springdoc.swagger-ui.path=/index.html
+# Configure the path for API Docs
+springdoc.api-docs.path=/graphadmin-api-docs
\ No newline at end of file
diff --git a/src/test/java/org/onap/aai/config/SwaggerConfigTest.java b/src/test/java/org/onap/aai/config/SwaggerConfigTest.java
new file mode 100644 (file)
index 0000000..7ced557
--- /dev/null
@@ -0,0 +1,52 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2025 Deutsche Telekom. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai.config;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.web.servlet.MockMvc;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
+
+@SpringBootTest
+@AutoConfigureMockMvc
+public class SwaggerConfigTest {
+
+    @Autowired
+    private MockMvc mockMvc;
+
+    @Test
+    public void testSwaggerUiPageLoads() throws Exception {
+        mockMvc.perform(get("/swagger-ui/index.html"))
+                .andExpect(status().isOk()); // Should now be 200 if permitted
+    }
+
+    @Test
+    public void testOpenApiDocsAvailable() throws Exception {
+        mockMvc.perform(get("/graphadmin-api-docs"))
+                .andExpect(status().isOk())
+                .andExpect(content().contentType("application/json"));
+    }
+}
\ No newline at end of file