use of io.swagger.v3.core.filter.SpecFilter in project swagger-core by swagger-api.
the class SpecFilterTest method filterAwayPetRefInSchemas.
@Test(description = "it should filter any Pet Ref in Schemas")
public void filterAwayPetRefInSchemas() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
final OpenAPI filtered = new SpecFilter().filter(openAPI, new NoPetRefSchemaFilter(), null, null, null);
validateSchemasInComponents(filtered.getComponents(), PET_MODEL);
}
use of io.swagger.v3.core.filter.SpecFilter in project swagger-core by swagger-api.
the class BaseOpenApiResource method getOpenApi.
protected Response getOpenApi(HttpHeaders headers, ServletConfig config, Application app, UriInfo uriInfo, String type) throws Exception {
String ctxId = getContextId(config);
OpenApiContext ctx = new JaxrsOpenApiContextBuilder().servletConfig(config).application(app).resourcePackages(resourcePackages).configLocation(configLocation).openApiConfiguration(openApiConfiguration).ctxId(ctxId).buildContext(true);
OpenAPI oas = ctx.read();
boolean pretty = false;
if (ctx.getOpenApiConfiguration() != null && Boolean.TRUE.equals(ctx.getOpenApiConfiguration().isPrettyPrint())) {
pretty = true;
}
if (oas != null) {
if (ctx.getOpenApiConfiguration() != null && ctx.getOpenApiConfiguration().getFilterClass() != null) {
try {
OpenAPISpecFilter filterImpl = (OpenAPISpecFilter) Class.forName(ctx.getOpenApiConfiguration().getFilterClass()).newInstance();
SpecFilter f = new SpecFilter();
oas = f.filter(oas, filterImpl, getQueryParams(uriInfo.getQueryParameters()), getCookies(headers), getHeaders(headers));
} catch (Exception e) {
LOGGER.error("failed to load filter", e);
}
}
}
if (oas == null) {
return Response.status(404).build();
}
if (StringUtils.isNotBlank(type) && type.trim().equalsIgnoreCase("yaml")) {
return Response.status(Response.Status.OK).entity(pretty ? ctx.getOutputYamlMapper().writer(new DefaultPrettyPrinter()).writeValueAsString(oas) : ctx.getOutputYamlMapper().writeValueAsString(oas)).type("application/yaml").build();
} else {
return Response.status(Response.Status.OK).entity(pretty ? ctx.getOutputJsonMapper().writer(new DefaultPrettyPrinter()).writeValueAsString(oas) : ctx.getOutputJsonMapper().writeValueAsString(oas)).type(MediaType.APPLICATION_JSON_TYPE).build();
}
}
Aggregations