Google API Compiler

Google API Compiler.

License

License

GroupId

GroupId

com.google.api
ArtifactId

ArtifactId

api-compiler
Last Version

Last Version

0.0.8
Release Date

Release Date

Type

Type

zip
Description

Description

Google API Compiler
Google API Compiler.
Project URL

Project URL

https://github.com/googleapis/api-compiler
Source Code Management

Source Code Management

https://github.com/googleapis/api-compiler

Download api-compiler

Dependencies

compile (14)

Group / Artifact Type Version
com.google.api.grpc : grpc-google-common-protos jar 0.1.20
io.swagger : swagger-models jar 1.5.9
com.google.protobuf : protobuf-java jar 3.0.0
com.github.fge : json-schema-validator jar 2.0.0
commons-cli : commons-cli jar 1.3
cglib : cglib jar 3.1
com.google.inject : guice jar 4.0
org.yaml : snakeyaml jar 1.16
com.google.protobuf : protobuf-java-util jar 3.0.0
com.google.guava : guava jar 19.0
com.google.auto.value : auto-value jar 1.1
io.swagger : swagger-parser jar 1.0.22
org.apache.commons : commons-lang3 jar 3.4
com.google.code.findbugs : jsr305 jar 3.0.0

test (4)

Group / Artifact Type Version
junit : junit jar 4.11
org.mockito : mockito-core jar 1.10.19
com.google.truth : truth jar 0.27
joda-time : joda-time jar 2.9

Project Modules

There are no modules declared in this project.

Build Status

Google API Compiler

NOTE: API Compiler needs Java8 or higher. If you want to use Java7, please use the release tag API Compiler Java7Support.

Overview

Google API Compiler (Api Compiler) is an open source tool for processing API specifications. It currently supports OpenAPI specification, Protocol Buffers (proto), and GRPC API Configuration, and can be extended to support other formats.

Google API Compiler parses the input files into object models, processes and validates the models, and generate various outputs, such as:

  • Validation warnings and errors.
  • Normalized/validated Google API Service Configuration.
  • API discovery document.
  • API reference documentation.
  • API client libraries.

Google API Service Configuration

Google API Service Configuration is generated by Google API Compiler and is an intermediate format, not meant to be hand written. It defines the surface and behavior of an API service, including interface, types, methods, authentication, discovery, documentation, logging, monitoring and more. It is formally defined by the proto message google.api.Service and works with both REST and RPC APIs. Developers typically create proto files, defining the surface of the API service and create the GRPC API configuration using YAML files. They then use the Google API Compiler to generate the Google API Service Configuration as google.api.Service proto message.

NOTE: Google API Service Configuration is a rich and mature specification used for Google production services, such as Cloud Logging, Cloud Vision, Cloud Bigtable, IAM, and more.

Used by other tools.

Google API compiler is used by other tools like googleapis/toolkit to read the users API definition and autogenerate client libraries.

Cloning Google API Compiler

Clone the Google API Compiler repo

$ git clone https://github.com/googleapis/api-compiler

Update submodules

$ git submodule update --recursive --init

Creating Google API Service Configuration from proto files and GRPC API Configurations

Creating a proto descriptor file

Google API Compiler does not consume the proto files directly. Developers need to use protoc to generate the proto descriptor, then feed it to the Google API Compiler.

# Creates a proto descriptor from proto files using protoc.
$ protoc <file1.proto> <file2.proto> --include_source_info --include_imports --descriptor_set_out=out.descriptors

Creating GRPC API Configurations

# -------------File: myapi.yaml-----------------

# The schema of this file.
type: google.api.Service

# The version of the GRPC API Configurations.
config_version: 3

# The service name. It should be the primary DNS name for the service.
name: library-example.googleapis.com

# The official title of this service.
title: Google Example Library API

# The list of API interfaces exposed by the service.
apis:
- name: google.example.library.v1.LibraryService

# Other aspects of the service, such as authentication.
# ...

Executing the Google API Compiler

DESCRIPTOR_FILE=<PATH TO out.descriptor>
CONFIG_FILE=<path to yaml file>
JSON_FILE_NAME=<json output file name>
BINARY_FILE_NAME=<binary output file name>

./run.sh \
--configs $CONFIG_FILE \
--descriptor $DESCRIPTOR_FILE \
--json_out $JSON_FILE_NAME \
--bin_out $BINARY_FILE_NAME

This command will output the Google API Service Configuration in different formats:

  • Binary file: $BINARY_FILE_NAME
  • Json file: $JSON_FILE_NAME

Either format can be used to configure a Google Cloud Endpoints API.

Creating Google API Service Configuration from an OpenAPI Specification

Validate an OpenAPI Specification and create the corresponding service configuration.

OPENAPI_FILE=<OpenAPI Spec filename>
JSON_FILE_NAME=<json output file name>
BINARY_FILE_NAME=<binary output file name>

./run.sh \
--openapi $OPENAPI_FILE \
--json_out $JSON_FILE_NAME \
--bin_out $BINARY_FILE_NAME

This will create the service configuration in different formats:

  • Binary file: $BINARY_FILE_NAME
  • JSON file: $JSON_FILE_NAME

Either format can be used to configure a Google Cloud Endpoints API.

Compile Google API Compiler

Build source code

$ ./gradlew buildApplication

For running tests, you need to have protoc in your path. If you don't already have protoc version 3, you can download it from https://github.com/google/protobuf/releases and set a symbolic link to the protoc.

# Example
$ sudo ln -s  <Path to the downloaded protoc> /usr/local/bin/protoc
com.google.api

Google APIs

Clients for Google APIs and tools that help produce them.

Versions

Version
0.0.8
0.0.7
0.0.6
0.0.5