use of io.swagger.models.Swagger in project carbon-apimgt by wso2.
the class DynamicHtmlGenTestCase method testPreprocessSwagger.
@Test
public void testPreprocessSwagger() throws Exception {
DynamicHtmlGen htmlGen = new DynamicHtmlGen();
Swagger swagger = new Swagger();
Path path = new Path();
Operation operation = new Operation();
List<String> tags = new ArrayList<>();
tags.add("tag1");
tags.add("tag2");
tags.add("tag3");
tags.add("tag4");
operation.setTags(tags);
path.setGet(operation);
swagger.path("get_sample", path);
htmlGen.preprocessSwagger(swagger);
List<String> processedTags = swagger.getPath("get_sample").getGet().getTags();
Assert.assertEquals(processedTags.size(), 1);
Assert.assertEquals(processedTags.get(0), "tag1");
}
use of io.swagger.models.Swagger 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.models.Swagger 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.models.Swagger in project ORCID-Source by ORCID.
the class MemberSwaggerResource method scan.
/**
* Scan the classes and add in the OAuth information
*
*/
@Override
protected synchronized Swagger scan(Application app) {
// tell swagger to pick up our jaxb annotations
Json.mapper().registerModule(new JaxbAnnotationModule());
Swagger s = super.scan(app);
OAuth2Definition oauth = new OAuth2Definition();
oauth.accessCode(this.authEndPoint, this.tokenEndPoint);
oauth.scope(ScopePathType.READ_LIMITED.value(), "Read Limited record");
oauth.scope(ScopePathType.PERSON_UPDATE.value(), "Update person");
oauth.scope(ScopePathType.ACTIVITIES_UPDATE.value(), "Update activities");
s.securityDefinition("orcid_auth", oauth);
OAuth2Definition oauthTwoLegs = new OAuth2Definition();
oauthTwoLegs.application(this.tokenEndPoint);
oauthTwoLegs.scope(ScopePathType.PREMIUM_NOTIFICATION.value(), "Notifications");
oauthTwoLegs.scope(ScopePathType.READ_PUBLIC.value(), "Read Public record");
oauthTwoLegs.scope(ScopePathType.GROUP_ID_RECORD_READ.value(), "Read groups");
oauthTwoLegs.scope(ScopePathType.GROUP_ID_RECORD_UPDATE.value(), "Update groups");
s.securityDefinition("orcid_two_legs", oauthTwoLegs);
return s;
}
use of io.swagger.models.Swagger in project camel by apache.
the class RestSwaggerReader method read.
/**
* Read the REST-DSL definition's and parse that as a Swagger model representation
*
* @param rests the rest-dsl
* @param route optional route path to filter the rest-dsl to only include from the chose route
* @param config the swagger configuration
* @param classResolver class resolver to use
* @return the swagger model
*/
public Swagger read(List<RestDefinition> rests, String route, BeanConfig config, String camelContextId, ClassResolver classResolver) {
Swagger swagger = new Swagger();
for (RestDefinition rest : rests) {
if (ObjectHelper.isNotEmpty(route) && !route.equals("/")) {
// filter by route
if (!rest.getPath().equals(route)) {
continue;
}
}
parse(swagger, rest, camelContextId, classResolver);
}
// configure before returning
swagger = config.configure(swagger);
return swagger;
}
Aggregations