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