use of com.google.api.services.discovery.model.RestDescription.Auth.Oauth2 in project endpoints-java by cloudendpoints.
the class DiscoveryGenerator method writeApi.
private RestDescription writeApi(ApiKey apiKey, Iterable<ApiConfig> apiConfigs, DiscoveryContext context, SchemaRepository schemaRepo) {
// 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());
final AuthScopeRepository scopeRepo = new AuthScopeRepository();
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());
}
scopeRepo.add(config.getScopeExpression());
for (ApiMethodConfig methodConfig : config.getApiClassConfig().getMethods().values()) {
if (!methodConfig.isIgnored()) {
writeApiMethod(config, servicePath, doc, methodConfig, schemaRepo, scopeRepo);
}
}
}
Map<String, ScopesElement> scopeElements = new LinkedHashMap<>();
for (Entry<String, String> entry : scopeRepo.getDescriptionsByScope().entrySet()) {
scopeElements.put(entry.getKey(), new ScopesElement().setDescription(entry.getValue()));
}
doc.setAuth(new Auth().setOauth2(new Oauth2().setScopes(scopeElements)));
List<Schema> schemas = schemaRepo.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;
}
Aggregations