use of io.swagger.models.Info in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method generateApiFromSwaggerResource.
/**
* return API Object
*
* @param provider Provider of the API.
* @param apiDefinition API definition as string
* @return API object.
* @throws APIManagementException If failed to generate API from swagger.
*/
@Override
public API.APIBuilder generateApiFromSwaggerResource(String provider, String apiDefinition) throws APIManagementException {
SwaggerParser swaggerParser = new SwaggerParser();
Swagger swagger = swaggerParser.parse(apiDefinition);
if (swagger == null) {
throw new APIManagementException("Swagger could not be generated from provided API definition");
}
Info apiInfo = swagger.getInfo();
if (apiInfo == null) {
throw new APIManagementException("Swagger doesn't contains the info");
} else {
String apiName = apiInfo.getTitle();
String apiVersion = apiInfo.getVersion();
String apiDescription = apiInfo.getDescription();
Contact contact = apiInfo.getContact();
BusinessInformation businessInformation = new BusinessInformation();
if (contact != null) {
businessInformation.setBusinessOwner(contact.getName());
businessInformation.setBusinessOwnerEmail(contact.getEmail());
}
API.APIBuilder apiBuilder = new API.APIBuilder(provider, apiName, apiVersion);
apiBuilder.businessInformation(businessInformation);
apiBuilder.description(apiDescription);
apiBuilder.context(swagger.getBasePath());
List<APIResource> apiResourceList = parseSwaggerAPIResources(new StringBuilder(apiDefinition));
Map<String, UriTemplate> uriTemplateMap = new HashMap();
for (APIResource apiResource : apiResourceList) {
uriTemplateMap.put(apiResource.getUriTemplate().getTemplateId(), apiResource.getUriTemplate());
}
apiBuilder.uriTemplates(uriTemplateMap);
apiBuilder.id(UUID.randomUUID().toString());
return apiBuilder;
}
}
use of io.swagger.models.Info in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method generateSwaggerFromResources.
/**
* generate the swagger from uri templates.
*
* @param api API Object
* @return Generated swagger resources as string.
*/
@Override
public String generateSwaggerFromResources(API.APIBuilder api) {
Swagger swagger = new Swagger();
Info info = new Info();
info.setTitle(api.getName());
info.setDescription(api.getDescription());
Contact contact = new Contact();
if (api.getBusinessInformation() != null) {
BusinessInformation businessInformation = api.getBusinessInformation();
contact.setName(businessInformation.getBusinessOwner());
contact.setEmail(businessInformation.getBusinessOwnerEmail());
}
info.setContact(contact);
info.setVersion(api.getVersion());
swagger.setInfo(info);
addSecuritySchemeToSwaggerDefinition(swagger, api.build());
Map<String, Path> stringPathMap = new HashMap();
for (UriTemplate uriTemplate : api.getUriTemplates().values()) {
String uriTemplateString = uriTemplate.getUriTemplate();
List<Parameter> parameterList = getParameters(uriTemplateString);
if (uriTemplate.getParameters() == null || uriTemplate.getParameters().isEmpty()) {
if (!HttpMethod.GET.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.DELETE.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.OPTIONS.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.HEAD.toString().equalsIgnoreCase(uriTemplate.getHttpVerb())) {
parameterList.add(getDefaultBodyParameter());
}
} else {
for (URITemplateParam uriTemplateParam : uriTemplate.getParameters()) {
Parameter parameter = getParameterFromURITemplateParam(uriTemplateParam);
parameterList.add(parameter);
}
}
Operation operation = new Operation();
operation.setParameters(parameterList);
operation.setOperationId(uriTemplate.getTemplateId());
// having content types like */* can break swagger definition
if (!StringUtils.isEmpty(uriTemplate.getContentType()) && !uriTemplate.getContentType().contains("*")) {
List<String> consumesList = new ArrayList<>();
consumesList.add(uriTemplate.getContentType());
operation.setConsumes(consumesList);
}
operation.addResponse("200", getDefaultResponse());
if (!APIMgtConstants.AUTH_NO_AUTHENTICATION.equals(uriTemplate.getAuthType()) && ((api.getSecurityScheme() & 2) == 2)) {
log.debug("API security scheme : API Key Scheme ---- Resource Auth Type : Not None");
operation.addSecurity(APIMgtConstants.SWAGGER_APIKEY, null);
}
if (!APIMgtConstants.AUTH_NO_AUTHENTICATION.equals(uriTemplate.getAuthType()) && ((api.getSecurityScheme() & 1) == 1)) {
log.debug("API security scheme : Oauth Scheme ---- Resource Auth Type : Not None");
operation.addSecurity(APIMgtConstants.SWAGGER_OAUTH2, null);
}
if (stringPathMap.containsKey(uriTemplateString)) {
Path path = stringPathMap.get(uriTemplateString);
path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
} else {
Path path = new Path();
path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
stringPathMap.put(uriTemplateString, path);
}
}
swagger.setPaths(stringPathMap);
swagger.setPaths(stringPathMap);
return Json.pretty(swagger);
}
use of io.swagger.models.Info in project cxf by apache.
the class Java2SwaggerMojo method configureSwagger.
private void configureSwagger() {
swagger = new Swagger();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
Info info = new Info();
Contact swaggerContact = new Contact();
License swaggerLicense = new License();
swaggerLicense.name(this.license).url(this.licenseUrl);
swaggerContact.name(this.contact);
info.version(this.version).description(this.description).contact(swaggerContact).license(swaggerLicense).title(this.title);
swagger.setInfo(info);
if (this.schemes != null) {
for (String scheme : this.schemes) {
swagger.scheme(Scheme.forValue(scheme));
}
}
swagger.setHost(this.host);
swagger.setBasePath(this.basePath);
}
use of io.swagger.models.Info in project apiee by phillip-kruger.
the class SwaggerCache method getSwaggerInfo.
private Info getSwaggerInfo() {
Contact contact = getSwaggerContact();
License license = getSwaggerLicense();
String title = whiteLabel.getProperty(INFO_TITLE, null);
String description = whiteLabel.getProperty(INFO_DESC, null);
String version = whiteLabel.getProperty(INFO_VERSION, null);
String terms = whiteLabel.getProperty(INFO_TERMS, null);
if (isSet(title, description, version, terms) || contact != null || license != null) {
Info info = new Info();
if (isSet(title))
info.setTitle(title);
if (isSet(description))
info.setDescription(description);
if (isSet(version))
info.setVersion(version);
if (isSet(terms))
info.setTermsOfService(terms);
if (contact != null)
info.setContact(contact);
if (license != null)
info.setLicense(license);
return info;
}
return null;
}
use of io.swagger.models.Info in project incubator-servicecomb-java-chassis by apache.
the class TestDefinition method testMicroserviceMetaManager.
@Test
public void testMicroserviceMetaManager() throws Exception {
MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
microserviceMetaManager.getOrCreateMicroserviceMeta("app:testname");
Assert.assertEquals("microservice meta manager", microserviceMetaManager.getName());
Assert.assertEquals("Not allow register repeat data, name=%s, key=%s", microserviceMetaManager.getRegisterErrorFmt());
Assert.assertEquals(0, microserviceMetaManager.getAllSchemaMeta("app:testname").size());
Swagger oSwagger = new Swagger();
Info oInfo = new Info();
oInfo.setVendorExtension("x-java-interface", "java.lang.String");
oSwagger.setInfo(oInfo);
Assert.assertEquals("java.lang.String", (ClassUtils.getJavaInterface(oSwagger)).getName());
oInfo.setVendorExtension("x-java-class", "java.lang.String");
}
Aggregations