Search in sources :

Example 36 with Info

use of io.swagger.models.Info in project ballerina by ballerina-lang.

the class SwaggerServiceMapper method parseServiceInfoAnnotationAttachment.

/**
 * Parses the 'ServiceInfo' annotation and build the swagger definition for it.
 * @param service The ballerina service which has the 'ServiceInfo' annotation attachment.
 * @param swagger The swagger definition to be built up.
 */
private void parseServiceInfoAnnotationAttachment(ServiceNode service, Swagger swagger) {
    Optional<? extends AnnotationAttachmentNode> swaggerInfoAnnotation = service.getAnnotationAttachments().stream().filter(a -> null != swaggerAlias && this.swaggerAlias.equals(a.getPackageAlias().getValue()) && "ServiceInfo".equals(a.getAnnotationName().getValue())).findFirst();
    Info info = new Info().version("1.0.0").title(service.getName().getValue());
    if (swaggerInfoAnnotation.isPresent()) {
        Map<String, AnnotationAttachmentAttributeValueNode> attributes = this.listToMap(swaggerInfoAnnotation.get());
        if (attributes.containsKey("serviceVersion")) {
            info.version(this.getStringLiteralValue(attributes.get("serviceVersion")));
        }
        if (attributes.containsKey("title")) {
            info.title(this.getStringLiteralValue(attributes.get("title")));
        }
        if (attributes.containsKey("description")) {
            info.description(this.getStringLiteralValue(attributes.get("description")));
        }
        if (attributes.containsKey("termsOfService")) {
            info.termsOfService(this.getStringLiteralValue(attributes.get("termsOfService")));
        }
        this.createContactModel(attributes.get("contact"), info);
        this.createLicenseModel(attributes.get("license"), info);
        this.createExternalDocModel(attributes.get("externalDoc"), swagger);
        this.createTagModel(attributes.get("tags"), swagger);
        this.createOrganizationModel(attributes.get("organization"), info);
        this.createDevelopersModel(attributes.get("developers"), info);
    }
    swagger.setInfo(info);
}
Also used : Scheme(io.swagger.models.Scheme) ApiKeyAuthDefinition(io.swagger.models.auth.ApiKeyAuthDefinition) Swagger(io.swagger.models.Swagger) Tag(io.swagger.models.Tag) License(io.swagger.models.License) Json(io.swagger.util.Json) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) BasicAuthDefinition(io.swagger.models.auth.BasicAuthDefinition) Lists(com.google.common.collect.Lists) Map(java.util.Map) Organization(org.ballerinalang.ballerina.swagger.convertor.service.model.Organization) LinkedList(java.util.LinkedList) Contact(io.swagger.models.Contact) OAuth2Definition(io.swagger.models.auth.OAuth2Definition) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SecuritySchemeDefinition(io.swagger.models.auth.SecuritySchemeDefinition) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) Info(io.swagger.models.Info) Developer(org.ballerinalang.ballerina.swagger.convertor.service.model.Developer) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode) ServiceNode(org.ballerinalang.model.tree.ServiceNode) AnnotationAttachmentAttributeValueNode(org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode) List(java.util.List) AnnotationAttachmentAttributeNode(org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeNode) ExternalDocs(io.swagger.models.ExternalDocs) LiteralNode(org.ballerinalang.model.tree.expressions.LiteralNode) Optional(java.util.Optional) In(io.swagger.models.auth.In) AnnotationAttachmentAttributeValueNode(org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode) Info(io.swagger.models.Info)

Example 37 with Info

use of io.swagger.models.Info in project syndesis by syndesisio.

the class BaseSwaggerConnectorGenerator method determineConnectorName.

@Override
protected final String determineConnectorName(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
    final SwaggerModelInfo modelInfo = parseSpecification(connectorSettings, false);
    if (!modelInfo.getErrors().isEmpty()) {
        throw new IllegalArgumentException("Given Swagger specification contains errors: " + modelInfo);
    }
    final Swagger swagger = modelInfo.getModel();
    final Info info = swagger.getInfo();
    if (info == null) {
        return super.determineConnectorName(connectorTemplate, connectorSettings);
    }
    final String title = info.getTitle();
    if (title == null) {
        return super.determineConnectorName(connectorTemplate, connectorSettings);
    }
    return title;
}
Also used : Swagger(io.swagger.models.Swagger) Info(io.swagger.models.Info)

Example 38 with Info

use of io.swagger.models.Info in project java-chassis by ServiceComb.

the class SwaggerUtils method getInterface.

public static Class<?> getInterface(Swagger swagger) {
    Info info = swagger.getInfo();
    if (info == null) {
        return null;
    }
    String name = getInterfaceName(info.getVendorExtensions());
    if (StringUtils.isEmpty(name)) {
        return null;
    }
    return ReflectUtils.getClassByName(name);
}
Also used : Info(io.swagger.models.Info)

Example 39 with Info

use of io.swagger.models.Info in project java-chassis by ServiceComb.

the class AbstractSwaggerGenerator method correctInfo.

private void correctInfo() {
    Info info = swagger.getInfo();
    if (info == null) {
        info = new Info();
        swagger.setInfo(info);
    }
    if (StringUtils.isEmpty(info.getTitle())) {
        info.setTitle("swagger definition for " + cls.getName());
    }
    if (StringUtils.isEmpty(info.getVersion())) {
        info.setVersion("1.0.0");
    }
    setJavaInterface(info);
}
Also used : Info(io.swagger.models.Info)

Aggregations

Info (io.swagger.models.Info)39 Swagger (io.swagger.models.Swagger)26 Contact (io.swagger.models.Contact)12 Operation (io.swagger.models.Operation)10 Path (io.swagger.models.Path)9 Test (org.testng.annotations.Test)8 License (io.swagger.models.License)7 QueryParameter (io.swagger.models.parameters.QueryParameter)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 ApiKeyAuthDefinition (io.swagger.models.auth.ApiKeyAuthDefinition)5 PathParameter (io.swagger.models.parameters.PathParameter)5 Model (io.swagger.models.Model)4 OAuth2Definition (io.swagger.models.auth.OAuth2Definition)4 Parameter (io.swagger.models.parameters.Parameter)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 UriTemplate (org.wso2.carbon.apimgt.core.models.UriTemplate)4 ServiceMethodInfo (org.wso2.msf4j.ServiceMethodInfo)4 Response (io.swagger.models.Response)3 Scheme (io.swagger.models.Scheme)3