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);
}
use of io.swagger.v3.oas.integration.GenericOpenApiContext in project swagger-core by swagger-api.
the class GenericOpenApiContextBuilder method buildContext.
@Override
public OpenApiContext buildContext(boolean init) throws OpenApiConfigurationException {
if (StringUtils.isBlank(ctxId)) {
ctxId = OpenApiContext.OPENAPI_CONTEXT_ID_DEFAULT;
}
OpenApiContext ctx = OpenApiContextLocator.getInstance().getOpenApiContext(ctxId);
if (ctx == null) {
OpenApiContext rootCtx = OpenApiContextLocator.getInstance().getOpenApiContext(OpenApiContext.OPENAPI_CONTEXT_ID_DEFAULT);
ctx = new GenericOpenApiContext().openApiConfiguration(openApiConfiguration).id(ctxId).parent(rootCtx);
if (ctx.getConfigLocation() == null && configLocation != null) {
((GenericOpenApiContext) ctx).configLocation(configLocation);
}
if (((GenericOpenApiContext) ctx).getResourcePackages() == null && resourcePackages != null) {
((GenericOpenApiContext) ctx).resourcePackages(resourcePackages);
}
if (((GenericOpenApiContext) ctx).getResourceClasses() == null && resourceClasses != null) {
((GenericOpenApiContext) ctx).resourceClasses(resourceClasses);
}
if (init) {
// includes registering itself with OpenApiContextLocator
ctx.init();
}
}
return ctx;
}
use of io.swagger.v3.oas.integration.GenericOpenApiContext 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"));
}
Aggregations