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));
}
}
}
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));
}
}
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());
}
Aggregations