use of com.google.api.services.discovery.model.RestDescription in project endpoints-java by cloudendpoints.
the class LocalDiscoveryProvider method ensureDiscoveryResult.
private synchronized void ensureDiscoveryResult() {
if (discoveryDocs == null) {
DiscoveryGenerator.Result result = generator.writeDiscovery(getAllApiConfigs(), new DiscoveryContext().setApiRoot(PLACEHOLDER_ROOT), repository);
directoryList = result.directory();
ImmutableMap.Builder<ApiKey, RestDescription> builder = ImmutableMap.builder();
for (Map.Entry<ApiKey, RestDescription> entry : result.discoveryDocs().entrySet()) {
ApiKey rootedKey = entry.getKey();
builder.put(new ApiKey(rootedKey.getName(), rootedKey.getVersion(), null), entry.getValue());
}
discoveryDocs = builder.build();
}
}
use of com.google.api.services.discovery.model.RestDescription 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.services.discovery.model.RestDescription in project endpoints-java by cloudendpoints.
the class LocalDiscoveryProvider method getRestDocument.
@Override
public RestDescription getRestDocument(String root, String name, String version) throws NotFoundException {
ensureDiscoveryResult();
RestDescription doc = discoveryDocs.get(new ApiKey(name, version, null));
if (doc == null) {
throw new NotFoundException("Not Found");
}
return replaceRoot(doc, root);
}
Aggregations