Generate Project Using API Specs
Generate Project Stub
Steps: The first step in developing a microservice starts with preparing Swagger contracts that detail all the APIs that the service is going to expose for external consumption.
Use the Swagger Codegen tool and SwaggerHub to generate server stubs and client SDKs using these Swagger contracts.
The following tutorial can be used for the creation of Swagger contracts -
Following is the generic command to create an 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 the API skeleton using codegen jar:
- 1.Go to the folder where you have downloaded the codegen jar.
- 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 the contract.
java -jar codegen-1.0-SNAPSHOT-jar-with-dependencies.jar -l -t -u file:///{ABSOLUTE_PATH_OF_FILE} -a birth-registration -b digit
- 1.Rename the
output
folder to birth-registration. Import it in Eclipse or VS Code. - 2.Update the spring-boot-starter-parent to 2.2.6-RELEASE in pom.xml. After updating the spring boot version do a maven update.
- 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=/birth-registration
server.servlet.context-path=/birth-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>
Last modified 9mo ago