Search in sources :

Example 41 with DefaultPrettyPrinter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project swagger-core by swagger-api.

the class SimpleBuilderTest method writeJson.

public static String writeJson(Object value) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    return mapper.writer(new DefaultPrettyPrinter()).writeValueAsString(value);
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 42 with DefaultPrettyPrinter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project swagger-core by swagger-api.

the class SortedOutputTest method configOutputTest.

@Test(description = "config output test")
public void configOutputTest() throws Exception {
    SwaggerConfiguration openApiConfiguration = new SwaggerConfiguration().objectMapperProcessorClass(SortedProcessor.class.getName()).resourcePackages(Collections.singleton("com.my.sorted.resources"));
    OpenApiContext ctx = new JaxrsOpenApiContext<>().openApiConfiguration(openApiConfiguration).init();
    OpenAPI openApi = ctx.read();
    String sorted = ctx.getOutputYamlMapper().writer(new DefaultPrettyPrinter()).writeValueAsString(openApi);
    openApiConfiguration = new SwaggerConfiguration().resourcePackages(Collections.singleton("com.my.sorted.resources"));
    ctx = new JaxrsOpenApiContext<>().openApiConfiguration(openApiConfiguration).init();
    String notSorted = ctx.getOutputYamlMapper().writer(new DefaultPrettyPrinter()).writeValueAsString(openApi);
    assertEquals(sorted, expectedSorted);
    assertEquals(notSorted, expectedNotSorted);
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) SwaggerConfiguration(io.swagger.v3.oas.integration.SwaggerConfiguration) OpenApiContext(io.swagger.v3.oas.integration.api.OpenApiContext) GenericOpenApiContext(io.swagger.v3.oas.integration.GenericOpenApiContext) Test(org.testng.annotations.Test)

Example 43 with DefaultPrettyPrinter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project swagger-core by swagger-api.

the class SortedOutputTest method sortOutputTest.

@Test(description = "sort output test")
public void sortOutputTest() throws Exception {
    SwaggerConfiguration openApiConfiguration = new SwaggerConfiguration().sortOutput(true).resourcePackages(Collections.singleton("com.my.sorted.resources"));
    OpenApiContext ctx = new JaxrsOpenApiContext<>().openApiConfiguration(openApiConfiguration).init();
    OpenAPI openApi = ctx.read();
    String sorted = ctx.getOutputYamlMapper().writer(new DefaultPrettyPrinter()).writeValueAsString(openApi);
    openApiConfiguration = new SwaggerConfiguration().resourcePackages(Collections.singleton("com.my.sorted.resources"));
    ctx = new JaxrsOpenApiContext<>().openApiConfiguration(openApiConfiguration).init();
    String notSorted = ctx.getOutputYamlMapper().writer(new DefaultPrettyPrinter()).writeValueAsString(openApi);
    assertEquals(sorted, expectedSorted);
    assertEquals(notSorted, expectedNotSorted);
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) SwaggerConfiguration(io.swagger.v3.oas.integration.SwaggerConfiguration) OpenApiContext(io.swagger.v3.oas.integration.api.OpenApiContext) GenericOpenApiContext(io.swagger.v3.oas.integration.GenericOpenApiContext) Test(org.testng.annotations.Test)

Aggregations

DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)42 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 IOException (java.io.IOException)9 File (java.io.File)7 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)6 DefaultIndenter (com.fasterxml.jackson.core.util.DefaultIndenter)6 OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)6 OpenAPI (io.swagger.v3.oas.models.OpenAPI)6 SwaggerConfiguration (io.swagger.v3.oas.integration.SwaggerConfiguration)4 PrettyPrinter (com.fasterxml.jackson.core.PrettyPrinter)3 JsonFactory (com.fasterxml.jackson.core.json.JsonFactory)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)3 OpenAPISpecFilter (io.swagger.v3.core.filter.OpenAPISpecFilter)3 SpecFilter (io.swagger.v3.core.filter.SpecFilter)3 OpenApiConfigurationException (io.swagger.v3.oas.integration.OpenApiConfigurationException)3 BufferedWriter (java.io.BufferedWriter)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3