From: atul.m.singh Date: Thu, 10 Apr 2025 11:09:45 +0000 (+0530) Subject: [AAI] implement OpenAPI definition of APIs aai-graphadmin module X-Git-Tag: 1.16.0^0 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=5951ddb3d6a92e82fac2dbb29dad084e3c1fd540;p=aai%2Fgraphadmin.git [AAI] implement OpenAPI definition of APIs aai-graphadmin module - 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 --- diff --git a/pom.xml b/pom.xml index 91dedea..f5d7dcd 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.onap.aai.aai-common aai-parent - 1.16.0-SNAPSHOT + 1.16.0 org.onap.aai.graphadmin aai-graphadmin @@ -56,7 +56,7 @@ localhost:5000 1.0.0 1.12.7 - 1.16.0-SNAPSHOT + 1.16.0 ${project.build.directory}/${project.artifactId}-${project.version}-build/ onap @@ -538,6 +538,11 @@ org.springframework.boot spring-boot-starter-security + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.0.2 + org.springframework.boot spring-boot-starter-validation diff --git a/src/main/java/org/onap/aai/config/SecurityConfig.java b/src/main/java/org/onap/aai/config/SecurityConfig.java index 6673f37..da1a620 100644 --- a/src/main/java/org/onap/aai/config/SecurityConfig.java +++ b/src/main/java/org/onap/aai/config/SecurityConfig.java @@ -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 index 0000000..48ca42e --- /dev/null +++ b/src/main/java/org/onap/aai/config/SwaggerConfig.java @@ -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 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0c40eb2..c94b6e4 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -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 index 0000000..7ced557 --- /dev/null +++ b/src/test/java/org/onap/aai/config/SwaggerConfigTest.java @@ -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