Skip to content

Commit

Permalink
Extract open API (#18879)
Browse files Browse the repository at this point in the history
* Extract open API

* Format

* Fix PMD
  • Loading branch information
benmoriceau authored Nov 3, 2022
1 parent bf9cd2b commit 6b21802
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 4 deletions.
4 changes: 4 additions & 0 deletions airbyte-server/src/main/java/io/airbyte/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import io.airbyte.server.handlers.JobHistoryHandler;
import io.airbyte.server.handlers.LogsHandler;
import io.airbyte.server.handlers.OAuthHandler;
import io.airbyte.server.handlers.OpenApiConfigHandler;
import io.airbyte.server.handlers.OperationsHandler;
import io.airbyte.server.handlers.SchedulerHandler;
import io.airbyte.server.handlers.SourceDefinitionsHandler;
Expand Down Expand Up @@ -333,6 +334,8 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,
destinationHandler,
sourceHandler);

final OpenApiConfigHandler openApiConfigHandler = new OpenApiConfigHandler();

LOGGER.info("Starting server...");

return apiFactory.create(
Expand Down Expand Up @@ -361,6 +364,7 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,
jobHistoryHandler,
logsHandler,
oAuthHandler,
openApiConfigHandler,
operationsHandler,
schedulerHandler,
workspacesHandler);
Expand Down
10 changes: 10 additions & 0 deletions airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.airbyte.server.apis.JobsApiController;
import io.airbyte.server.apis.LogsApiController;
import io.airbyte.server.apis.NotificationsApiController;
import io.airbyte.server.apis.OpenapiApiController;
import io.airbyte.server.apis.binders.AttemptApiBinder;
import io.airbyte.server.apis.binders.ConnectionApiBinder;
import io.airbyte.server.apis.binders.DbMigrationBinder;
Expand All @@ -37,6 +38,7 @@
import io.airbyte.server.apis.binders.JobsApiBinder;
import io.airbyte.server.apis.binders.LogsApiBinder;
import io.airbyte.server.apis.binders.NotificationApiBinder;
import io.airbyte.server.apis.binders.OpenapiApiBinder;
import io.airbyte.server.apis.binders.SourceOauthApiBinder;
import io.airbyte.server.apis.factories.AttemptApiFactory;
import io.airbyte.server.apis.factories.ConnectionApiFactory;
Expand All @@ -49,6 +51,7 @@
import io.airbyte.server.apis.factories.JobsApiFactory;
import io.airbyte.server.apis.factories.LogsApiFactory;
import io.airbyte.server.apis.factories.NotificationsApiFactory;
import io.airbyte.server.apis.factories.OpenapiApiFactory;
import io.airbyte.server.apis.factories.SourceOauthApiFactory;
import io.airbyte.server.handlers.AttemptHandler;
import io.airbyte.server.handlers.ConnectionsHandler;
Expand All @@ -59,6 +62,7 @@
import io.airbyte.server.handlers.JobHistoryHandler;
import io.airbyte.server.handlers.LogsHandler;
import io.airbyte.server.handlers.OAuthHandler;
import io.airbyte.server.handlers.OpenApiConfigHandler;
import io.airbyte.server.handlers.OperationsHandler;
import io.airbyte.server.handlers.SchedulerHandler;
import io.airbyte.server.handlers.WorkspacesHandler;
Expand Down Expand Up @@ -98,6 +102,7 @@ ServerRunnable create(final SynchronousSchedulerClient synchronousSchedulerClien
final JobHistoryHandler jobHistoryHandler,
final LogsHandler logsHandler,
final OAuthHandler oAuthHandler,
final OpenApiConfigHandler openApiConfigHandler,
final OperationsHandler operationsHandler,
final SchedulerHandler schedulerHandler,
final WorkspacesHandler workspacesHandler);
Expand Down Expand Up @@ -130,6 +135,7 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
final JobHistoryHandler jobHistoryHandler,
final LogsHandler logsHandler,
final OAuthHandler oAuthHandler,
final OpenApiConfigHandler openApiConfigHandler,
final OperationsHandler operationsHandler,
final SchedulerHandler schedulerHandler,
final WorkspacesHandler workspacesHandler) {
Expand Down Expand Up @@ -184,6 +190,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul

NotificationsApiFactory.setValues(workspacesHandler);

OpenapiApiFactory.setValues(openApiConfigHandler);

// server configurations
final Set<Class<?>> componentClasses = Set.of(
ConfigurationApi.class,
Expand All @@ -198,6 +206,7 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
JobsApiController.class,
LogsApiController.class,
NotificationsApiController.class,
OpenapiApiController.class,
SourceOauthApiFactory.class);

final Set<Object> components = Set.of(
Expand All @@ -214,6 +223,7 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
new JobsApiBinder(),
new LogsApiBinder(),
new NotificationApiBinder(),
new OpenapiApiBinder(),
new SourceOauthApiBinder());

// construct server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
import io.airbyte.server.handlers.DestinationDefinitionsHandler;
import io.airbyte.server.handlers.DestinationHandler;
import io.airbyte.server.handlers.JobHistoryHandler;
import io.airbyte.server.handlers.OpenApiConfigHandler;
import io.airbyte.server.handlers.OperationsHandler;
import io.airbyte.server.handlers.SchedulerHandler;
import io.airbyte.server.handlers.SourceDefinitionsHandler;
Expand Down Expand Up @@ -152,7 +151,6 @@ public class ConfigurationApi implements io.airbyte.api.generated.V1Api {
private final JobHistoryHandler jobHistoryHandler;
private final WebBackendConnectionsHandler webBackendConnectionsHandler;
private final WebBackendGeographiesHandler webBackendGeographiesHandler;
private final OpenApiConfigHandler openApiConfigHandler;

public ConfigurationApi(final ConfigRepository configRepository,
final JobPersistence jobPersistence,
Expand Down Expand Up @@ -222,7 +220,6 @@ public ConfigurationApi(final ConfigRepository configRepository,
eventRunner,
configRepository);
webBackendGeographiesHandler = new WebBackendGeographiesHandler();
openApiConfigHandler = new OpenApiConfigHandler();
}

// WORKSPACE
Expand Down Expand Up @@ -962,9 +959,13 @@ public File getLogs(final LogsRequestBody logsRequestBody) {
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link HealthApiController}. Since the path of
* {@link HealthApiController} is more granular, it will override this implementation
*/
@Override
public File getOpenApiSpec() {
return execute(openApiConfigHandler::getFile);
throw new NotImplementedException();
}

// HEALTH
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.server.apis;

import io.airbyte.api.generated.OpenapiApi;
import io.airbyte.server.handlers.OpenApiConfigHandler;
import java.io.File;
import javax.ws.rs.Path;
import lombok.AllArgsConstructor;

@Path("/v1/openapi")
@AllArgsConstructor
public class OpenapiApiController implements OpenapiApi {

private final OpenApiConfigHandler openApiConfigHandler;

@Override
public File getOpenApiSpec() {
return ConfigurationApi.execute(openApiConfigHandler::getFile);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.server.apis.binders;

import io.airbyte.server.apis.OpenapiApiController;
import io.airbyte.server.apis.factories.OpenapiApiFactory;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.process.internal.RequestScoped;

public class OpenapiApiBinder extends AbstractBinder {

@Override
protected void configure() {
bindFactory(OpenapiApiFactory.class)
.to(OpenapiApiController.class)
.in(RequestScoped.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.server.apis.factories;

import io.airbyte.server.apis.OpenapiApiController;
import io.airbyte.server.handlers.OpenApiConfigHandler;
import org.glassfish.hk2.api.Factory;

public class OpenapiApiFactory implements Factory<OpenapiApiController> {

private static OpenApiConfigHandler openApiConfigHandler;

public static void setValues(final OpenApiConfigHandler openApiConfigHandler) {
OpenapiApiFactory.openApiConfigHandler = openApiConfigHandler;
}

@Override
public OpenapiApiController provide() {
return new OpenapiApiController(openApiConfigHandler);
}

@Override
public void dispose(final OpenapiApiController instance) {
/* no op */
}

}

0 comments on commit 6b21802

Please sign in to comment.