# Generate Project Using API Specs

## **Overview**

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

## **Steps**

### **Build A Microservice**

1. Prepare [Swagger ](https://swagger.io/docs/specification/2-0/what-is-swagger/)contracts that detail all the APIs that the service is going to expose for external consumption. eGov uses a customised [Swagger Codegen ](https://github.com/egovernments/Digit-Core/blob/codegen-openapi-3.0-Core-2.9-lts/accelerators/codegen/codegen-2.0-SNAPSHOT-jar-with-dependencies.jar)tool.
2. Download the jar file and make sure it is available in the classpath. Use the [Swagger Codegen tool](https://github.com/egovernments/Digit-Core/blob/codegen-openapi-3.0-Core-2.9-lts/accelerators/codegen/codegen-2.0-SNAPSHOT-jar-with-dependencies.jar) to generate client SDKs using these Swagger contracts.

{% hint style="info" %}
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](https://youtu.be/mViFmjcDOoA)
{% endhint %}

### Generate API Skeleton

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

{% hint style="info" %}

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

{% endhint %}

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 ](https://github.com/egovernments/Digit-Core/blob/master/tutorials/backend-developer-guide/btr-services/birth-registration-api-spec.yaml)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
```

2. Rename the `output` folder to birth-registration.
3. Import it in Eclipse or VS Code.
4. Update the spring-boot-starter-parent to 3.2.2 in pom.xml.
5. Perform a maven update once the spring boot version is updated.
6. 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
```

8. Add the below external dependencies to pom.xml:

{% code lineNumbers="true" %}

```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>
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.digit.org/platform/guides/developer-guide/backend-developer-guide/section-1-create-project/generate-project-using-api-specs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
