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:
- Design openapi v3 with swaggerhub, postman or etc openapi GUI design tools, get your spec.yaml (use v3.0 only, v3.1 not yet)
- Follow steps written at How to use to generate your microservices program
- 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.
- clone this project to your home director
cd ~
mkdir golang
cd golang
git clone https://github.com/SIMITGROUP/openapigenerator.git
- build this project
cd openapigenerator
make
./openapigenerator --apifile="samples/spec.yaml" --targetfolder="../openapiserverfolder" --projectname="openapiserver" --listen=":9000" --lang="go"
- use your rest api
cd ../openapiserverfolder
make
./openapiserver
-
Try your rest api http://localhost:9000, to access your mock rest api server. It will run return sample data defined in .yaml file.
-
Put in your real code at below file and repeat (3.) a. openapiserverfolder/openapi/routerhandle.go b. openapiserverfolder/openapi/Model_xxx.go
- Auto prepare model/interface according each component's schema
- Auto prepare path and route to handles according operationID (required), response example data according reference schema and examples
- Supported http traffic (GET/POST/PUT/DELETE)
- Build in gin http server
- Work with application/json response (only)
- Use middleware control security requirement (support basic and apikey at this moment)
- Supported Component type schema securityscheme
- add in missing basic and bearer jwt authorization
- prepare log system
- auto generate unit test
- missing support component type Parameters RequestBodies connect still connect to schema, require: true/false application/json only Responses Examples Callbacks Headers Links
- Not support ***oneOf, anyOf, allOf, not ***
- security scheme for apikey, oauth2,openid
- every property in component/schema shall define type, and example
- 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
- api refer to Schema type "array" , only able to show blank array
- jwt is not supported yet
- parameters and apikey's name only support alphanumeric or "_".
- Response and request body only support application/json
- spec.yaml used to generate below objects
- Allroutes
- Allschemas
- Allsecurityschemes
- Allhandles
- Allparameters
- 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
- Allschemas use for generate
- Model (Data type) of each response
- Example data
Todo:
- unit test auto run http request using all sample provided in .yaml
- add configuration for use sample data/use external module