Search in sources :

Example 1 with ApiConfig

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();
}
Also used : EndpointsMethodHandler(com.google.api.server.spi.handlers.EndpointsMethodHandler) EndpointNode(com.google.api.server.spi.SystemService.EndpointNode) ApiProxyHandler(com.google.api.server.spi.handlers.ApiProxyHandler) ImmutableList(com.google.common.collect.ImmutableList) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) PathDispatcher(com.google.api.server.spi.dispatcher.PathDispatcher) ExplorerHandler(com.google.api.server.spi.handlers.ExplorerHandler) ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) MethodConfigMap(com.google.api.server.spi.config.model.ApiClassConfig.MethodConfigMap)

Example 2 with ApiConfig

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();
}
Also used : ApiKey(com.google.api.server.spi.config.model.ApiKey) ImmutableSet(com.google.common.collect.ImmutableSet) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) RestDescription(com.google.api.services.discovery.model.RestDescription) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with ApiConfig

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));
        }
    }
}
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 4 with ApiConfig

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.
    }
}
Also used : ApiReference(com.google.api.server.spi.config.ApiReference) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Example 5 with ApiConfig

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);
}
Also used : SimpleLevelOverridingInheritedApi(com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) SimpleLevelOverridingApi(com.google.api.server.spi.testing.SimpleLevelOverridingApi) SimpleLevelOverridingInheritedApi(com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Aggregations

ApiConfig (com.google.api.server.spi.config.model.ApiConfig)91 Test (org.junit.Test)72 Api (com.google.api.server.spi.config.Api)29 ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)26 SimpleLevelOverridingInheritedApi (com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi)20 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)18 ApiKey (com.google.api.server.spi.config.model.ApiKey)9 Swagger (io.swagger.models.Swagger)8 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)7 TypeLoader (com.google.api.server.spi.TypeLoader)5 ApiConfigLoader (com.google.api.server.spi.config.ApiConfigLoader)4 ApiConfigValidator (com.google.api.server.spi.config.validation.ApiConfigValidator)4 ServiceContext (com.google.api.server.spi.ServiceContext)3 ApiConfigAnnotationReader (com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ApiClass (com.google.api.server.spi.config.ApiClass)2 ApiFrontendLimits (com.google.api.server.spi.config.ApiFrontendLimits)2 ApiReference (com.google.api.server.spi.config.ApiReference)2 Named (com.google.api.server.spi.config.Named)2 ApiAuthConfig (com.google.api.server.spi.config.model.ApiAuthConfig)2