googleapis/api-compiler

Name: api-compiler

Owner: Google APIs

Description: A compiler that reads API descriptions into Google's API Service Configuration format.

Created: 2016-05-18 21:14:51.0

Updated: 2018-05-16 22:11:11.0

Pushed: 2018-03-21 00:07:23.0

Homepage:

Size: 1081

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

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:

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

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

Update submodules

t 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.

eates a proto descriptor from proto files using protoc.
otoc <file1.proto> <file2.proto> --include_source_info --include_imports --descriptor_set_out=out.descriptors
Creating GRPC API Configurations
-----------File: myapi.yaml-----------------

e schema of this file.
: google.api.Service

e version of the GRPC API Configurations.
ig_version: 3

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

e official title of this service.
e: Google Example Library API

e list of API interfaces exposed by the service.
:
me: google.example.library.v1.LibraryService

her aspects of the service, such as authentication.
.
Executing the Google API Compiler
RIPTOR_FILE=<PATH TO out.descriptor>
IG_FILE=<path to yaml file>
_FILE_NAME=<json output file name>
RY_FILE_NAME=<binary output file name>

n.sh \
nfigs $CONFIG_FILE \
scriptor $DESCRIPTOR_FILE \
on_out $JSON_FILE_NAME \
n_out $BINARY_FILE_NAME

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

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.

API_FILE=<OpenAPI Spec filename>
_FILE_NAME=<json output file name>
RY_FILE_NAME=<binary output file name>

n.sh \
enapi $OPENAPI_FILE \
on_out $JSON_FILE_NAME \
n_out $BINARY_FILE_NAME

This will create the service configuration in different formats:

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.

ample
do ln -s  <Path to the downloaded protoc> /usr/local/bin/protoc

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.