Generate Project Using API Specs

Generate Project Stub

Overview

This page provides detailed steps for generating projects using the given API specifications.

Steps

Build A Microservice

  1. Prepare Swagger contracts that detail all the APIs that the service is going to expose for external consumption. eGov uses a customised Swagger Codegen tool.

  2. Download the jar file and make sure it is available in the classpath. Use the Swagger Codegen tool to generate client SDKs using these Swagger contracts.

Refer to the following tutorials to understand the creation of Swagger contracts -

OpenAPI 3.0 Tutorial| Swagger Tutorial For Beginners | Design REST API Using Swagger Editor

Generate API Skeleton

  1. Use the generic command below to create an API skeleton for any Swagger contract:

java -jar codegen-2.0-SNAPSHOT-jar-with-dependencies.jar 
-l -t -u {CONTRACT_PATH } -a project_name -b digit

The following sequence is used to generate the API skeleton using codegen jar:

  1. Navigate to the folder where you have downloaded the codegen jar.

  2. Execute the following command:

java -jar codegen-2.0-SNAPSHOT-jar-with-dependencies.jar -l -t -u https://raw.githubusercontent.com/egovernments/Digit-Core/master/tutorials/backend-developer-guide/btr-services/birth-registration-api-spec.yaml -a birth-registration -b digit

OR

Download the contract available here and save it in a file locally. Run the following command to generate the skeleton code from the contract.

java -jar codegen-2.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.

  2. Import it in Eclipse or VS Code.

  3. Update the spring-boot-starter-parent to 3.2.2 in pom.xml.

  4. Perform a maven update once the spring boot version is updated.

  5. Put a slash in front of server.contextPath and add this property to the application.properties file which helps request handlers to serve requests -

server.contextPath=/birth
server.servlet.context-path=/birth
  1. Add the below external dependencies to pom.xml:

<dependency>
     <groupId>org.flywaydb</groupId>
     <artifactId>flyway-core</artifactId>
     <version>9.22.3</version>
</dependency>
<dependency>
     <groupId>org.postgresql</groupId>
     <artifactId>postgresql</artifactId>
     <version>42.7.1</version>
</dependency>
<dependency>
     <groupId>org.egov</groupId>
     <artifactId>mdms-client</artifactId>
     <version>2.9.0-SNAPSHOT</version>
</dependency>

Last updated

All content on this page by eGov Foundation is licensed under a Creative Commons Attribution 4.0 International License.