Light-rest-4j microservices framework encourages Design Driven API building and
OpenAPI Specification is the central
piece to drive the runtime for security and validation. Also, the specification
can be used to scaffold a running server project the first time so that developers
can focus their efforts on the domain business logic implementation without
worrying about how each component are wired together.
During the service implementation phase, specification might be changed and you can
regenerate the service codebase again without overwriting your handlers and test
cases for handlers. The regeneration is also useful if you want to upgrade to the
latest version of the frameworks for your project.
To create OpenAPI specification, the best tool is swagger-editor and I have an
article in tool section to describe how to use it.
By following the instructions on how to use the editor, let’s create four API specifications
in model-config repository using OpenAPI 3.0 specification standard.
API AA is called by consumer directly and it will call API AB, API AC and API AD to get datacontact:email:[email protected]license:name:Apache2.0url:'http://www.apache.org/licenses/LICENSE-2.0.html'paths:/data:get:description:ReturnanarrayofstringscollectedfromdownstreamAPIsoperationId:listDataresponses:'200':description:Successfulresponsecontent:application/json:schema:title:ArrayOfStringstype:arrayitems:type:stringexamples:response:value:- Message1- Message2security:- aa_auth:- aa.w- aa.rcomponents:securitySchemes:aa_auth:type:oauth2flows:implicit:authorizationUrl:'http://localhost:8080/oauth2/code'scopes:aa.w:writeaccessaa.r:readaccess
As defined in the specification, API AA will return a list of stings and it requires
scope aa.r or scope aa.w to access the endpoint /data.
In the next step, we are going to use light-codegen to scaffold four projects.