Search in sources :

Example 41 with ApiMethodConfig

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

the class JsonConfigWriter method convertApiMethods.

private void convertApiMethods(ObjectNode methodsNode, ObjectNode descriptorSchemasNode, ObjectNode descriptorMethodsNode, ApiConfig apiConfig) throws IllegalArgumentException, SecurityException, ApiConfigException {
    Map<EndpointMethod, ApiMethodConfig> methodConfigs = apiConfig.getApiClassConfig().getMethods();
    for (Map.Entry<EndpointMethod, ApiMethodConfig> methodConfig : methodConfigs.entrySet()) {
        if (!methodConfig.getValue().isIgnored()) {
            EndpointMethod endpointMethod = methodConfig.getKey();
            ApiMethodConfig config = methodConfig.getValue();
            convertApiMethod(methodsNode, descriptorSchemasNode, descriptorMethodsNode, endpointMethod, config, apiConfig);
        }
    }
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) EndpointMethod(com.google.api.server.spi.EndpointMethod) Map(java.util.Map)

Example 42 with ApiMethodConfig

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

the class DiscoveryGenerator method writeApi.

private RestDescription writeApi(ApiKey apiKey, Iterable<ApiConfig> apiConfigs, DiscoveryContext context, SchemaRepository repo) {
    // The first step is to scan all methods and try to extract a base path, aka a common prefix
    // for all methods. This prefix must end in a slash and can't contain any path parameters.
    String servicePath = computeApiServicePath(apiConfigs);
    String basePath = context.basePath + "/" + servicePath;
    RestDescription doc = REST_SKELETON.clone().setBasePath(basePath).setBaseUrl(context.getApiRoot() + "/" + servicePath).setId(apiKey.getName() + ":" + apiKey.getVersion()).setName(apiKey.getName()).setRootUrl(context.getApiRoot() + "/").setServicePath(servicePath).setVersion(apiKey.getVersion());
    for (ApiConfig config : apiConfigs) {
        // precedence here if there happens to be divergence.
        if (config.getDescription() != null) {
            doc.setDescription(config.getDescription());
        }
        if (config.getTitle() != null) {
            doc.setTitle(config.getTitle());
        }
        if (config.getDocumentationLink() != null) {
            doc.setDocumentationLink(config.getDocumentationLink());
        }
        if (config.getNamespaceConfig() != null) {
            ApiNamespaceConfig namespaceConfig = config.getNamespaceConfig();
            if (!Strings.isEmptyOrWhitespace(namespaceConfig.getOwnerName())) {
                doc.setOwnerName(namespaceConfig.getOwnerName());
            }
            if (!Strings.isEmptyOrWhitespace(namespaceConfig.getOwnerDomain())) {
                doc.setOwnerDomain(namespaceConfig.getOwnerDomain());
            }
            if (!Strings.isEmptyOrWhitespace(namespaceConfig.getPackagePath())) {
                doc.setPackagePath(namespaceConfig.getPackagePath());
            }
        }
        if (config.getCanonicalName() != null) {
            doc.setCanonicalName(config.getCanonicalName());
        }
        for (ApiMethodConfig methodConfig : config.getApiClassConfig().getMethods().values()) {
            if (!methodConfig.isIgnored()) {
                writeApiMethod(config, servicePath, doc, methodConfig, repo);
            }
        }
    }
    List<Schema> schemas = repo.getAllSchemaForApi(apiKey);
    if (!schemas.isEmpty()) {
        Map<String, JsonSchema> docSchemas = Maps.newTreeMap();
        for (Schema schema : schemas) {
            docSchemas.put(schema.name(), convertToDiscoverySchema(schema));
        }
        doc.setSchemas(docSchemas);
    }
    return doc;
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) Schema(com.google.api.server.spi.config.model.Schema) JsonSchema(com.google.api.services.discovery.model.JsonSchema) JsonSchema(com.google.api.services.discovery.model.JsonSchema) RestDescription(com.google.api.services.discovery.model.RestDescription) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) ApiNamespaceConfig(com.google.api.server.spi.config.model.ApiNamespaceConfig)

Example 43 with ApiMethodConfig

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

the class ApiConfigValidator method validateMethods.

private void validateMethods(ApiClassConfig.MethodConfigMap configMap, Map<String, ApiMethodConfig> restfulSignatures) throws ApiClassConfigInvalidException, ApiMethodConfigInvalidException, ApiParameterConfigInvalidException {
    Map<String, ApiMethodConfig> javaMethodNames = Maps.newHashMap();
    for (ApiMethodConfig methodConfig : configMap.values()) {
        if (!methodConfig.isIgnored()) {
            validateRestSignatureUnique(methodConfig, restfulSignatures);
            validateBackendMethodNameUnique(methodConfig, javaMethodNames);
            validateMethod(methodConfig);
            validateResourceAndFieldNames(methodConfig);
        }
    }
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig)

Example 44 with ApiMethodConfig

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

the class ApiAnnotationConfigTest method testSetAuthLevelIfSpecified.

@Test
public void testSetAuthLevelIfSpecified() throws Exception {
    for (AuthLevel authLevel : AuthLevel.values()) {
        if (authLevel == AuthLevel.UNSPECIFIED) {
            // next test.
            continue;
        }
        annotationConfig.setAuthLevelIfSpecified(authLevel);
        assertEquals(authLevel, config.getAuthLevel());
        ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(getResultNoParamsMethod());
        assertEquals(authLevel, methodConfig.getAuthLevel());
    }
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) AuthLevel(com.google.api.server.spi.config.AuthLevel) Test(org.junit.Test)

Example 45 with ApiMethodConfig

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

the class ApiAnnotationConfigTest method testSetAudiencesIfSpecified_empty.

@Test
public void testSetAudiencesIfSpecified_empty() throws Exception {
    String[] empty = {};
    annotationConfig.setAudiencesIfSpecified(empty);
    EndpointMethod method = getResultNoParamsMethod();
    ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(method);
    assertEquals(Collections.emptyList(), methodConfig.getAudiences());
    String[] audiences = { "bleh", "more bleh" };
    annotationConfig.setAudiencesIfSpecified(audiences);
    annotationConfig.setAudiencesIfSpecified(empty);
    assertEquals(Collections.emptyList(), config.getAudiences());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Aggregations

ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)54 Test (org.junit.Test)37 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)26 EndpointMethod (com.google.api.server.spi.EndpointMethod)16 SimpleLevelOverridingInheritedApi (com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi)10 Api (com.google.api.server.spi.config.Api)8 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)8 User (com.google.api.server.spi.auth.common.User)5 PassAuthenticator (com.google.api.server.spi.testing.PassAuthenticator)5 PassPeerAuthenticator (com.google.api.server.spi.testing.PassPeerAuthenticator)5 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)4 ApiAuthConfig (com.google.api.server.spi.config.model.ApiAuthConfig)3 ApiCacheControlConfig (com.google.api.server.spi.config.model.ApiCacheControlConfig)3 ApiFrontendLimitsConfig (com.google.api.server.spi.config.model.ApiFrontendLimitsConfig)3 Attribute (com.google.api.server.spi.request.Attribute)3 Named (com.google.api.server.spi.config.Named)2 ApiSerializationConfig (com.google.api.server.spi.config.model.ApiSerializationConfig)2 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)2 FailAuthenticator (com.google.api.server.spi.testing.FailAuthenticator)2 FailPeerAuthenticator (com.google.api.server.spi.testing.FailPeerAuthenticator)2