Search in sources :

Example 1 with GenericOpenApiContext

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());
}
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 2 with GenericOpenApiContext

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"));
}
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) Application(javax.ws.rs.core.Application) 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 3 with GenericOpenApiContext

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

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);
}
Also used : OpenAPIConfiguration(io.swagger.v3.oas.integration.api.OpenAPIConfiguration) GenericOpenApiContext(io.swagger.v3.oas.integration.GenericOpenApiContext) GenericOpenApiContext(io.swagger.v3.oas.integration.GenericOpenApiContext) OpenApiContext(io.swagger.v3.oas.integration.api.OpenApiContext) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 5 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)

Aggregations

OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)7 GenericOpenApiContext (io.swagger.v3.oas.integration.GenericOpenApiContext)5 OpenAPI (io.swagger.v3.oas.models.OpenAPI)5 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)2 Operation (io.swagger.v3.oas.annotations.Operation)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 Application (javax.ws.rs.core.Application)1