use of io.swagger.models.License in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method createLicenseModel.
/**
* Creates the license swagger definition.
* @param annotationAttributeValue The ballerina annotation attribute value for license.
* @param info The info definition which the license needs to be build on.
*/
private void createLicenseModel(AnnotationAttachmentAttributeValueNode annotationAttributeValue, Info info) {
if (null != annotationAttributeValue) {
AnnotationAttachmentNode licenseAnnotationAttachment = (AnnotationAttachmentNode) annotationAttributeValue.getValue();
Map<String, AnnotationAttachmentAttributeValueNode> licenseAttributes = this.listToMap(licenseAnnotationAttachment);
License license = new License();
if (licenseAttributes.containsKey("name")) {
license.setName(this.getStringLiteralValue(licenseAttributes.get("name")));
}
if (licenseAttributes.containsKey("url")) {
license.setUrl(this.getStringLiteralValue(licenseAttributes.get("url")));
}
info.setLicense(license);
}
}
use of io.swagger.models.License in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method createLicenseModel.
/**
* Creates the license swagger definition.
* @param annotationAttributeValue The ballerina annotation attribute value for license.
* @param info The info definition which the license needs to be build on.
*/
private void createLicenseModel(AnnAttributeValue annotationAttributeValue, Info info) {
if (null != annotationAttributeValue) {
AnnAttachmentInfo licenseAnnotationAttachment = annotationAttributeValue.getAnnotationAttachmentValue();
License license = new License();
for (AnnAttributeKeyValuePair annAttributeKeyValuePair : licenseAnnotationAttachment.getAttributeKeyValuePairs()) {
if ("name".equals(annAttributeKeyValuePair.getAttributeName())) {
license.setName(annAttributeKeyValuePair.getAttributeValue().getStringValue());
} else if ("url".equals(annAttributeKeyValuePair.getAttributeName())) {
license.setUrl(annAttributeKeyValuePair.getAttributeValue().getStringValue());
}
}
info.setLicense(license);
}
}
use of io.swagger.models.License 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.License in project incubator-servicecomb-java-chassis by apache.
the class SwaggerDefinitionProcessor method convertLicense.
private License convertLicense(io.swagger.annotations.License licenseAnnotation) {
License license = new License();
license.setName(licenseAnnotation.name());
license.setUrl(licenseAnnotation.url());
return license;
}
use of io.swagger.models.License in project swagger-parser by swagger-api.
the class LegacyConverterTest method convertSingleFile.
/**
* reads a single-file swagger definition
*/
@Test
public void convertSingleFile() throws Exception {
Swagger swagger = converter.read("src/test/resources/specs/v1_2/singleFile.json");
assertTrue(swagger.getSecurityDefinitions().size() == 2);
SecuritySchemeDefinition auth = swagger.getSecurityDefinitions().get("oauth2");
assertNotNull(auth);
assertEquals(auth.getClass(), OAuth2Definition.class);
OAuth2Definition oauth2 = (OAuth2Definition) auth;
assertEquals(oauth2.getFlow(), "implicit");
assertEquals(oauth2.getAuthorizationUrl(), "http://petstore.swagger.io/oauth/dialog");
assertTrue(oauth2.getScopes().size() == 2);
Map<String, String> scopes = oauth2.getScopes();
assertEquals(scopes.get("email"), "Access to your email address");
assertEquals(scopes.get("pets"), "Access to your pets");
auth = swagger.getSecurityDefinitions().get("apiKey");
assertNotNull(auth);
assertEquals(auth.getClass(), ApiKeyAuthDefinition.class);
ApiKeyAuthDefinition apiKey = (ApiKeyAuthDefinition) auth;
assertEquals(apiKey.getName(), "api_key");
assertEquals(apiKey.getIn(), In.HEADER);
assertEquals(swagger.getSwagger(), "2.0");
assertEquals(swagger.getHost(), "petstore.swagger.io");
assertEquals(swagger.getBasePath(), "/api");
assertNotNull(swagger.getInfo());
Info info = swagger.getInfo();
assertEquals(info.getVersion(), "1.0.0");
assertEquals(info.getTitle(), "Swagger Sample App");
assertEquals(info.getTermsOfService(), "http://swagger.io/terms/");
Contact contact = info.getContact();
assertEquals(contact.getUrl(), "apiteam@swagger.io");
License license = info.getLicense();
assertEquals(license.getName(), "Apache 2.0");
assertEquals(license.getUrl(), "http://www.apache.org/licenses/LICENSE-2.0.html");
assertTrue(swagger.getDefinitions().size() == 3);
assertTrue(swagger.getPaths().size() == 5);
Operation patchOperation = swagger.getPaths().get("/pet/{petId}").getPatch();
List<Map<String, List<String>>> security = patchOperation.getSecurity();
assertTrue(security.size() == 1);
Map<String, List<String>> securityDetail = security.get(0);
String key = securityDetail.keySet().iterator().next();
assertEquals(key, "oauth2");
List<String> oauth2Scopes = securityDetail.get(key);
assertEquals(oauth2Scopes.size(), 1);
assertEquals(oauth2Scopes.get(0), "test:anything");
Operation fetchOperation = swagger.getPaths().get("/pet/findByStatus").getGet();
QueryParameter param = (QueryParameter) fetchOperation.getParameters().get(0);
assertEquals(param.getDefaultValue(), "available");
List<String> _enum = param.getEnum();
assertEquals(_enum.get(0), "available");
assertEquals(_enum.get(1), "pending");
assertEquals(_enum.get(2), "sold");
}
Aggregations