|
8 | 8 | import de.chojo.jdautil.botlist.BotlistService;
|
9 | 9 | import de.chojo.repbot.config.Configuration;
|
10 | 10 | import de.chojo.repbot.web.Api;
|
| 11 | +import de.chojo.repbot.web.error.ApiException; |
11 | 12 | import io.javalin.Javalin;
|
12 |
| -import io.javalin.plugin.openapi.OpenApiOptions; |
13 |
| -import io.javalin.plugin.openapi.OpenApiPlugin; |
14 |
| -import io.javalin.plugin.openapi.ui.ReDocOptions; |
15 |
| -import io.javalin.plugin.openapi.ui.SwaggerOptions; |
16 |
| -import io.javalin.plugin.openapi.utils.OpenApiVersionUtil; |
17 |
| -import io.swagger.v3.oas.models.info.License; |
| 13 | +import io.javalin.openapi.OpenApiLicense; |
| 14 | +import io.javalin.openapi.plugin.OpenApiPlugin; |
| 15 | +import io.javalin.openapi.plugin.OpenApiPluginConfiguration; |
| 16 | +import io.javalin.openapi.plugin.swagger.SwaggerConfiguration; |
| 17 | +import io.javalin.openapi.plugin.swagger.SwaggerPlugin; |
18 | 18 | import net.dv8tion.jda.api.entities.User;
|
19 | 19 | import net.dv8tion.jda.api.exceptions.ErrorResponseException;
|
20 | 20 | import net.dv8tion.jda.api.requests.ErrorResponse;
|
@@ -80,19 +80,44 @@ public void init() {
|
80 | 80 | private void initApi() {
|
81 | 81 | var api = configuration.api();
|
82 | 82 |
|
83 |
| - var info = new io.swagger.v3.oas.models.info.Info().version("1.0").title("Reputation Bot API") |
84 |
| - .description("Documentation for the Reputation Bot API") |
85 |
| - .license(new License().name("GNU Affero General Public License v3.0") |
86 |
| - .url("https://github.com/RainbowDashLabs/reputation-bot/blob/master/LICENSE.md")); |
| 83 | + /* |
87 | 84 | var options = new OpenApiOptions(info)
|
88 | 85 | .path("/json-docs")
|
89 | 86 | .reDoc(new ReDocOptions("/redoc")) // endpoint for redoc
|
90 | 87 | .swagger(new SwaggerOptions("/docs").title("Reputation Bot API"));
|
91 |
| - OpenApiVersionUtil.INSTANCE.setLogWarnings(false); |
| 88 | + OpenApiVersionUtil.INSTANCE.setLogWarnings(false);*/ |
92 | 89 |
|
93 |
| - javalin = Javalin.create(config -> config.registerPlugin(new OpenApiPlugin(options))) |
94 |
| - .start(api.host(), api.port()); |
95 |
| - new Api(javalin, data.metrics()).init(); |
| 90 | + javalin = Javalin.create(config -> { |
| 91 | + config.registerPlugin(new OpenApiPlugin(this::configureOpenApi)); |
| 92 | + config.registerPlugin(new SwaggerPlugin(this::configureSwagger)); |
| 93 | + config.router.apiBuilder(() -> new Api(data.metrics()).init()); |
| 94 | + }) |
| 95 | + .start(api.host(), api.port()); |
| 96 | + javalin.exception(ApiException.class, (err, ctx) -> ctx.result(err.getMessage()).status(err.status())); |
| 97 | + } |
| 98 | + |
| 99 | + private void configureSwagger(SwaggerConfiguration swaggerConfiguration) { |
| 100 | + swaggerConfiguration.setDocumentationPath("/docs"); |
| 101 | + swaggerConfiguration.setUiPath("/swagger-ui"); |
| 102 | + } |
| 103 | + |
| 104 | + private void configureOpenApi(OpenApiPluginConfiguration config) { |
| 105 | + config.withDocumentationPath("/docs") |
| 106 | + .withDefinitionConfiguration((version, definition) -> { |
| 107 | + definition.withInfo(info -> { |
| 108 | + info.setTitle("Reputation Bot API"); |
| 109 | + info.setVersion("1.0"); |
| 110 | + info.setDescription("Documentation for the Reputation Bot API"); |
| 111 | + info.setLicense(new OpenApiLicense() |
| 112 | + .name("GNU Affero General Public License v3.0") |
| 113 | + .url("https://github.com/RainbowDashLabs/reputation-bot/blob/master/LICENSE.md") |
| 114 | + ); |
| 115 | + }); |
| 116 | + definition.withServer(openApiServer -> { |
| 117 | + openApiServer.setUrl("https://repbot.rainbowdashlabs.de"); |
| 118 | + openApiServer.setDescription("Main server"); |
| 119 | + }); |
| 120 | + }); |
96 | 121 | }
|
97 | 122 |
|
98 | 123 | /**
|
|
0 commit comments