This repo is directly linked with the How to fast generate your API Test with OpenAPI Tools and REST Assured
Please, take a look at the presentation.
The backend project was created using SpringBoot 3 and an in-memory database. You access it at https://github.com/eliasnogueira/credit-api.
You can use one of the following approaches to use the application:
- Start your Docker Desktop
- Pull the eliasnogueira/combined-credit-api^140MB^ from
Docker Hub
docker pull eliasnogueira/combined-credit-api
- Start the application container
docker run --name credit-api -p 8088:8088 -d eliasnogueira/combined-credit-api
- If you need to stop it, run
docker stop credit-api
- Open the project package session on GitHub: https://github.com/eliasnogueira/credit-api/packages/1742648
- In the Assets session, download the
.jar
file - Open the Terminal and navigate to the folder the file was saved
cd Downloads
- Start the application by running the following:
java -jar file-name.jar
- Clone the backend project running one of the following cloning methods:
- HTTPS
git clone https://github.com/eliasnogueira/credit-api.git
- SSH
git clone git@github.com:eliasnogueira/credit-api.git
- GitHub CLI
Download ZIP" https://github.com/eliasnogueira/credit-api/archive/refs/heads/main.zip
gh repo clone eliasnogueira/credit-api
- HTTPS
- Open the Terminal and navigate to the project directory
- Run the application
mvn spring-boot:run
You can also run the CreditApiApplication
class located at src/main/java
All references are from the src/main/java
folder.
com.eliasnogueira.apitest.models
have a Model/POJO class for the Simulation request and responsecom.eliasnogueira.apitest.restassured.specification
have the request and response specifications for each APIcom.eliasnogueira.apitest.client
have the Restrictions API Client implementation example using the auto-generated client from the OpenAPI toolscom.eliasnogueira.apitest.service
have the Restrictions Service implementation based on its client
All references are from the src/test/java
folder.
BaseApConfiguration
as the BaseTest class to configure the application endpoints and general config- note: the
RestAssured.basePath
is not necessary when running the architecture tests
- note: the
com.eliasnogueira.apitest.*.raw
package: you will find the "raw" REST Assured tests using it basicgiven - when - then
syntaxcom.eliasnogueira.apitest.*.spec
package: you will find the REST Assured tests using the Request and Response Specifications- *
com.eliasnogueira.apitest.*.architecture
package: you will find the REST Assured tests using an architecture based on client and services abstractions together with the generated OpenAPI client
The focus here is the explanation about the auto-generation classes based on an Open API specification, and you need to
look at the <build>
section.
To auto-generate the necessary client and classes using the Open API Generator we need to download the spec.
This is done using the wagon-maven-plugin
plugin downloading the target Open API spec all the time we generate the
classes (from the Maven compile lifecycle and on).
You now have the Open API spec downloaded in your project, so it's possible to generate its client and classes using
the openapi-generator-maven-plugin
.
Don't forget to add the targed/generated-sources
folder as the Generated Resources Root
in your IDE.