use of io.swagger.core.filter.SpecFilter in project ORCID-Source by ORCID.
the class SwaggerJSONResource method getListingYaml.
@GET
@Produces("application/yaml")
@Path(OrcidApiConstants.SWAGGER_FILE_YAML)
@ApiOperation(value = "The swagger definition in YAML", hidden = true)
public Response getListingYaml(@Context Application app, @Context HttpHeaders headers, @Context UriInfo uriInfo) {
Swagger swagger = (Swagger) context.getAttribute("swagger");
if (!initialized) {
swagger = scan(app);
}
try {
if (swagger != null) {
SwaggerSpecFilter filterImpl = FilterFactory.getFilter();
LOGGER.debug("using filter " + filterImpl);
if (filterImpl != null) {
SpecFilter f = new SpecFilter();
swagger = f.filter(swagger, filterImpl, getQueryParams(uriInfo.getQueryParameters()), getCookies(headers), getHeaders(headers));
}
String yaml = Yaml.mapper().writeValueAsString(swagger);
String[] parts = yaml.split("\n");
StringBuilder b = new StringBuilder();
for (String part : parts) {
//int pos = part.indexOf("!<");
//int endPos = part.indexOf(">");
b.append(part);
b.append("\n");
}
return Response.ok().entity(b.toString()).type("application/yaml").build();
}
} catch (Exception e) {
e.printStackTrace();
}
return Response.status(404).build();
}
use of io.swagger.core.filter.SpecFilter in project ORCID-Source by ORCID.
the class SwaggerJSONResource method getListingJson.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path(OrcidApiConstants.SWAGGER_FILE)
@ApiOperation(value = "The swagger definition in JSON", hidden = true)
public Response getListingJson(@Context Application app, @Context HttpHeaders headers, @Context UriInfo uriInfo) {
Swagger swagger = (Swagger) context.getAttribute("swagger");
if (!initialized) {
swagger = scan(app);
}
if (swagger != null) {
SwaggerSpecFilter filterImpl = FilterFactory.getFilter();
if (filterImpl != null) {
SpecFilter f = new SpecFilter();
swagger = f.filter(swagger, filterImpl, getQueryParams(uriInfo.getQueryParameters()), getCookies(headers), getHeaders(headers));
}
return Response.ok().entity(swagger).build();
} else {
return Response.status(404).build();
}
}
use of io.swagger.core.filter.SpecFilter in project swagger-core by swagger-api.
the class SpecFilterTest method filterAwayBrokenReferenceModelProperties.
@Test(description = "it should filter away broken reference model properties")
public void filterAwayBrokenReferenceModelProperties() throws IOException {
final Swagger swagger = getSwagger("specFiles/paramAndResponseRef.json");
assertNotNull(swagger.getDefinitions().get("Order"));
assertNotNull(swagger.getDefinitions().get("NoPropertiesModel"));
assertNotNull(swagger.getDefinitions().get("OrderTag"));
assertNotNull(swagger.getDefinitions().get("Tag"));
final NoOpOperationsFilter noOpfilter = new NoOpOperationsFilter();
Swagger filtered = new SpecFilter().filter(swagger, noOpfilter, null, null, null);
assertNotNull(filtered.getDefinitions().get("Order"));
assertNotNull(filtered.getDefinitions().get("NoPropertiesModel"));
assertNotNull(filtered.getDefinitions().get("OrderTag"));
assertNotNull(filtered.getDefinitions().get("Tag"));
final RemoveUnreferencedDefinitionsFilter refFilter = new RemoveUnreferencedDefinitionsFilter();
filtered = new SpecFilter().filter(swagger, refFilter, null, null, null);
assertNull(filtered.getDefinitions().get("Order"));
assertNull(filtered.getDefinitions().get("NoPropertiesModel"));
assertNull(filtered.getDefinitions().get("OrderTag"));
assertNotNull(filtered.getDefinitions().get("Tag"));
}
use of io.swagger.core.filter.SpecFilter in project swagger-core by swagger-api.
the class SpecFilterTest method cloneEverything.
@Test(description = "it should clone everything")
public void cloneEverything() throws IOException {
final Swagger swagger = getSwagger("specFiles/petstore.json");
final Swagger filtered = new SpecFilter().filter(swagger, new NoOpOperationsFilter(), null, null, null);
assertEquals(Json.pretty(swagger), Json.pretty(filtered));
}
use of io.swagger.core.filter.SpecFilter in project swagger-core by swagger-api.
the class SpecFilterTest method cloneWithoutModels.
@Test(description = "it should clone everything from JSON without models")
public void cloneWithoutModels() throws IOException {
final String json = ResourceUtils.loadClassResource(getClass(), "specFiles/noModels.json");
final Swagger swagger = Json.mapper().readValue(json, Swagger.class);
final Swagger filtered = new SpecFilter().filter(swagger, new NoOpOperationsFilter(), null, null, null);
SerializationMatchers.assertEqualsToJson(filtered, json);
}
Aggregations