Search in sources :

Example 6 with GenericOpenApiContext

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);
}
Also used : OpenAPIConfiguration(io.swagger.v3.oas.integration.api.OpenAPIConfiguration) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) OpenApiContext(io.swagger.v3.oas.integration.api.OpenApiContext) Test(org.testng.annotations.Test)

Example 7 with GenericOpenApiContext

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;
}
Also used : OpenApiContext(io.swagger.v3.oas.integration.api.OpenApiContext)

Example 8 with GenericOpenApiContext

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

Aggregations

OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)8 GenericOpenApiContext (io.swagger.v3.oas.integration.GenericOpenApiContext)6 OpenAPI (io.swagger.v3.oas.models.OpenAPI)6 Info (io.swagger.v3.oas.models.info.Info)5 Test (org.testng.annotations.Test)5 Reader (io.swagger.v3.jaxrs2.Reader)4 SwaggerConfiguration (io.swagger.v3.oas.integration.SwaggerConfiguration)4 OpenAPIConfiguration (io.swagger.v3.oas.integration.api.OpenAPIConfiguration)3 Operation (io.swagger.v3.oas.annotations.Operation)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Application (javax.ws.rs.core.Application)1