Search in sources :

Example 11 with 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(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);
    }
}
Also used : AnnotationAttachmentAttributeValueNode(org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode) License(io.swagger.models.License) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 12 with 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);
    }
}
Also used : AnnAttributeKeyValuePair(org.ballerinalang.util.codegen.AnnAttributeKeyValuePair) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) License(io.swagger.models.License)

Example 13 with 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;
}
Also used : License(io.swagger.models.License) Info(io.swagger.models.Info) Contact(io.swagger.models.Contact)

Example 14 with License

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;
}
Also used : License(io.swagger.models.License)

Example 15 with 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");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) OAuth2Definition(io.swagger.models.auth.OAuth2Definition) License(io.swagger.models.License) SecuritySchemeDefinition(io.swagger.models.auth.SecuritySchemeDefinition) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) Contact(io.swagger.models.Contact) ApiKeyAuthDefinition(io.swagger.models.auth.ApiKeyAuthDefinition) Swagger(io.swagger.models.Swagger) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Test(org.testng.annotations.Test)

Aggregations

License (io.swagger.models.License)19 Contact (io.swagger.models.Contact)15 Info (io.swagger.models.Info)9 Info (io.swagger.annotations.Info)6 Swagger (io.swagger.models.Swagger)6 ApiKeyAuthDefinition (io.swagger.models.auth.ApiKeyAuthDefinition)3 OAuth2Definition (io.swagger.models.auth.OAuth2Definition)3 Operation (io.swagger.models.Operation)2 BasicAuthDefinition (io.swagger.models.auth.BasicAuthDefinition)2 SecuritySchemeDefinition (io.swagger.models.auth.SecuritySchemeDefinition)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)2 AnnotationAttachmentAttributeValueNode (org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Lists (com.google.common.collect.Lists)1 EimDbCreator (io.elastest.eim.database.mysql.EimDbCreator)1 SwaggerContextService (io.swagger.jaxrs.config.SwaggerContextService)1