This is an API first hexagonal-architecture microservice that serves information about products.
Steps in its creation:
- First, the project was generated with Spring initialzr (https://start.spring.io/).
- Added openapi-generator in order to generate the API and DTOs from main/resources/api.yml
- Moved back from Spring boot 3.0.3 to 2.7.9 because 3.0.0 transitioned to JakartaEE 9 and openapi-generator does not fully support it yet (OpenAPITools/openapi-generator#13124)
- Created database (flyway)
- Implemented endpoint (tests, controller, service, mapper, product factory)
- Refactor and added swagger-ui
- Migrated to hexagonal architecture
- Release
API docs are also auto generated based on the OpenAPI 3 specification from annotations, available at
- http://localhost:8080/v3/api-docs (json format)
- http://localhost:8080/v3/api-docs.yaml (yaml format)
Swagger integration available at http://localhost:8080/swagger-ui.html
Tests can be run with ./mvnw clean test
Hexagonal architecture is a model of designing software applications around domain logic to isolate it from external factors.
In order to achieve this, the code is divided into three layers: application (outside), domain (inside) and infrastructure (outside).
To start the microservice, execute the following command in the root folder of the project:
./mvnw clean package && java -jar target/shop-0.1.1.jar
and you will be able to test the endpoint in the swagger-ui: http://localhost:8080/swagger-ui.html
Provided dataset is loaded via flyway and is tested in ProductIntegrationTest.java
- Decouple domain POJOs from entity POJOs in order to normalize Product class (Product should contain a price and a branch, and the price shouldn't contain a product)