An open API service indexing awesome lists of open source software.

https://github.com/virtualansoftware/virtualan-api-first-openapi

The API first (or design first) approach focuses on the API’s design before starting to write the code. The resulting code will be the output of our design, which means that the first thing we need to do is to write the API specification (OpenApi). That is, we will design how our API will look like and how it should work before starting to write any line of the code.
https://github.com/virtualansoftware/virtualan-api-first-openapi

api-first mock-server service-virtualization spring-boot virtualan

Last synced: 9 months ago
JSON representation

The API first (or design first) approach focuses on the API’s design before starting to write the code. The resulting code will be the output of our design, which means that the first thing we need to do is to write the API specification (OpenApi). That is, we will design how our API will look like and how it should work before starting to write any line of the code.

Awesome Lists containing this project

README

          

# API First tutorial

This project contains an example of how to generate the API interfaces from an OpenApi specification using the spring generator.

# API First with Spring boot:

[![Maven Central](https://img.shields.io/maven-central/v/io.virtualan/virtualan-plugin.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.virtualan%22%20AND%20a:%22virtualan-plugin%22)

## 1. How Virtualan works?
Virtualan would be built with spring boot framework that would convert API service as Virtualized service in matter of adding couple of annotations. **_Simply as Virtualized service_** which currently supports spring-boot based Rest service(API) with **Spring-RestController** or **CXF-Jaxrs** as Virtualized service with **@VirtualService** and **@ApiVirtual** annotations.

### Add the "virtualan-plugin" dependency
• Add "virtualan-plugin" dependency in the pom.xml

io.virtualan
virtualan-plugin
${virtualan.version}

### Add @VirtualService and @ApiVirtual annotations
• @VirtualService - Annotation should be added in the class level
• @ApiVirtual - Annotation should be added in the method level that the API would you like to Virtualize.

### Service Data base setup (Optional)
• Add the entries in the **application.properties** of the database to be used to store the test data (Example: hsql with in memory DB).
virtualan.datasource.driver-class-name=
virtualan.datasource.jdbc-url=
virtualan.datasource.username=
virtualan.datasource.password=<>

## 2. Api First
The API first (or design first) approach focuses on the API’s design before starting to write the code. The resulting code will be the output of our design, which means that the first thing we need to do is to write the API specification (OpenApi). That is, we will design how our API will look like and how it should work before starting to write any line of the code.

### Open API generator
> Generate the open api spring boot rest application using the following plugin for the Open API contract

```mvn

org.openapitools
openapi-generator-maven-plugin
5.0.0



generate


${project.basedir}/src/main/resources/spec/openapi-spec.yml
spring
${project-base-package}
${project-base-package}.model
${project-base-package}.swagger
false
true
${project.basedir}/.openapi-generator-ignore
false
true

${project-base-package}.swagger



```

### Add Depandency to virtualize
> Add the following depandency for service virtulization

```mvn

io.virtualan
virtualan-plugin
2.2.1

org.hsqldb
hsqldb
2.5.0

```

### Virtualize Generated API
Add **\true\** under configOptions and this will generate code and create service virtulization or Mocking

```mvn

org.openapitools
openapi-generator-maven-plugin
5.0.0



generate


${project.basedir}/src/main/resources/spec/openapi-spec.yml
spring
${project-base-package}
${project-base-package}.model
${project-base-package}.swagger
false
true
Problem=org.zalando.problem.Problem
${project.basedir}/.openapi-generator-ignore
false
true

${project-base-package}.swagger

true




```

## **How it could be useful**
In the Agile world, We need to develop (Micro)services & Test the services in parallel. How can tester or development team can develop or test parallel to all the APIs before the real Microservices would be developed? Here Virtualized service comes into the picture.

------