Search in sources :

Example 16 with SwaggerConfiguration

use of io.swagger.v3.oas.integration.SwaggerConfiguration in project swagger-core by swagger-api.

the class JaxrsApplicationAndAnnotationScannerTest method shouldScanClassesFromPackages.

@Test(description = "scan a simple resource from packages")
public void shouldScanClassesFromPackages() throws Exception {
    SwaggerConfiguration config = new SwaggerConfiguration().resourcePackages(Stream.of("com.my.project.resources", "org.my.project.resources").collect(Collectors.toSet())).openAPI(new OpenAPI().info(new Info().description("TEST INFO DESC")));
    OpenApiContext ctx = new GenericOpenApiContext<>().openApiConfiguration(config).openApiReader(new Reader(config)).openApiScanner(scanner.application(null).openApiConfiguration(config)).init();
    OpenAPI openApi = ctx.read();
    assertNotNull(openApi);
    assertEquals(openApi.getPaths().keySet(), Arrays.asList("/packageA", "/packageB"));
}
Also used : Reader(io.swagger.v3.jaxrs2.Reader) GenericOpenApiContext(io.swagger.v3.oas.integration.GenericOpenApiContext) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) SwaggerConfiguration(io.swagger.v3.oas.integration.SwaggerConfiguration) GenericOpenApiContext(io.swagger.v3.oas.integration.GenericOpenApiContext) OpenApiContext(io.swagger.v3.oas.integration.api.OpenApiContext) Test(org.testng.annotations.Test)

Example 17 with SwaggerConfiguration

use of io.swagger.v3.oas.integration.SwaggerConfiguration in project swagger-core by swagger-api.

the class JaxrsApplicationAndAnnotationScannerTest method shouldScanClassesFromPackagesAndApplication.

@Test(description = "scan classes from the packages and Application")
public void shouldScanClassesFromPackagesAndApplication() throws Exception {
    SwaggerConfiguration openApiConfiguration = new SwaggerConfiguration();
    openApiConfiguration.setResourcePackages(Collections.singleton("com.my.project.resources"));
    scanner.setConfiguration(openApiConfiguration);
    assertEquals(scanner.classes().size(), 2);
    assertTrue(scanner.classes().contains(ResourceInPackageA.class));
    assertTrue(scanner.classes().contains(ResourceInApplication.class));
}
Also used : SwaggerConfiguration(io.swagger.v3.oas.integration.SwaggerConfiguration) ResourceInPackageA(com.my.project.resources.ResourceInPackageA) Test(org.testng.annotations.Test)

Example 18 with SwaggerConfiguration

use of io.swagger.v3.oas.integration.SwaggerConfiguration 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 19 with SwaggerConfiguration

use of io.swagger.v3.oas.integration.SwaggerConfiguration 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

SwaggerConfiguration (io.swagger.v3.oas.integration.SwaggerConfiguration)16 OpenAPI (io.swagger.v3.oas.models.OpenAPI)11 OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)10 Test (org.testng.annotations.Test)9 GenericOpenApiContext (io.swagger.v3.oas.integration.GenericOpenApiContext)6 Info (io.swagger.v3.oas.models.info.Info)6 OpenApiConfigurationException (io.swagger.v3.oas.integration.OpenApiConfigurationException)5 HashSet (java.util.HashSet)5 DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)4 Reader (io.swagger.v3.jaxrs2.Reader)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 ResourceInPackageA (com.my.project.resources.ResourceInPackageA)2 OpenAPISpecFilter (io.swagger.v3.core.filter.OpenAPISpecFilter)2 SpecFilter (io.swagger.v3.core.filter.SpecFilter)2 JaxrsOpenApiContextBuilder (io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder)2 OpenAPIDefinition (io.swagger.v3.oas.annotations.OpenAPIDefinition)2 GenericOpenApiContextBuilder (io.swagger.v3.oas.integration.GenericOpenApiContextBuilder)2 IgnoredPackages (io.swagger.v3.oas.integration.IgnoredPackages)2 OpenAPIConfiguration (io.swagger.v3.oas.integration.api.OpenAPIConfiguration)2