Git Product home page Git Product logo

openapigenerator's Introduction

Introduction

This project still under rapid development, it working but not yet production ready.

The goal of this project is to allow developer setup microservices in shortest time, design with low code concept.

We know openapi is cool, usually we use swagger or postman for api testing, documentation and design. However, design, develop, testing and documentation is redundant work and spend us lot of time.

To create good rest api, here is the step:

  1. Design openapi v3 with swaggerhub, postman or etc openapi GUI design tools, get your spec.yaml (use v3.0 only, v3.1 not yet)
  2. Follow steps written at How to use to generate your microservices program
  3. If your .yaml design well, the server will function as expected. Then you can edit your openapiserver/openapi/handles.go to make your microservices use real data.

design api standard (spec.yaml), before development. The spec.yaml you did can turn into fully function microservices with step-by-step below. After code generated, just change the function defined in openapi/handle.go, simple and easy.

How to use

  1. clone this project to your home director
cd ~
mkdir golang
cd golang
git clone https://github.com/SIMITGROUP/openapigenerator.git
  1. build this project
cd openapigenerator
make

./openapigenerator --apifile="samples/spec.yaml"  --targetfolder="../openapiserverfolder" --projectname="openapiserver" --listen=":9000"  --lang="go"
  1. use your rest api
cd ../openapiserverfolder
make
./openapiserver
  1. Try your rest api http://localhost:9000, to access your mock rest api server. It will run return sample data defined in .yaml file.

  2. Put in your real code at below file and repeat (3.) a. openapiserverfolder/openapi/routerhandle.go b. openapiserverfolder/openapi/Model_xxx.go

Features

  1. Auto prepare model/interface according each component's schema
  2. Auto prepare path and route to handles according operationID (required), response example data according reference schema and examples
  3. Supported http traffic (GET/POST/PUT/DELETE)
  4. Build in gin http server
  5. Work with application/json response (only)
  6. Use middleware control security requirement (support basic and apikey at this moment)
  7. Supported Component type schema securityscheme

Todo

  1. add in missing basic and bearer jwt authorization
  2. prepare log system
  3. auto generate unit test
  4. missing support component type Parameters RequestBodies connect still connect to schema, require: true/false application/json only Responses Examples Callbacks Headers Links

Rules while using this project

  1. Not support ***oneOf, anyOf, allOf, not ***
  2. security scheme for apikey, oauth2,openid
  3. every property in component/schema shall define type, and example
  4. every api request require to define a. with response http status 200 and - require content type application/json - $ref link to suitable schema b. operationID is require to auto generate handle

Limitation

  1. api refer to Schema type "array" , only able to show blank array
  2. jwt is not supported yet
  3. parameters and apikey's name only support alphanumeric or "_".
  4. Response and request body only support application/json

Technical Info

  1. spec.yaml used to generate below objects
    • Allroutes
    • Allschemas
    • Allsecurityschemes
    • Allhandles
    • Allparameters
  2. Allroutes generate
    • tell web server each http request (post/get/... ) go to which handle function
    • prepare all handle function, each function sample dataisted in .yaml
    • implement security middleware if define in .yaml
  3. Allschemas use for generate
    • Model (Data type) of each response
    • Example data

Todo:

  1. unit test auto run http request using all sample provided in .yaml
  2. add configuration for use sample data/use external module

openapigenerator's People

Contributors

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