Skip to content

Commit 6b21802

Browse files
authored
Extract open API (#18879)
* Extract open API * Format * Fix PMD
1 parent bf9cd2b commit 6b21802

File tree

6 files changed

+93
-4
lines changed

6 files changed

+93
-4
lines changed

airbyte-server/src/main/java/io/airbyte/server/ServerApp.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import io.airbyte.server.handlers.JobHistoryHandler;
6161
import io.airbyte.server.handlers.LogsHandler;
6262
import io.airbyte.server.handlers.OAuthHandler;
63+
import io.airbyte.server.handlers.OpenApiConfigHandler;
6364
import io.airbyte.server.handlers.OperationsHandler;
6465
import io.airbyte.server.handlers.SchedulerHandler;
6566
import io.airbyte.server.handlers.SourceDefinitionsHandler;
@@ -333,6 +334,8 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,
333334
destinationHandler,
334335
sourceHandler);
335336

337+
final OpenApiConfigHandler openApiConfigHandler = new OpenApiConfigHandler();
338+
336339
LOGGER.info("Starting server...");
337340

338341
return apiFactory.create(
@@ -361,6 +364,7 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,
361364
jobHistoryHandler,
362365
logsHandler,
363366
oAuthHandler,
367+
openApiConfigHandler,
364368
operationsHandler,
365369
schedulerHandler,
366370
workspacesHandler);

airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.airbyte.server.apis.JobsApiController;
2727
import io.airbyte.server.apis.LogsApiController;
2828
import io.airbyte.server.apis.NotificationsApiController;
29+
import io.airbyte.server.apis.OpenapiApiController;
2930
import io.airbyte.server.apis.binders.AttemptApiBinder;
3031
import io.airbyte.server.apis.binders.ConnectionApiBinder;
3132
import io.airbyte.server.apis.binders.DbMigrationBinder;
@@ -37,6 +38,7 @@
3738
import io.airbyte.server.apis.binders.JobsApiBinder;
3839
import io.airbyte.server.apis.binders.LogsApiBinder;
3940
import io.airbyte.server.apis.binders.NotificationApiBinder;
41+
import io.airbyte.server.apis.binders.OpenapiApiBinder;
4042
import io.airbyte.server.apis.binders.SourceOauthApiBinder;
4143
import io.airbyte.server.apis.factories.AttemptApiFactory;
4244
import io.airbyte.server.apis.factories.ConnectionApiFactory;
@@ -49,6 +51,7 @@
4951
import io.airbyte.server.apis.factories.JobsApiFactory;
5052
import io.airbyte.server.apis.factories.LogsApiFactory;
5153
import io.airbyte.server.apis.factories.NotificationsApiFactory;
54+
import io.airbyte.server.apis.factories.OpenapiApiFactory;
5255
import io.airbyte.server.apis.factories.SourceOauthApiFactory;
5356
import io.airbyte.server.handlers.AttemptHandler;
5457
import io.airbyte.server.handlers.ConnectionsHandler;
@@ -59,6 +62,7 @@
5962
import io.airbyte.server.handlers.JobHistoryHandler;
6063
import io.airbyte.server.handlers.LogsHandler;
6164
import io.airbyte.server.handlers.OAuthHandler;
65+
import io.airbyte.server.handlers.OpenApiConfigHandler;
6266
import io.airbyte.server.handlers.OperationsHandler;
6367
import io.airbyte.server.handlers.SchedulerHandler;
6468
import io.airbyte.server.handlers.WorkspacesHandler;
@@ -98,6 +102,7 @@ ServerRunnable create(final SynchronousSchedulerClient synchronousSchedulerClien
98102
final JobHistoryHandler jobHistoryHandler,
99103
final LogsHandler logsHandler,
100104
final OAuthHandler oAuthHandler,
105+
final OpenApiConfigHandler openApiConfigHandler,
101106
final OperationsHandler operationsHandler,
102107
final SchedulerHandler schedulerHandler,
103108
final WorkspacesHandler workspacesHandler);
@@ -130,6 +135,7 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
130135
final JobHistoryHandler jobHistoryHandler,
131136
final LogsHandler logsHandler,
132137
final OAuthHandler oAuthHandler,
138+
final OpenApiConfigHandler openApiConfigHandler,
133139
final OperationsHandler operationsHandler,
134140
final SchedulerHandler schedulerHandler,
135141
final WorkspacesHandler workspacesHandler) {
@@ -184,6 +190,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
184190

185191
NotificationsApiFactory.setValues(workspacesHandler);
186192

193+
OpenapiApiFactory.setValues(openApiConfigHandler);
194+
187195
// server configurations
188196
final Set<Class<?>> componentClasses = Set.of(
189197
ConfigurationApi.class,
@@ -198,6 +206,7 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
198206
JobsApiController.class,
199207
LogsApiController.class,
200208
NotificationsApiController.class,
209+
OpenapiApiController.class,
201210
SourceOauthApiFactory.class);
202211

203212
final Set<Object> components = Set.of(
@@ -214,6 +223,7 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
214223
new JobsApiBinder(),
215224
new LogsApiBinder(),
216225
new NotificationApiBinder(),
226+
new OpenapiApiBinder(),
217227
new SourceOauthApiBinder());
218228

219229
// construct server

airbyte-server/src/main/java/io/airbyte/server/apis/ConfigurationApi.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@
117117
import io.airbyte.server.handlers.DestinationDefinitionsHandler;
118118
import io.airbyte.server.handlers.DestinationHandler;
119119
import io.airbyte.server.handlers.JobHistoryHandler;
120-
import io.airbyte.server.handlers.OpenApiConfigHandler;
121120
import io.airbyte.server.handlers.OperationsHandler;
122121
import io.airbyte.server.handlers.SchedulerHandler;
123122
import io.airbyte.server.handlers.SourceDefinitionsHandler;
@@ -152,7 +151,6 @@ public class ConfigurationApi implements io.airbyte.api.generated.V1Api {
152151
private final JobHistoryHandler jobHistoryHandler;
153152
private final WebBackendConnectionsHandler webBackendConnectionsHandler;
154153
private final WebBackendGeographiesHandler webBackendGeographiesHandler;
155-
private final OpenApiConfigHandler openApiConfigHandler;
156154

157155
public ConfigurationApi(final ConfigRepository configRepository,
158156
final JobPersistence jobPersistence,
@@ -222,7 +220,6 @@ public ConfigurationApi(final ConfigRepository configRepository,
222220
eventRunner,
223221
configRepository);
224222
webBackendGeographiesHandler = new WebBackendGeographiesHandler();
225-
openApiConfigHandler = new OpenApiConfigHandler();
226223
}
227224

228225
// WORKSPACE
@@ -962,9 +959,13 @@ public File getLogs(final LogsRequestBody logsRequestBody) {
962959
throw new NotImplementedException();
963960
}
964961

962+
/**
963+
* This implementation has been moved to {@link HealthApiController}. Since the path of
964+
* {@link HealthApiController} is more granular, it will override this implementation
965+
*/
965966
@Override
966967
public File getOpenApiSpec() {
967-
return execute(openApiConfigHandler::getFile);
968+
throw new NotImplementedException();
968969
}
969970

970971
// HEALTH
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
3+
*/
4+
5+
package io.airbyte.server.apis;
6+
7+
import io.airbyte.api.generated.OpenapiApi;
8+
import io.airbyte.server.handlers.OpenApiConfigHandler;
9+
import java.io.File;
10+
import javax.ws.rs.Path;
11+
import lombok.AllArgsConstructor;
12+
13+
@Path("/v1/openapi")
14+
@AllArgsConstructor
15+
public class OpenapiApiController implements OpenapiApi {
16+
17+
private final OpenApiConfigHandler openApiConfigHandler;
18+
19+
@Override
20+
public File getOpenApiSpec() {
21+
return ConfigurationApi.execute(openApiConfigHandler::getFile);
22+
}
23+
24+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
3+
*/
4+
5+
package io.airbyte.server.apis.binders;
6+
7+
import io.airbyte.server.apis.OpenapiApiController;
8+
import io.airbyte.server.apis.factories.OpenapiApiFactory;
9+
import org.glassfish.hk2.utilities.binding.AbstractBinder;
10+
import org.glassfish.jersey.process.internal.RequestScoped;
11+
12+
public class OpenapiApiBinder extends AbstractBinder {
13+
14+
@Override
15+
protected void configure() {
16+
bindFactory(OpenapiApiFactory.class)
17+
.to(OpenapiApiController.class)
18+
.in(RequestScoped.class);
19+
}
20+
21+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
3+
*/
4+
5+
package io.airbyte.server.apis.factories;
6+
7+
import io.airbyte.server.apis.OpenapiApiController;
8+
import io.airbyte.server.handlers.OpenApiConfigHandler;
9+
import org.glassfish.hk2.api.Factory;
10+
11+
public class OpenapiApiFactory implements Factory<OpenapiApiController> {
12+
13+
private static OpenApiConfigHandler openApiConfigHandler;
14+
15+
public static void setValues(final OpenApiConfigHandler openApiConfigHandler) {
16+
OpenapiApiFactory.openApiConfigHandler = openApiConfigHandler;
17+
}
18+
19+
@Override
20+
public OpenapiApiController provide() {
21+
return new OpenapiApiController(openApiConfigHandler);
22+
}
23+
24+
@Override
25+
public void dispose(final OpenapiApiController instance) {
26+
/* no op */
27+
}
28+
29+
}

0 commit comments

Comments
 (0)