Coder Social home page Coder Social logo

5l1v3r1 / gnostic Goto Github PK

View Code? Open in Web Editor NEW

This project forked from google/gnostic

0.0 1.0 0.0 5.23 MB

A compiler for APIs described by the OpenAPI Specification with plugins for code generation and other API support tasks.

License: Apache License 2.0

Shell 0.08% Go 99.57% Makefile 0.08% JavaScript 0.27%

gnostic's Introduction

Build Status

⨁ gnostic

This repository contains a Go command line tool which converts JSON and YAML OpenAPI descriptions to and from equivalent Protocol Buffer representations.

Protocol Buffers provide a language-neutral, platform-neutral, extensible mechanism for serializing structured data. gnostic's Protocol Buffer models for the OpenAPI Specification can be used to generate code that includes data structures with explicit fields for the elements of an OpenAPI description. This makes it possible for developers to work with OpenAPI descriptions in type-safe ways, which is particularly useful in strongly-typed languages like Go and Swift.

gnostic reads OpenAPI descriptions into these generated data structures, reports errors, resolves internal dependencies, and writes the results in a binary form that can be used in any language that is supported by the Protocol Buffer tools. A plugin interface simplifies integration with API tools written in a variety of different languages, and when necessary, Protocol Buffer OpenAPI descriptions can be reexported as JSON or YAML.

gnostic compilation code and OpenAPI Protocol Buffer models are automatically generated from an OpenAPI JSON Schema. Source code for the generator is in the generate-gnostic directory.

Disclaimer

This is prerelease software and work in progress. Feedback and contributions are welcome, but we currently make no guarantees of function or stability.

Requirements

gnostic can be run in any environment that supports Go and the Google Protocol Buffer Compiler.

Installation

The following instructions are for installing gnostic using Go modules, supported by Go 1.11 and later.

  1. Get this package by downloading it with git clone.

     git clone https://github.com/googleapis/gnostic
     cd gnostic
    
  2. [Optional] Build and run the gnostic compiler generator. This uses JSON schemas to generate Protocol Buffer language files that describes supported API specification formats and Go-language files of code that will read JSON or YAML API descriptions into the generated protocol buffer models.

Pre-generated versions of these files are checked into the directories named OpenAPIv2, OpenAPIv3, and discovery.

    go install ./generate-gnostic
    generate-gnostic --v2
    generate-gnostic --v3
    generate-gnostic --discovery
  1. Generate Protocol Buffer support code. This step requires a local installation of protoc, the Protocol Buffer Compiler, and the Go protoc plugin. You can get protoc here. You can install the plugin with this command:

     go get github.com/golang/protobuf/protoc-gen-go
    

Then use the following to compile the gnostic Protocol Buffer models:

    ./COMPILE-PROTOS.sh
  1. Build gnostic.

     go install .
    
  2. Run gnostic. This sample invocation creates a file in the current directory named "petstore.pb" that contains a binary Protocol Buffer description of a sample API.

     gnostic --pb-out=. examples/v2.0/json/petstore.json
    
  3. You can also compile files that you specify with a URL. Here's another way to compile the previous example. This time we're creating "petstore.text", which contains a textual representation of the Protocol Buffer description. This is mainly for use in testing and debugging.

     gnostic --text-out=petstore.text https://raw.githubusercontent.com/googleapis/gnostic/master/examples/v2.0/json/petstore.json
    
  4. For a sample application, see apps/report.

     go install ./apps/report
     report petstore.pb
    
  5. gnostic supports plugins. Some are already implemented in the plugins directory. Others, like gnostic-go-generator, are separated into their own repositories.

Copyright

Copyright 2017, Google Inc.

License

Released under the Apache 2.0 license.

gnostic's People

Contributors

andrewshan avatar bhenderson avatar bobcatfish avatar gizzon avatar glickbot avatar guptasu avatar liubog2008 avatar lorenzhw avatar mikeralphson avatar noahdietz avatar orsobruno avatar sebidude avatar skipor avatar smarterclayton avatar tfesenko avatar timburks 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.