Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configured Swagger in the project #490

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ allprojects {
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
maven{
url "https://maven.reposilite.com/releases/"
}
}

configurations.configureEach {
Expand Down
2 changes: 2 additions & 0 deletions dbms/src/main/java/org/polypheny/db/PolyphenyDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ public void join( final long millis ) throws InterruptedException {

log.info( "****************************************************************************************************" );
log.info( " Polypheny-DB successfully started and ready to process your queries!" );
log.info( " For Swagger documentation:" );
log.info( " http://localhost:{}/swagger", RuntimeConfig.WEBUI_SERVER_PORT.getInteger() );
log.info( " The UI is waiting for you on port {}:", RuntimeConfig.WEBUI_SERVER_PORT.getInteger() );
log.info( " http://localhost:{}", RuntimeConfig.WEBUI_SERVER_PORT.getInteger() );
log.info( "****************************************************************************************************" );
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@ slf4j_api_version = 2.0.12
typesafe_config_version = 1.2.1
unirest_version = 3.14.5
web3j_version = 5.0.0
openapi = 1.1.7
4 changes: 4 additions & 0 deletions webui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ dependencies {
implementation group: "com.fasterxml.jackson.core", name: "jackson-core", version: jackson_core_version // Apache 2.0
implementation group: "com.fasterxml.jackson.core", name: "jackson-annotations", version: jackson_annotations_version // Apache 2.0

annotationProcessor group: "io.javalin-rfc", name: "openapi-annotation-processor", version: openapi

implementation group: "io.javalin-rfc", name: "javalin-openapi-plugin", version: openapi
implementation group: "io.javalin-rfc", name: "javalin-swagger-plugin", version: openapi

// --- Test Compile ---
testImplementation project(path: ":core", configuration: "tests")
}
Expand Down
12 changes: 12 additions & 0 deletions webui/src/main/java/org/polypheny/db/webui/Crud.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Part;

import io.javalin.openapi.HttpMethod;
import io.javalin.openapi.OpenApi;
import io.javalin.openapi.OpenApiContent;
import io.javalin.openapi.OpenApiRequestBody;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -2079,6 +2084,13 @@ void getSources( final Context ctx ) {
/**
* Deploy a new adapter
*/
@OpenApi(
path = "/createAdapter",
summary = "Deploy a new adapter",
tags = { "Adapter" },
methods = {HttpMethod.POST},
requestBody = @OpenApiRequestBody(content = @OpenApiContent(from = AdapterModel.class))
)
void addAdapter( final Context ctx ) throws ServletException, IOException {
initMultipart( ctx );
String body = "";
Expand Down
23 changes: 23 additions & 0 deletions webui/src/main/java/org/polypheny/db/webui/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import com.fasterxml.jackson.databind.SerializationFeature;
import io.javalin.Javalin;
import io.javalin.http.Context;
import io.javalin.openapi.plugin.OpenApiConfiguration;
import io.javalin.openapi.plugin.OpenApiPlugin;
import io.javalin.openapi.plugin.swagger.SwaggerConfiguration;
import io.javalin.openapi.plugin.swagger.SwaggerPlugin;
import io.javalin.plugin.json.JavalinJackson;
import io.javalin.websocket.WsConfig;
import java.io.BufferedReader;
Expand Down Expand Up @@ -61,6 +65,8 @@ public class HttpServer implements Runnable {
@Getter
private WebSocket webSocketHandler;

String deprecatedDocsPath = "/swagger-docs";


public static HttpServer getInstance() {
if ( INSTANCE == null ) {
Expand All @@ -70,6 +76,21 @@ public static HttpServer getInstance() {
}


private OpenApiConfiguration getOpenApiConfiguration() {
OpenApiConfiguration openApiConfiguration = new OpenApiConfiguration();
openApiConfiguration.setTitle( "Polypheny-DB WebUI" );
openApiConfiguration.setDocumentationPath(deprecatedDocsPath); // by default it's /openapi
return openApiConfiguration;
}


private SwaggerConfiguration getSwaggerConfiguration() {
SwaggerConfiguration swaggerConfiguration = new SwaggerConfiguration();
swaggerConfiguration.setDocumentationPath(deprecatedDocsPath);
return swaggerConfiguration;
}


public static final ObjectMapper mapper = new ObjectMapper() {
{
setSerializationInclusion( JsonInclude.Include.NON_NULL );
Expand All @@ -88,6 +109,8 @@ public static HttpServer getInstance() {
config.jsonMapper( new JavalinJackson( mapper ) );
config.enableCorsForAllOrigins();
config.addStaticFiles( staticFileConfig -> staticFileConfig.directory = "webapp/" );
config.registerPlugin( new OpenApiPlugin( getOpenApiConfiguration() ) );
config.registerPlugin( new SwaggerPlugin( getSwaggerConfiguration() ) );
} ).start( RuntimeConfig.WEBUI_SERVER_PORT.getInteger() );
private Crud crud;

Expand Down