Search in sources :

Example 1 with OpenApiOptions

use of io.javalin.plugin.openapi.OpenApiOptions in project teku by ConsenSys.

the class BeaconRestApi method getOpenApiOptions.

private static OpenApiOptions getOpenApiOptions(final JsonProvider jsonProvider, final BeaconRestApiConfig config) {
    final JacksonModelConverterFactory factory = new JacksonModelConverterFactory(jsonProvider.getObjectMapper());
    final Info applicationInfo = new Info().title(StringUtils.capitalize(VersionProvider.CLIENT_IDENTITY)).version(VersionProvider.IMPLEMENTATION_VERSION).description("A minimal API specification for the beacon node, which enables a validator " + "to connect and perform its obligations on the Ethereum 2.0 phase 0 beacon chain.").license(new License().name("Apache 2.0").url("https://www.apache.org/licenses/LICENSE-2.0.html"));
    final OpenApiOptions options = new OpenApiOptions(applicationInfo).modelConverterFactory(factory);
    if (config.isRestApiDocsEnabled()) {
        options.path("/swagger-docs").swagger(new SwaggerOptions("/swagger-ui"));
    }
    return options;
}
Also used : OpenApiOptions(io.javalin.plugin.openapi.OpenApiOptions) SwaggerOptions(io.javalin.plugin.openapi.ui.SwaggerOptions) License(io.swagger.v3.oas.models.info.License) Info(io.swagger.v3.oas.models.info.Info) JacksonModelConverterFactory(io.javalin.plugin.openapi.jackson.JacksonModelConverterFactory)

Example 2 with OpenApiOptions

use of io.javalin.plugin.openapi.OpenApiOptions in project javalin by tipsy.

the class ExampleController method main.

public static void main(String[] args) {
    ObjectMapper objectMapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
    OpenApiOptions openApiOptions = new OpenApiOptions(new Info().version("1.0").description("My Application")).activateAnnotationScanningFor("io.javalin.examples").path("/swagger-docs").swagger(new SwaggerOptions("/swagger").title("My Swagger Documentation")).reDoc(new ReDocOptions("/redoc", new RedocOptionsObject.Builder().setHideDownloadButton(true).setTheme(new RedocOptionsTheme.Builder().setSpacingUnit(10).setTypographyOptimizeSpeed(true).build()).build()).title("My ReDoc Documentation"));
    Javalin app = Javalin.create(config -> {
        config.registerPlugin(new OpenApiPlugin(openApiOptions));
        config.jsonMapper(new JavalinJackson(objectMapper));
    }).start(7070);
    app.post("/users", ExampleController::create);
}
Also used : Javalin(io.javalin.Javalin) HttpMethod(io.javalin.plugin.openapi.annotations.HttpMethod) OpenApiPlugin(io.javalin.plugin.openapi.OpenApiPlugin) ReDocOptions(io.javalin.plugin.openapi.ui.ReDocOptions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RedocOptionsObject(io.javalin.plugin.openapi.ui.RedocOptionsObject) Info(io.swagger.v3.oas.models.info.Info) OpenApiContent(io.javalin.plugin.openapi.annotations.OpenApiContent) Javalin(io.javalin.Javalin) OpenApiOptions(io.javalin.plugin.openapi.OpenApiOptions) JavalinJackson(io.javalin.plugin.json.JavalinJackson) RedocOptionsTheme(io.javalin.plugin.openapi.ui.RedocOptionsTheme) OpenApiParam(io.javalin.plugin.openapi.annotations.OpenApiParam) Context(io.javalin.http.Context) OpenApiResponse(io.javalin.plugin.openapi.annotations.OpenApiResponse) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) SwaggerOptions(io.javalin.plugin.openapi.ui.SwaggerOptions) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi) OpenApiOptions(io.javalin.plugin.openapi.OpenApiOptions) SwaggerOptions(io.javalin.plugin.openapi.ui.SwaggerOptions) JavalinJackson(io.javalin.plugin.json.JavalinJackson) ReDocOptions(io.javalin.plugin.openapi.ui.ReDocOptions) Info(io.swagger.v3.oas.models.info.Info) OpenApiPlugin(io.javalin.plugin.openapi.OpenApiPlugin) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with OpenApiOptions

use of io.javalin.plugin.openapi.OpenApiOptions in project Jexxa by repplix.

the class OpenAPIConvention method initOpenAPI.

private void initOpenAPI() {
    if (properties.containsKey(JEXXA_REST_OPEN_API_PATH)) {
        var applicationInfo = new Info().version(properties.getProperty(JEXXA_CONTEXT_VERSION, "1.0")).description("Auto generated OpenAPI for " + properties.getProperty(JEXXA_CONTEXT_NAME, "Unknown Context")).title(properties.getProperty(JEXXA_CONTEXT_NAME, "Unknown Context"));
        openApiOptions = new OpenApiOptions(applicationInfo).path("/" + properties.getProperty(JEXXA_REST_OPEN_API_PATH));
        // Show all fields of an ValueObject
        openApiOptions.getJacksonMapper().setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
        javalinConfig.registerPlugin(new OpenApiPlugin(openApiOptions));
        javalinConfig.enableCorsForAllOrigins();
        openApiOptions.defaultDocumentation(doc -> {
            doc.json(String.valueOf(HTTP_BAD_REQUEST), BadRequestResponse.class);
            doc.json(String.valueOf(HTTP_BAD_REQUEST), BadRequestResponse.class);
        });
    }
}
Also used : OpenApiOptions(io.javalin.plugin.openapi.OpenApiOptions) Info(io.swagger.v3.oas.models.info.Info) OpenApiPlugin(io.javalin.plugin.openapi.OpenApiPlugin)

