-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3012 from HenrikJannsen/api-refactorings
Refactor Api module
- Loading branch information
Showing
8 changed files
with
86 additions
and
87 deletions.
There are no files selected for viewing
72 changes: 0 additions & 72 deletions
72
apps/rest-api-app/src/main/java/bisq/rest_api/JaxRsApplication.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
apps/rest-api-app/src/main/java/bisq/rest_api/RestApiResourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package bisq.rest_api; | ||
|
||
import bisq.common.rest_api.error.CustomExceptionMapper; | ||
import bisq.common.rest_api.error.RestApiException; | ||
import bisq.rest_api.report.ReportRestApi; | ||
import bisq.rest_api.util.SerializationModule; | ||
import bisq.rest_api.util.SwaggerResolution; | ||
import bisq.user.identity.UserIdentityRestApi; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.glassfish.jersey.internal.inject.AbstractBinder; | ||
import org.glassfish.jersey.server.ResourceConfig; | ||
|
||
@Slf4j | ||
public class RestApiResourceConfig extends ResourceConfig { | ||
public RestApiResourceConfig(RestApiApplicationService applicationService, String baseUrl) { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
mapper.registerModule(new SerializationModule()); | ||
|
||
register(CustomExceptionMapper.class) | ||
.register(RestApiException.Mapper.class) | ||
.register(mapper); | ||
|
||
// Swagger/OpenApi does not work when using instances at register instead of classes. | ||
// As we want to pass the dependencies in the constructor, so we need the hack | ||
// with AbstractBinder to register resources as classes for Swagger | ||
register(SwaggerResolution.class); | ||
register(UserIdentityRestApi.class); | ||
register(ReportRestApi.class); | ||
|
||
register(new AbstractBinder() { | ||
@Override | ||
protected void configure() { | ||
bind(new SwaggerResolution(baseUrl)).to(SwaggerResolution.class); | ||
bind(new UserIdentityRestApi(applicationService.getUserService().getUserIdentityService())).to(UserIdentityRestApi.class); | ||
bind(new ReportRestApi(applicationService.getNetworkService(), applicationService.getBondedRolesService())).to(ReportRestApi.class); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
*/ | ||
package bisq.rest_api.util; | ||
|
||
import bisq.rest_api.JaxRsApplication; | ||
import io.swagger.v3.core.util.Json; | ||
import io.swagger.v3.jaxrs2.Reader; | ||
import io.swagger.v3.oas.annotations.Hidden; | ||
|
@@ -39,6 +38,11 @@ | |
@Hidden | ||
public class SwaggerResolution { | ||
private static String swaggerJson; | ||
private final String baseUrl; | ||
|
||
public SwaggerResolution(String baseUrl) { | ||
this.baseUrl = baseUrl; | ||
} | ||
|
||
@GET | ||
public String swagIt(@Context Application application) { | ||
|
@@ -48,14 +52,11 @@ public String swagIt(@Context Application application) { | |
Info info = new Info() | ||
.title("Bisq 2 REST API") | ||
.description("This is the rest API description for Bisq2, For more Information about Bisq, see https://bisq.network") | ||
// .termsOfService("http://swagger.io/terms/") | ||
// .contact(new Contact() | ||
// .email("[email protected]")) | ||
.license(new License() | ||
.name("GNU Affero General Public License") | ||
.url("https://github.com/bisq-network/bisq2/blob/main/LICENSE")); | ||
|
||
api.info(info).addServersItem(new Server().url(JaxRsApplication.BASE_URL)); | ||
api.info(info).addServersItem(new Server().url(baseUrl)); | ||
SwaggerConfiguration configuration = new SwaggerConfiguration().openAPI(api); | ||
Reader reader = new Reader(configuration); | ||
OpenAPI openAPI = reader.read(application.getClasses()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters