All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.tinkoff.kora.openapi.management.OpenApiManagementModule Maven / Gradle / Ivy

There is a newer version: 1.1.10
Show newest version
package ru.tinkoff.kora.openapi.management;

import ru.tinkoff.kora.config.common.Config;
import ru.tinkoff.kora.config.common.extractor.ConfigValueExtractor;
import ru.tinkoff.kora.http.server.common.HttpServerResponse;
import ru.tinkoff.kora.http.server.common.handler.HttpServerRequestHandler;
import ru.tinkoff.kora.http.server.common.handler.HttpServerRequestHandlerImpl;

import java.util.concurrent.CompletableFuture;

public interface OpenApiManagementModule {

    default OpenApiManagementConfig openApiManagementConfig(Config config, ConfigValueExtractor extractor) {
        return extractor.extract(config.get("openapi.management"));
    }

    default HttpServerRequestHandler openApiManagementController(OpenApiManagementConfig config) {
        final String path = (config.file().size() == 1) ? config.endpoint() : config.endpoint() + "/{file}";
        if (!config.enabled()) {
            return HttpServerRequestHandlerImpl.get(path,
                (context, request) -> CompletableFuture.completedFuture(HttpServerResponse.of(404)));
        }

        var handler = new OpenApiHttpServerHandler(config);
        return HttpServerRequestHandlerImpl.get(path, handler);
    }

    default HttpServerRequestHandler swaggerUIManagementController(OpenApiManagementConfig config) {
        if (config.swaggerui() == null) {
            return HttpServerRequestHandlerImpl.get("/swagger-ui",
                (context, request) -> CompletableFuture.completedFuture(HttpServerResponse.of(404)));
        } else if (!config.enabled() || !config.swaggerui().enabled()) {
            return HttpServerRequestHandlerImpl.get(config.swaggerui().endpoint(),
                (context, request) -> CompletableFuture.completedFuture(HttpServerResponse.of(404)));
        }

        var handler = new SwaggerUIHttpServerHandler(config);
        return HttpServerRequestHandlerImpl.get(config.swaggerui().endpoint(), handler);
    }

    default HttpServerRequestHandler rapidocManagementController(OpenApiManagementConfig config) {
        if (config.rapidoc() == null) {
            return HttpServerRequestHandlerImpl.get("/rapidoc",
                (context, request) -> CompletableFuture.completedFuture(HttpServerResponse.of(404)));
        } else if (!config.enabled() || !config.rapidoc().enabled()) {
            return HttpServerRequestHandlerImpl.get(config.rapidoc().endpoint(),
                (context, request) -> CompletableFuture.completedFuture(HttpServerResponse.of(404)));
        }

        var handler = new RapidocHttpServerHandler(config);
        return HttpServerRequestHandlerImpl.get(config.rapidoc().endpoint(), handler);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy