use of io.swagger.v3.oas.integration.GenericOpenApiContext in project swagger-core by swagger-api.
the class JaxrsApplicationAndResourcePackagesAnnotationScannerTest method shouldScanForClassesWhenApplicationIsNotSet.
@Test(description = "scan classes from Application when it is not set")
public void shouldScanForClassesWhenApplicationIsNotSet() throws Exception {
SwaggerConfiguration config = new SwaggerConfiguration().openAPI(new OpenAPI().info(new Info().description("TEST INFO DESC")));
OpenApiContext ctx = new GenericOpenApiContext<>().openApiConfiguration(config).openApiReader(new Reader(config)).openApiScanner(scanner.openApiConfiguration(config)).init();
OpenAPI openApi = ctx.read();
assertNotNull(openApi);
assertNull(openApi.getPaths());
}
use of io.swagger.v3.oas.integration.GenericOpenApiContext in project swagger-core by swagger-api.
the class JaxrsApplicationAndResourcePackagesAnnotationScannerTest method shouldScanOnlyApplicationClasses.
@Test(description = "scan classes from Application")
public void shouldScanOnlyApplicationClasses() throws Exception {
SwaggerConfiguration config = new SwaggerConfiguration().openAPI(new OpenAPI().info(new Info().description("TEST INFO DESC")));
Application application = new Application() {
@Override
public Set<Class<?>> getClasses() {
return Collections.singleton(ResourceInPackageA.class);
}
};
OpenApiContext ctx = new GenericOpenApiContext<>().openApiConfiguration(config).openApiReader(new Reader(config)).openApiScanner(scanner.application(application).openApiConfiguration(config)).init();
OpenAPI openApi = ctx.read();
assertNotNull(openApi);
assertEquals(openApi.getPaths().keySet(), Arrays.asList("/packageA"));
}
use of io.swagger.v3.oas.integration.GenericOpenApiContext in project swagger-core by swagger-api.
the class JaxrsApplicationAndResourcePackagesAnnotationScannerTest method shouldScanOnlyResourcePackagesClasses.
@Test(description = "scan classes from resource packages only")
public void shouldScanOnlyResourcePackagesClasses() 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(new JaxrsApplicationAndResourcePackagesAnnotationScanner().openApiConfiguration(config)).init();
OpenAPI openApi = ctx.read();
assertNotNull(openApi);
assertEquals(openApi.getPaths().keySet(), Arrays.asList("/packageA", "/packageB"));
}
use of io.swagger.v3.oas.integration.GenericOpenApiContext in project cxf by apache.
the class OpenApiCustomizedResource method getOpenApi.
@GET
@Produces({ MediaType.APPLICATION_JSON, "application/yaml" })
@Operation(hidden = true)
public Response getOpenApi(@Context ServletConfig config, @Context HttpHeaders headers, @Context UriInfo uriInfo, @PathParam("type") String type) throws Exception {
if (customizer != null) {
final OpenAPIConfiguration configuration = customizer.customize(getOpenApiConfiguration());
setOpenApiConfiguration(configuration);
// By default, the OpenApiContext instance is cached. It means that the configuration
// changes won't be taken into account (due to the deep copying rather than reference
// passing). In order to reflect any changes which customization may do, we have to
// update reader's configuration directly.
final String ctxId = ServletConfigContextUtils.getContextIdFromServletConfig(config);
final OpenApiContext ctx = OpenApiContextLocator.getInstance().getOpenApiContext(ctxId);
if (ctx instanceof GenericOpenApiContext<?>) {
((GenericOpenApiContext<?>) ctx).getOpenApiReader().setConfiguration(configuration);
customizer.customize(ctx.read());
}
}
return super.getOpenApi(headers, uriInfo, type);
}
use of io.swagger.v3.oas.integration.GenericOpenApiContext in project swagger-core by swagger-api.
the class IntegrationTest method shouldInitialize.
@Test(description = "initialize a context and read")
public void shouldInitialize() throws Exception {
OpenAPIConfiguration 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).init();
OpenAPI openApi = ctx.read();
assertNotNull(openApi);
}
Aggregations