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"));
}
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));
}
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);
}
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);
}
Aggregations