Example 4 with OpenApiOptions

use of io.javalin.plugin.openapi.OpenApiOptions in project cineast by vitrivr.

the class OpenApiCompatHelper method getJavalinOpenApiOptions.

/**
 * Creates the Javalin options used to create an OpenAPI specification.
 */
public static OpenApiOptions getJavalinOpenApiOptions(APIConfig config) {
    // Default Javalin JSON mapper includes all null values, which breakes the openapi specs.
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.addMixIn(Schema.class, // Makes Schema.exampleFlagSet being ignored by jackson
    SchemaMixin.class);
    return new OpenApiOptions(() -> getOpenApi(config)).path("/openapi-specs").activateAnnotationScanningFor("org.vitrivr.cineast.api").toJsonMapper(new JacksonToJsonMapper(mapper)).modelConverterFactory(() -> new ModelResolver(mapper)).swagger(new SwaggerOptions("/swagger-ui").title("Swagger UI for Cineast Documentation")).reDoc(new ReDocOptions("/redoc").title("ReDoc for Cineast Documentation"));
}
Also used : OpenApiOptions(io.javalin.plugin.openapi.OpenApiOptions) SwaggerOptions(io.javalin.plugin.openapi.ui.SwaggerOptions) JacksonToJsonMapper(io.javalin.plugin.openapi.jackson.JacksonToJsonMapper) ReDocOptions(io.javalin.plugin.openapi.ui.ReDocOptions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ModelResolver(io.swagger.v3.core.jackson.ModelResolver)

Example 5 with OpenApiOptions

use of io.javalin.plugin.openapi.OpenApiOptions in project Jexxa by jexxa-projects.

the class OpenAPIConvention method initOpenAPI.

private void initOpenAPI() {
    if (properties.containsKey(JEXXA_REST_OPEN_API_PATH)) {
        var applicationInfo = new Info().version(properties.getProperty(JEXXA_CONTEXT_VERSION, "1.0")).description("Auto generated OpenAPI for " + properties.getProperty(JEXXA_CONTEXT_NAME, "Unknown Context")).title(properties.getProperty(JEXXA_CONTEXT_NAME, "Unknown Context"));
        openApiOptions = new OpenApiOptions(applicationInfo).path("/" + properties.getProperty(JEXXA_REST_OPEN_API_PATH));
        // Show all fields of an ValueObject
        openApiOptions.getJacksonMapper().setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
        javalinConfig.registerPlugin(new OpenApiPlugin(openApiOptions));
        javalinConfig.enableCorsForAllOrigins();
        openApiOptions.defaultDocumentation(doc -> {
            doc.json(String.valueOf(HTTP_BAD_REQUEST), BadRequestResponse.class);
            doc.json(String.valueOf(HTTP_BAD_REQUEST), BadRequestResponse.class);
        });
    }
}
Also used : OpenApiOptions(io.javalin.plugin.openapi.OpenApiOptions) Info(io.swagger.v3.oas.models.info.Info) OpenApiPlugin(io.javalin.plugin.openapi.OpenApiPlugin)

Aggregations

OpenApiOptions (io.javalin.plugin.openapi.OpenApiOptions)5 Info (io.swagger.v3.oas.models.info.Info)4 OpenApiPlugin (io.javalin.plugin.openapi.OpenApiPlugin)3 SwaggerOptions (io.javalin.plugin.openapi.ui.SwaggerOptions)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ReDocOptions (io.javalin.plugin.openapi.ui.ReDocOptions)2 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 Javalin (io.javalin.Javalin)1 Context (io.javalin.http.Context)1 JavalinJackson (io.javalin.plugin.json.JavalinJackson)1 HttpMethod (io.javalin.plugin.openapi.annotations.HttpMethod)1 OpenApi (io.javalin.plugin.openapi.annotations.OpenApi)1 OpenApiContent (io.javalin.plugin.openapi.annotations.OpenApiContent)1 OpenApiParam (io.javalin.plugin.openapi.annotations.OpenApiParam)1 OpenApiResponse (io.javalin.plugin.openapi.annotations.OpenApiResponse)1 JacksonModelConverterFactory (io.javalin.plugin.openapi.jackson.JacksonModelConverterFactory)1 JacksonToJsonMapper (io.javalin.plugin.openapi.jackson.JacksonToJsonMapper)1 RedocOptionsObject (io.javalin.plugin.openapi.ui.RedocOptionsObject)1 RedocOptionsTheme (io.javalin.plugin.openapi.ui.RedocOptionsTheme)1 ModelResolver (io.swagger.v3.core.jackson.ModelResolver)1