Giter Site home page Giter Site logo

timburks / api-compiler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from googleapis/api-compiler

0.0 1.0 0.0 1.02 MB

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

License: Apache License 2.0

Shell 0.20% Java 99.75% Vim Snippet 0.03% Dockerfile 0.02%

api-compiler's Introduction

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

api-compiler's People

Contributors

the8bit avatar guptasu avatar andreamlin avatar garrettjonesgoogle avatar wora avatar justinbeckwith avatar pongad avatar omaray avatar rcleveng avatar timburks avatar lookuptable avatar cushon avatar wlu2016 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.