DIGIT CORE
Search…
Generate project from API specs

Generate project stub

The first step in developing a Micro-service starts with preparing Swagger contracts which details out all the APIs that the service is going to expose for external consumption.
Swagger Codegen tool and SwaggerHub can be used to generate server stubs and client SDKs using these Swagger contracts.
The following tutorial can be used for the creation of Swagger contracts - OpenAPI 3.0 Tutorial| Swagger Tutorial For Beginners | Design REST API Using Swagger Editor
Download the customized Codegen jar from here and make sure it is available in the class path.
Following is the generic command to create API skeleton for any swagger contract:
java -jar codegen-1.0-SNAPSHOT-jar-with-dependencies.jar
-l -t -u {CONTRACT_PATH } -a project_name -b /path/to/code/folder
For this guide, the following should be the sequence to generate API skeleton using codegen jar:
  1. 1.
    Go to the folder where you have downloaded the codegen jar.
  2. 2.
    Execute the following command:
java -jar codegen-1.0-SNAPSHOT-jar-with-dependencies.jar -l -t -u https://github.com/egovernments/DIGIT-Dev/blob/birth-registration-service/municipal-services/birth-registration/birth-registration-api-spec.yaml -a birth-registration -b digit
OR
Download the contract from here and save it in a file locally. Run the following command to generate the skeleton code from contract.
java -jar codegen-1.0-SNAPSHOT-jar-with-dependencies.jar -l -t -u file:///{ABSOLUTE_PATH_OF_FILE} -a voter-registration -b digit
  1. 1.
    Rename the output folder to birth-registration. Import it in Eclipse or VS Code.
  2. 2.
    Update the spring-boot-starter-parent to 2.2.6-RELEASE in pom.xml. After updating spring boot version do maven update.
  3. 3.
    Put a slash in front of server.contextPath and add this property to application.properties file which helps requests handlers to serve requests -
server.contextPath=/voter-registration
server.servlet.context-path=/voter-registration
4. Add these external dependencies to pom.xml:
1
<dependency>
2
<groupId>org.flywaydb</groupId>
3
<artifactId>flyway-core</artifactId>
4
</dependency>
5
<dependency>
6
<groupId>org.egov</groupId>
7
<artifactId>mdms-client</artifactId>
8
<version>0.0.2-SNAPSHOT</version>
9
</dependency>
10
<dependency>
11
<groupId>org.postgresql</groupId>
12
<artifactId>postgresql</artifactId>
13
<version>42.2.2.jre7</version>
14
</dependency>
All content on this page by eGov Foundation is licensed under a Creative Commons Attribution 4.0 International License.
Copy link