Search in sources :

Example 16 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(ServiceInfo service, Swagger swagger) {
    AnnAttachmentInfo swaggerInfoAnnotation = service.getAnnotationAttachmentInfo(SwaggerConstants.SWAGGER_PACKAGE_PATH, "ServiceInfo");
    Info info = new Info().version("1.0.0").title(service.getName());
    if (null != swaggerInfoAnnotation) {
        for (AnnAttributeKeyValuePair annAttributeKeyValuePair : swaggerInfoAnnotation.getAttributeKeyValuePairs()) {
            if ("version".equals(annAttributeKeyValuePair.getAttributeName())) {
                info.version(annAttributeKeyValuePair.getAttributeValue().getStringValue());
            } else if ("title".equals(annAttributeKeyValuePair.getAttributeName())) {
                info.title(annAttributeKeyValuePair.getAttributeValue().getStringValue());
            } else if ("description".equals(annAttributeKeyValuePair.getAttributeName())) {
                info.description(annAttributeKeyValuePair.getAttributeValue().getStringValue());
            } else if ("termsOfService".equals(annAttributeKeyValuePair.getAttributeName())) {
                info.termsOfService(annAttributeKeyValuePair.getAttributeValue().getStringValue());
            } else if ("contact".equals(annAttributeKeyValuePair.getAttributeName())) {
                this.createContactModel(annAttributeKeyValuePair.getAttributeValue(), info);
            } else if ("license".equals(annAttributeKeyValuePair.getAttributeName())) {
                this.createLicenseModel(annAttributeKeyValuePair.getAttributeValue(), info);
            } else if ("externalDoc".equals(annAttributeKeyValuePair.getAttributeName())) {
                this.createExternalDocModel(annAttributeKeyValuePair.getAttributeValue(), swagger);
            } else if ("tags".equals(annAttributeKeyValuePair.getAttributeName())) {
                this.createTagModel(annAttributeKeyValuePair.getAttributeValue(), swagger);
            } else if ("organization".equals(annAttributeKeyValuePair.getAttributeName())) {
                this.createOrganizationModel(annAttributeKeyValuePair.getAttributeValue(), info);
            } else if ("developers".equals(annAttributeKeyValuePair.getAttributeName())) {
                this.createDevelopersModel(annAttributeKeyValuePair.getAttributeValue(), info);
            }
        }
    }
    swagger.setInfo(info);
}
Also used : AnnAttributeKeyValuePair(org.ballerinalang.util.codegen.AnnAttributeKeyValuePair) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) Info(io.swagger.models.Info) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) ServiceInfo(org.ballerinalang.util.codegen.ServiceInfo)

Example 17 with Info

use of io.swagger.models.Info in project endpoints-java by cloudendpoints.

the class SwaggerGenerator method writeSwagger.

private Swagger writeSwagger(Iterable<ApiConfig> configs, SwaggerContext context, GenerationContext genCtx) throws ApiConfigException {
    ImmutableListMultimap<ApiKey, ? extends ApiConfig> configsByKey = FluentIterable.from(configs).index(CONFIG_TO_ROOTLESS_KEY);
    Swagger swagger = new Swagger().produces("application/json").consumes("application/json").scheme(context.scheme).host(context.hostname).basePath(context.basePath).info(new Info().title(context.hostname).version(context.docVersion));
    for (ApiKey apiKey : configsByKey.keySet()) {
        writeApi(apiKey, configsByKey.get(apiKey), swagger, genCtx);
    }
    writeQuotaDefinitions(swagger, genCtx);
    return swagger;
}
Also used : ApiKey(com.google.api.server.spi.config.model.ApiKey) Swagger(io.swagger.models.Swagger) Info(io.swagger.models.Info)

Example 18 with Info

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

the class SwaggerDefinitionProcessor method convertInfo.

private Info convertInfo(io.swagger.annotations.Info infoAnnotation) {
    if (infoAnnotation == null) {
        return null;
    }
    Info info = new Info();
    info.setTitle(infoAnnotation.title());
    info.setVersion(infoAnnotation.version());
    if (StringUtils.isNotEmpty(infoAnnotation.description())) {
        info.setDescription(infoAnnotation.description());
    }
    if (StringUtils.isNotEmpty(infoAnnotation.termsOfService())) {
        info.setTermsOfService(infoAnnotation.termsOfService());
    }
    info.setContact(convertContact(infoAnnotation.contact()));
    info.setLicense(convertLicense(infoAnnotation.license()));
    info.getVendorExtensions().putAll(BaseReaderUtils.parseExtensions(infoAnnotation.extensions()));
    return info;
}
Also used : Info(io.swagger.models.Info)

Example 19 with Info

use of io.swagger.models.Info 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 20 with Info

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

the class SecurityDefinitionTest method createModelWithSecurityRequirements.

@Test(description = "it should create a model with security requirements")
public void createModelWithSecurityRequirements() throws IOException {
    final Model personModel = ModelConverters.getInstance().read(Person.class).get("Person");
    final Model errorModel = ModelConverters.getInstance().read(Error.class).get("Error");
    final Info info = new Info().version("1.0.0").title("Swagger Petstore");
    final Contact contact = new Contact().name("Swagger API Team").email("foo@bar.baz").url("http://swagger.io");
    info.setContact(contact);
    final Swagger swagger = new Swagger().info(info).host("petstore.swagger.io").scheme(Scheme.HTTP).consumes("application/json").produces("application/json").model("Person", personModel).model("Error", errorModel);
    swagger.securityDefinition("githubAccessCode", new OAuth2Definition().accessCode("http://foo.com/accessCode", "http://foo.com/tokenUrl").scope("user:email", "Grants read access to a user’s email addresses."));
    final Operation get = new Operation().produces("application/json").summary("finds pets in the system").description("a longer description").tag("Pet Operations").operationId("get pet by id");
    get.parameter(new QueryParameter().name("tags").description("tags to filter by").required(false).property(new StringProperty()));
    get.parameter(new PathParameter().name("petId").description("pet to fetch").property(new LongProperty()));
    final Response response = new Response().description("pets returned").schema(new RefProperty().asDefault("Person"));
    final Response errorResponse = new Response().description("error response").schema(new RefProperty().asDefault("Error"));
    get.response(200, response).defaultResponse(errorResponse).security(new SecurityRequirement("internal_oauth2").scope("user:email")).security(new SecurityRequirement("api_key"));
    swagger.path("/pets", new Path().get(get));
    final String json = ResourceUtils.loadClassResource(getClass(), "ModelWithSecurityRequirements.json");
    SerializationMatchers.assertEqualsToJson(swagger, json);
}
Also used : Path(io.swagger.models.Path) QueryParameter(io.swagger.models.parameters.QueryParameter) OAuth2Definition(io.swagger.models.auth.OAuth2Definition) Error(io.swagger.models.Error) StringProperty(io.swagger.models.properties.StringProperty) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) PathParameter(io.swagger.models.parameters.PathParameter) Contact(io.swagger.models.Contact) RefProperty(io.swagger.models.properties.RefProperty) Response(io.swagger.models.Response) Swagger(io.swagger.models.Swagger) LongProperty(io.swagger.models.properties.LongProperty) Model(io.swagger.models.Model) Person(io.swagger.models.Person) SecurityRequirement(io.swagger.models.SecurityRequirement) Test(org.testng.annotations.Test)

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