Skip to content
Snippets Groups Projects
Commit 13e78a9b authored by Jayesh Bagul's avatar Jayesh Bagul
Browse files

Generate Swagger using springdoc-openapi OAS 3.0

parent b7a55646
No related tags found
No related merge requests found
Pipeline #215004 failed
......@@ -32,11 +32,7 @@
<java.version>11</java.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<springfox-version>2.7.0</springfox-version>
<os-core-common.version>0.15.0-SNAPSHOT</os-core-common.version>
<!--
<springfox-version>2.9.2</springfox-version>
-->
</properties>
<dependencyManagement>
......@@ -48,6 +44,12 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- swagger dependency -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${openapi.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
......
......@@ -3,41 +3,61 @@ package com.osdu.opcuaingestion.api;
import com.osdu.opcuaingestion.modal.DeviceList;
import com.osdu.opcuaingestion.service.OsduService;
import com.osdu.opcuaingestion.util.ParquetConverter;
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.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.time.Instant;
import java.util.Map;
@RequestMapping("/osdu")
@RestController
@Tag(name = "osdu-controller-api", description = "OsduController related endpoints")
public class OsduController {
@Autowired
OsduService osduService ;
@Autowired
ParquetConverter parquetConverter;
Logger log = LogManager.getRootLogger();
@Operation(summary = "${osduController.getNodeDetails.summary}", description = "${osduController.getNodeDetails.description}",
security = {@SecurityRequirement(name = "Authorization")})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Success Response", content = { @Content(schema = @Schema(implementation = ResponseEntity.class)) }),
@ApiResponse(responseCode = "400", description = "Bad Request", content = {@Content(schema = @Schema(implementation = AppError.class ))}),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = {@Content(schema = @Schema(implementation = AppError.class ))}),
@ApiResponse(responseCode = "403", description = "User not authorized to perform the action.", content = {@Content(schema = @Schema(implementation = AppError.class ))}),
@ApiResponse(responseCode = "404", description = "object not found", content = {@Content(schema = @Schema(implementation = AppError.class ))}),
@ApiResponse(responseCode = "500", description = "Internal Server Error", content = {@Content(schema = @Schema(implementation = AppError.class ))}),
@ApiResponse(responseCode = "502", description = "Bad Gateway", content = {@Content(schema = @Schema(implementation = AppError.class ))}),
@ApiResponse(responseCode = "503", description = "Service Unavailable", content = {@Content(schema = @Schema(implementation = AppError.class ))})
})
@GetMapping("/getNodeAttributes")
public String getNodeDetails() throws Exception {
//return discoveryClient.getNodeValues();
// return "Hello Mr. Client";
return osduService.getNodeDetailsInfo();
}
@Operation(summary = "${osduController.convertToParquet.summary}", description = "${osduController.convertToParquet.description}",
security = {@SecurityRequirement(name = "Authorization")})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Success Response", content = { @Content(schema = @Schema(implementation = ResponseEntity.class)) }),
@ApiResponse(responseCode = "400", description = "Bad Request", content = {@Content(schema = @Schema(implementation = AppError.class ))}),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = {@Content(schema = @Schema(implementation = AppError.class ))}),
@ApiResponse(responseCode = "403", description = "User not authorized to perform the action.", content = {@Content(schema = @Schema(implementation = AppError.class ))}),
@ApiResponse(responseCode = "404", description = "object not found", content = {@Content(schema = @Schema(implementation = AppError.class ))}),
@ApiResponse(responseCode = "500", description = "Internal Server Error", content = {@Content(schema = @Schema(implementation = AppError.class ))}),
@ApiResponse(responseCode = "502", description = "Bad Gateway", content = {@Content(schema = @Schema(implementation = AppError.class ))}),
@ApiResponse(responseCode = "503", description = "Service Unavailable", content = {@Content(schema = @Schema(implementation = AppError.class ))})
})
@GetMapping(value = "/convertToParquet")
public String convertToParquet(){
log.info("******************Inside the convertJsonToParquet****************");
//Map<String, String> chronoMap = getFolderBasedOnTimestamp(Instant.now().toEpochMilli());
......
package com.osdu.opcuaingestion.swagger;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.parameters.Parameter;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springdoc.core.customizers.OperationCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@OpenAPIDefinition(
info = @Info(
title = "${api.title}",
description = "${api.description}",
version = "${api.version}",
contact = @Contact(name = "${api.contact.name}", email = "${api.contact.email}"),
license = @License(name = "${api.license.name}", url = "${api.license.url}")),
servers = @Server(url = "${api.server.url}"),
// security = @SecurityRequirement(name = "Authorization"),
tags = {
@Tag(name = "osdu-controller-api", description = "OsduController related endpoints")
}
)
@SecurityScheme(name = "Authorization", scheme = "bearer", bearerFormat = "Authorization", type = SecuritySchemeType.HTTP)
@Configuration
//@Profile("!noswagger")
public class SwaggerConfiguration {
@Bean
public OperationCustomizer customize() {
return (operation, handlerMethod) -> {
Parameter dataPartitionId = new Parameter()
.name(DpsHeaders.DATA_PARTITION_ID)
.description("Tenant Id")
.in("header")
.required(true)
.schema(new StringSchema());
return operation.addParametersItem(dataPartitionId);
};
}
}
#Manage common SpringDoc and OpenAPI related properties
#SpringDoc related properties
springdoc.swagger-ui.tagsSorter=alpha
springdoc.swagger-ui.operationsSorter=alpha
springdoc.swagger-ui.doc-expansion=none
springdoc.swagger-ui.path=/swagger
springdoc.swagger-ui.displayOperationId=true
springdoc.api-docs.path=/api-docs
#OpenAPI 3.0 - Well Delivery Properties
api.title=OPC-UA Ingestion API
api.description=Ingestion for OPC-UA framework
api.version=1.0.0
api.contact.name=OSDU Data Platform Team
api.contact.email=dps@OSDU.org
api.license.name=Apache 2.0
api.license.url=https://www.apache.org/licenses/LICENSE-2.0.html
api.server.url=${server.servlet.contextPath}
osduController.getNodeDetails.summary=getNodeDetails
osduController.getNodeDetails.description= getNodeDetails
osduController.convertToParquet.summary=convertToParquet
osduController.convertToParquet.description= convertToParquet.
\ No newline at end of file
......@@ -36,8 +36,8 @@
<nimbusds.version>7.9</nimbusds.version>
<woodstox-core.version>6.2.3</woodstox-core.version>
<log4j2.version>2.17.1</log4j2.version>
<springfox.version>3.0.0</springfox.version>
<json-smart.version>2.4.7</json-smart.version>
<openapi.version>1.7.0</openapi.version>
</properties>
<licenses>
......@@ -135,9 +135,9 @@
<!--Swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${springfox.version}</version>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${openapi.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.plugin</groupId>
......
......@@ -19,9 +19,10 @@ package org.opengroup.osdu.opaua.provider.azure;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;
@SpringBootApplication(scanBasePackages = "org.opengroup.osdu.opaua")
@PropertySource("classpath:swagger.properties")
public class OpaUaAzureApplication {
public static void main(String[] args) {
SpringApplication.run(OpaUaAzureApplication.class, args);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment