use of com.google.api.server.spi.config.model.ApiConfig in project endpoints-java by cloudendpoints.
the class EndpointsServlet method createDispatcher.
private PathDispatcher<EndpointsContext> createDispatcher() {
PathDispatcher.Builder<EndpointsContext> builder = PathDispatcher.builder();
List<EndpointNode> endpoints = systemService.getEndpoints();
// We're building an ImmutableList here, because it will eventually be used for JSON-RPC.
ImmutableList.Builder<EndpointsMethodHandler> handlersBuilder = ImmutableList.builder();
for (EndpointNode endpoint : endpoints) {
ApiConfig apiConfig = endpoint.getConfig();
MethodConfigMap methods = apiConfig.getApiClassConfig().getMethods();
for (Entry<EndpointMethod, ApiMethodConfig> methodEntry : methods.entrySet()) {
if (!methodEntry.getValue().isIgnored()) {
handlersBuilder.add(new EndpointsMethodHandler(initParameters, getServletContext(), methodEntry.getKey(), apiConfig, methodEntry.getValue(), systemService));
}
}
}
ImmutableList<EndpointsMethodHandler> handlers = handlersBuilder.build();
for (EndpointsMethodHandler handler : handlers) {
builder.add(handler.getRestMethod(), Strings.stripTrailingSlash(handler.getRestPath()), handler.getRestHandler());
}
ExplorerHandler explorerHandler = new ExplorerHandler();
builder.add("GET", EXPLORER_PATH, explorerHandler);
builder.add("GET", EXPLORER_PATH + "/", explorerHandler);
builder.add("GET", "static/proxy.html", new ApiProxyHandler());
return builder.build();
}
use of com.google.api.server.spi.config.model.ApiConfig in project endpoints-java by cloudendpoints.
the class DiscoveryGenerator method writeDiscovery.
public Result writeDiscovery(Iterable<ApiConfig> configs, DiscoveryContext context, SchemaRepository schemaRepository) {
ImmutableListMultimap<ApiKey, ApiConfig> configsByKey = Multimaps.index(configs, new Function<ApiConfig, ApiKey>() {
@Override
public ApiKey apply(ApiConfig config) {
return config.getApiKey();
}
});
ImmutableMap.Builder<ApiKey, RestDescription> builder = ImmutableMap.builder();
// "Default" API versions were determined automagically in legacy endpoints.
// This version only allows to remove an API from default ones by adding
// defaultVersion = AnnotationBoolean.FALSE to @Api
ImmutableSet.Builder<ApiKey> preferred = ImmutableSet.builder();
for (ApiKey apiKey : configsByKey.keySet()) {
ImmutableList<ApiConfig> apiConfigs = configsByKey.get(apiKey);
builder.put(apiKey, writeApi(apiKey, apiConfigs, context, schemaRepository));
// last config takes precedence (same as writeApi)
if (Iterables.getLast(apiConfigs).getIsDefaultVersion()) {
preferred.add(apiKey);
}
}
ImmutableMap<ApiKey, RestDescription> discoveryDocs = builder.build();
return Result.builder().setDiscoveryDocs(discoveryDocs).setDirectory(generateDirectory(discoveryDocs, preferred.build(), context)).build();
}
use of com.google.api.server.spi.config.model.ApiConfig 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.ApiConfig in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testSimpleInheritanceCycleDetection.
@Test
public void testSimpleInheritanceCycleDetection() throws Exception {
// Nest the classes, so Java doesn't get upset about declaration/reference order.
@ApiReference(Test1.Test2.class)
final class Test1 {
@ApiReference(Test1.class)
final class Test2 {
}
}
try {
ApiConfig config = createConfig(Test1.class);
annotationReader.loadEndpointClass(serviceContext, Test1.class, config);
fail();
} catch (CyclicApiInheritanceException e) {
// Expected.
}
}
use of com.google.api.server.spi.config.model.ApiConfig in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testLevelOverridingWithDefaultOverrides.
@Test
public void testLevelOverridingWithDefaultOverrides() throws Exception {
@Api(scopes = { "s0c", "s1c" }, audiences = { "a0c", "a1c" }, clientIds = { "c0c", "c1c" }, resource = "resource2", useDatastoreForAdditionalConfig = AnnotationBoolean.TRUE)
final class Test extends SimpleLevelOverridingInheritedApi {
}
ApiConfig config = createConfig(Test.class);
annotationReader.loadEndpointClass(serviceContext, Test.class, config);
annotationReader.loadEndpointMethods(serviceContext, Test.class, config.getApiClassConfig().getMethods());
// All values overridden at a lower level, so nothing should change.
verifySimpleLevelOverriding(config);
}
Aggregations