Skip to content

Commit

Permalink
Sync From Google To GitHub.
Browse files Browse the repository at this point in the history
  • Loading branch information
guptasu committed May 25, 2016
1 parent ab48ce3 commit c0d5a37
Show file tree
Hide file tree
Showing 18 changed files with 1,399 additions and 49 deletions.
17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ NOTE: Google API Service Configuration is a rich and mature specification used
for Google production services, such as Cloud Logging, Cloud Bigtable, IAM, and
many more.

## Used by other tools.
Google API compiler is used by other tools like [googleapis/toolkit](https://github.com/googleapis/toolkit)
to read the users API definition and autogenerate client libraries.

## Compile Google API Compiler

Clone the _Google API Compiler_ repo
Expand Down Expand Up @@ -141,16 +145,3 @@ This will create the Google API service configuration:

Any of these can be used as input to an Endpoints API server.

## Work with Google Cloud Endpoints

Once you generate the service config, you can use it to configure Endpoints API
Proxy. For example, based on the service config, Endpoints API Proxy will know
how to perform authentication/logging/monitoring, if needed, for a given HTTP
request.

The service config can be fed into other tools to generate API reference,
a Google API discovery document, REST and RPC client libraries etc.

If you choose to use Google Cloud Services to provide control plane features
like logging and monitoring, you also need to submit the service config via
`gcloud` to configure the corresponding backend services.
34 changes: 0 additions & 34 deletions src/main/java/com/google/api/tools/framework/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
Expand All @@ -40,7 +39,6 @@
import com.google.protobuf.DescriptorProtos.FileDescriptorProto;
import com.google.protobuf.DescriptorProtos.FileDescriptorSet;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.Message;
import com.google.protobuf.UInt32Value;

Expand Down Expand Up @@ -81,10 +79,6 @@ public class Model extends Element implements ConfigLocationResolver {
private static final String CORP_DNS_SUFFIX = ".corp.googleapis.com";
private static final String SANDBOX_DNS_SUFFIX = ".sandbox.googleapis.com";
private static final String PRIVATE_API_DNS_SUFFIX = "-pa.googleapis.com";
private static final String DISCOVERY_API_NAME = "google.discovery.Discovery";

private static final FieldDescriptor CONFIG_VERSION_FIELD =
Preconditions.checkNotNull(Service.getDescriptor().findFieldByName("config_version"));

// An experiment which allows to turn off merging semantics and drop back to proto3.
// This is for cases the new merging causes compatibility problems.
Expand Down Expand Up @@ -314,18 +308,6 @@ public String getApiV1VersionSuffix() {
return apiV1VersionSuffix;
}

/**
* Useful to see if this model has any APIs other than the ones automatically defined by Discovery
* TODO(user) Remove this after we fix Discovery for services with no APIs
*/
public boolean hasApis() {
for (Api api : getNormalizedConfig().getApisList()) {
if (!DISCOVERY_API_NAME.equals(api.getName())) {
return true;
}
}
return false;
}
//-------------------------------------------------------------------------
// Attributes belonging to resolved stage

Expand Down Expand Up @@ -492,22 +474,6 @@ public int getConfigVersion() {
return CURRENT_CONFIG_DEFAULT_VERSION;
}

/**
* Sets config version for testing.
*/
@VisibleForTesting
public void setConfigVersionForTesting(int configVersion) {
serviceConfig =
serviceConfig
.toBuilder()
.setValue(
CONFIG_VERSION_FIELD,
null,
UInt32Value.newBuilder().setValue(configVersion).build(),
new SimpleLocation("from test"))
.build();
}

// -------------------------------------------------------------------------
// Attributes belonging to normalized stage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.api.tools.framework.tools;

import com.google.api.AnnotationsProto;
import com.google.api.AuthProto;
import com.google.api.tools.framework.model.Diag;
import com.google.api.tools.framework.model.ExtensionPool;
import com.google.api.tools.framework.model.Model;
Expand Down Expand Up @@ -75,6 +76,7 @@ public List<Diag> getDiags() {
protected ExtensionRegistry getPlatformExtensions() {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
AnnotationsProto.registerAllExtensions(registry);
AuthProto.registerAllExtensions(registry);
return registry;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.api.tools.framework.aspects.http.model.HttpAttribute.PathSegment;
import com.google.api.tools.framework.aspects.http.model.RestKind;
import com.google.api.tools.framework.aspects.http.model.RestMethod;
import com.google.api.tools.framework.model.ConfigSource;
import com.google.api.tools.framework.model.Diag;
import com.google.api.tools.framework.model.ExtensionPool;
import com.google.api.tools.framework.model.Interface;
Expand All @@ -40,6 +41,7 @@
import com.google.protobuf.DescriptorProtos.MethodDescriptorProto;
import com.google.protobuf.DescriptorProtos.ServiceDescriptorProto;
import com.google.protobuf.Empty;
import com.google.protobuf.UInt32Value;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -122,8 +124,14 @@ public void customGet() {

private void restify(MethodKind httpKind, String simpleName, String template) {
Model model = Model.create(FileDescriptorSet.getDefaultInstance());
model.setServiceConfig(Service.getDefaultInstance());
model.setConfigVersionForTesting(configVersion);
model.setServiceConfig(
ConfigSource.newBuilder(Service.getDefaultInstance())
.setValue(
Service.getDescriptor().findFieldByNumber(Service.CONFIG_VERSION_FIELD_NUMBER),
null,
UInt32Value.newBuilder().setValue(configVersion).build(),
new SimpleLocation("from test"))
.build());
HttpConfigAspect aspect = HttpConfigAspect.create(model);
ProtoFile file = ProtoFile.create(model, FileDescriptorProto.getDefaultInstance(), true,
ExtensionPool.EMPTY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.api.tools.framework.model.testing;

import com.google.api.AnnotationsProto;
import com.google.api.AuthProto;
import com.google.api.Service;
import com.google.api.tools.framework.model.ConfigSource;
import com.google.api.tools.framework.model.DiagCollector;
Expand Down Expand Up @@ -70,6 +71,7 @@ public class TestConfig {
static {
EXTENSIONS = ExtensionRegistry.newInstance();
AnnotationsProto.registerAllExtensions(EXTENSIONS);
AuthProto.registerAllExtensions(EXTENSIONS);
}

private final List<String> protoFiles;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";

package proto.test.v1;

import "google/api/annotations.proto";

message In {
string some = 1;
}

message Out {
string other = 1;
}

service TestService {
// Call v1beta2
rpc Call(In) returns (Out) {
option (google.api.http) = { get: "/v1beta2/test" };
}
}
Loading

0 comments on commit c0d5a37

Please sign in to comment.