Search in sources :

Example 6 with License

use of io.swagger.models.License in project elastest-instrumentation-manager by elastest.

the class Bootstrap method init.

@Override
public void init(ServletConfig config) throws ServletException {
    Info info = new Info().title("Swagger Server").description("RESTful API specification for the ElasTest Instrumentation Manager (EIM)").termsOfService("TBD").contact(new Contact().email("david.rojoa@atos.net")).license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html"));
    ServletContext context = config.getServletContext();
    Swagger swagger = new Swagger().info(info);
    // load properties
    String propertiesFile = "/WEB-INF/bootstrap.properties";
    Properties.load(config.getServletContext().getResourceAsStream(propertiesFile), propertiesFile);
    // create database schema
    EimDbCreator dbCreator = new EimDbCreator();
    dbCreator.createSchema();
    new SwaggerContextService().withServletConfig(config).updateSwagger(swagger);
}
Also used : SwaggerContextService(io.swagger.jaxrs.config.SwaggerContextService) Swagger(io.swagger.models.Swagger) License(io.swagger.models.License) ServletContext(javax.servlet.ServletContext) Info(io.swagger.models.Info) EimDbCreator(io.elastest.eim.database.mysql.EimDbCreator) Contact(io.swagger.models.Contact)

Example 7 with License

use of io.swagger.models.License in project camel by apache.

the class RestSwaggerSupport method initSwagger.

public void initSwagger(BeanConfig swaggerConfig, Map<String, Object> config) {
    // configure swagger options
    String s = (String) config.get("swagger.version");
    if (s != null) {
        swaggerConfig.setVersion(s);
    }
    s = (String) config.get("base.path");
    if (s != null) {
        swaggerConfig.setBasePath(s);
    }
    s = (String) config.get("host");
    if (s != null) {
        swaggerConfig.setHost(s);
    }
    s = (String) config.get("cors");
    if (s != null) {
        cors = "true".equalsIgnoreCase(s);
    }
    s = (String) config.get("schemes");
    if (s == null) {
        // deprecated due typo
        s = (String) config.get("schemas");
    }
    if (s != null) {
        String[] schemes = s.split(",");
        swaggerConfig.setSchemes(schemes);
    } else {
        // assume http by default
        swaggerConfig.setSchemes(new String[] { "http" });
    }
    String version = (String) config.get("api.version");
    String title = (String) config.get("api.title");
    String description = (String) config.get("api.description");
    String termsOfService = (String) config.get("api.termsOfService");
    String licenseName = (String) config.get("api.license.name");
    String licenseUrl = (String) config.get("api.license.url");
    String contactName = (String) config.get("api.contact.name");
    String contactUrl = (String) config.get("api.contact.url");
    String contactEmail = (String) config.get("api.contact.email");
    Info info = new Info();
    info.setVersion(version);
    info.setTitle(title);
    info.setDescription(description);
    info.setTermsOfService(termsOfService);
    if (licenseName != null || licenseUrl != null) {
        License license = new License();
        license.setName(licenseName);
        license.setUrl(licenseUrl);
        info.setLicense(license);
    }
    if (contactName != null || contactUrl != null || contactEmail != null) {
        Contact contact = new Contact();
        contact.setName(contactName);
        contact.setUrl(contactUrl);
        contact.setEmail(contactEmail);
        info.setContact(contact);
    }
    swaggerConfig.setInfo(info);
}
Also used : License(io.swagger.models.License) Info(io.swagger.models.Info) Contact(io.swagger.models.Contact)

Example 8 with License

use of io.swagger.models.License in project swagger-core by swagger-api.

the class Reader method readInfoConfig.

protected void readInfoConfig(SwaggerDefinition config) {
    Info infoConfig = config.info();
    io.swagger.models.Info info = swagger.getInfo();
    if (info == null) {
        info = new io.swagger.models.Info();
        swagger.setInfo(info);
    }
    if (!infoConfig.description().isEmpty()) {
        info.setDescription(infoConfig.description());
    }
    if (!infoConfig.termsOfService().isEmpty()) {
        info.setTermsOfService(infoConfig.termsOfService());
    }
    if (!infoConfig.title().isEmpty()) {
        info.setTitle(infoConfig.title());
    }
    if (!infoConfig.version().isEmpty()) {
        info.setVersion(infoConfig.version());
    }
    if (!infoConfig.contact().name().isEmpty()) {
        Contact contact = info.getContact();
        if (contact == null) {
            contact = new Contact();
            info.setContact(contact);
        }
        contact.setName(infoConfig.contact().name());
        if (!infoConfig.contact().email().isEmpty()) {
            contact.setEmail(infoConfig.contact().email());
        }
        if (!infoConfig.contact().url().isEmpty()) {
            contact.setUrl(infoConfig.contact().url());
        }
    }
    if (!infoConfig.license().name().isEmpty()) {
        License license = info.getLicense();
        if (license == null) {
            license = new License();
            info.setLicense(license);
        }
        license.setName(infoConfig.license().name());
        if (!infoConfig.license().url().isEmpty()) {
            license.setUrl(infoConfig.license().url());
        }
    }
    info.getVendorExtensions().putAll(BaseReaderUtils.parseExtensions(infoConfig.extensions()));
}
Also used : License(io.swagger.models.License) Info(io.swagger.annotations.Info) Contact(io.swagger.models.Contact)

Example 9 with License

use of io.swagger.models.License in project swagger-core by swagger-api.

the class Reader method readInfoConfig.

private void readInfoConfig(SwaggerDefinition config) {
    final Info infoConfig = config.info();
    io.swagger.models.Info info = swagger.getInfo();
    if (info == null) {
        info = new io.swagger.models.Info();
        swagger.setInfo(info);
    }
    if (StringUtils.isNotBlank(infoConfig.description())) {
        info.setDescription(infoConfig.description());
    }
    if (StringUtils.isNotBlank(infoConfig.termsOfService())) {
        info.setTermsOfService(infoConfig.termsOfService());
    }
    if (StringUtils.isNotBlank(infoConfig.title())) {
        info.setTitle(infoConfig.title());
    }
    if (StringUtils.isNotBlank(infoConfig.version())) {
        info.setVersion(infoConfig.version());
    }
    if (StringUtils.isNotBlank(infoConfig.contact().name())) {
        Contact contact = info.getContact();
        if (contact == null) {
            contact = new Contact();
            info.setContact(contact);
        }
        contact.setName(infoConfig.contact().name());
        if (StringUtils.isNotBlank(infoConfig.contact().email())) {
            contact.setEmail(infoConfig.contact().email());
        }
        if (StringUtils.isNotBlank(infoConfig.contact().url())) {
            contact.setUrl(infoConfig.contact().url());
        }
    }
    if (StringUtils.isNotBlank(infoConfig.license().name())) {
        License license = info.getLicense();
        if (license == null) {
            license = new License();
            info.setLicense(license);
        }
        license.setName(infoConfig.license().name());
        if (StringUtils.isNotBlank(infoConfig.license().url())) {
            license.setUrl(infoConfig.license().url());
        }
    }
    info.getVendorExtensions().putAll(BaseReaderUtils.parseExtensions(infoConfig.extensions()));
}
Also used : License(io.swagger.models.License) Info(io.swagger.annotations.Info) Contact(io.swagger.models.Contact)

Example 10 with License

use of io.swagger.models.License 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)

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