Search in sources :

Example 1 with ApiLimitMetricConfig

use of com.google.api.server.spi.config.model.ApiLimitMetricConfig in project endpoints-java by cloudendpoints.

the class SwaggerGenerator method writeApi.

private void writeApi(ApiKey apiKey, ImmutableList<? extends ApiConfig> apiConfigs, Swagger swagger, GenerationContext genCtx) throws ApiConfigException {
    // TODO: This may result in duplicate validations in the future if made available online
    genCtx.validator.validate(apiConfigs);
    for (ApiConfig apiConfig : apiConfigs) {
        for (ApiLimitMetricConfig limitMetric : apiConfig.getApiLimitMetrics()) {
            addNonConflictingApiLimitMetric(genCtx.limitMetrics, limitMetric);
        }
        writeApiClass(apiConfig, swagger, genCtx);
    }
    List<Schema> schemas = genCtx.schemata.getAllSchemaForApi(apiKey);
    if (!schemas.isEmpty()) {
        for (Schema schema : schemas) {
            swagger.addDefinition(schema.name(), convertToSwaggerSchema(schema));
        }
    }
}
Also used : Schema(com.google.api.server.spi.config.model.Schema) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) ApiLimitMetricConfig(com.google.api.server.spi.config.model.ApiLimitMetricConfig)

Example 2 with ApiLimitMetricConfig

use of com.google.api.server.spi.config.model.ApiLimitMetricConfig in project endpoints-java by cloudendpoints.

the class SwaggerGenerator method writeQuotaDefinitions.

private void writeQuotaDefinitions(Swagger swagger, GenerationContext genCtx) {
    if (!genCtx.limitMetrics.isEmpty()) {
        Map<String, List<Map<String, Object>>> quotaDefinitions = new HashMap<>();
        List<Map<String, Object>> limits = new ArrayList<>();
        List<Map<String, Object>> metrics = new ArrayList<>();
        for (ApiLimitMetricConfig limitMetric : genCtx.limitMetrics.values()) {
            metrics.add(ImmutableMap.<String, Object>builder().put(METRIC_NAME_KEY, limitMetric.name()).put(METRIC_VALUE_TYPE_KEY, METRIC_VALUE_TYPE).put(METRIC_KIND_KEY, METRIC_KIND).build());
            ImmutableMap.Builder<String, Object> limitBuilder = ImmutableMap.<String, Object>builder().put(LIMIT_NAME_KEY, limitMetric.name()).put(LIMIT_METRIC_KEY, limitMetric.name()).put(LIMIT_DEFAULT_LIMIT_KEY, ImmutableMap.of("STANDARD", limitMetric.limit())).put(LIMIT_UNIT_KEY, LIMIT_PER_MINUTE_PER_PROJECT);
            if (limitMetric.displayName() != null && !"".equals(limitMetric.displayName())) {
                limitBuilder.put(LIMIT_DISPLAY_NAME_KEY, limitMetric.displayName());
            }
            limits.add(limitBuilder.build());
        }
        quotaDefinitions.put(LIMITS_KEY, limits);
        swagger.setVendorExtension(MANAGEMENT_DEFINITIONS_KEY, ImmutableMap.of(METRICS_KEY, metrics, QUOTA_KEY, quotaDefinitions));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ApiLimitMetricConfig(com.google.api.server.spi.config.model.ApiLimitMetricConfig) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with ApiLimitMetricConfig

use of com.google.api.server.spi.config.model.ApiLimitMetricConfig in project endpoints-java by cloudendpoints.

the class ApiAnnotationConfig method setApiLimitMetrics.

public void setApiLimitMetrics(ApiLimitMetric[] apiLimitMetrics) {
    ImmutableList.Builder<ApiLimitMetricConfig> metricConfigs = ImmutableList.builder();
    if (apiLimitMetrics != null && apiLimitMetrics.length > 0) {
        for (ApiLimitMetric metric : apiLimitMetrics) {
            metricConfigs.add(ApiLimitMetricConfig.builder().setName(metric.name()).setDisplayName(metric.displayName()).setLimit(metric.limit()).build());
        }
    }
    config.setApiLimitMetrics(metricConfigs.build());
}
Also used : ApiLimitMetric(com.google.api.server.spi.config.ApiLimitMetric) ImmutableList(com.google.common.collect.ImmutableList) ApiLimitMetricConfig(com.google.api.server.spi.config.model.ApiLimitMetricConfig)

Aggregations

ApiLimitMetricConfig (com.google.api.server.spi.config.model.ApiLimitMetricConfig)3 ImmutableList (com.google.common.collect.ImmutableList)2 ApiLimitMetric (com.google.api.server.spi.config.ApiLimitMetric)1 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)1 Schema (com.google.api.server.spi.config.model.Schema)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1