diff --git a/spring-boot-modules/spring-boot-swagger-2/pom.xml b/spring-boot-modules/spring-boot-swagger-2/pom.xml index d2d1d10ad9..daca41426a 100644 --- a/spring-boot-modules/spring-boot-swagger-2/pom.xml +++ b/spring-boot-modules/spring-boot-swagger-2/pom.xml @@ -112,6 +112,7 @@ true ${project.basedir}/src/main/resources/static/event.yaml + ${project.basedir}/src/main/resources/static/account_api_description.yaml spring true diff --git a/spring-boot-modules/spring-boot-swagger-2/src/main/java/com/baeldung/apifirstdevelopment/controller/AccountController.java b/spring-boot-modules/spring-boot-swagger-2/src/main/java/com/baeldung/apifirstdevelopment/controller/AccountController.java new file mode 100644 index 0000000000..96242efb41 --- /dev/null +++ b/spring-boot-modules/spring-boot-swagger-2/src/main/java/com/baeldung/apifirstdevelopment/controller/AccountController.java @@ -0,0 +1,20 @@ +package com.baeldung.apifirstdevelopment.controller; + +import org.openapitools.api.AccountApi; +import org.openapitools.model.Account; +import org.openapitools.model.DepositRequest; +import org.springframework.http.ResponseEntity; + +public class AccountController implements AccountApi { + @Override + public ResponseEntity depositToAccount(DepositRequest depositRequest) { + //Execute the business logic through Service/Utils/Repository classes + return AccountApi.super.depositToAccount(depositRequest); + } + + @Override + public ResponseEntity getAccount() { + //Execute the business logic through Service/Utils/Repository classes + return AccountApi.super.getAccount(); + } +} diff --git a/spring-boot-modules/spring-boot-swagger-2/src/main/resources/account_api_description.yaml b/spring-boot-modules/spring-boot-swagger-2/src/main/resources/account_api_description.yaml new file mode 100644 index 0000000000..38349d6540 --- /dev/null +++ b/spring-boot-modules/spring-boot-swagger-2/src/main/resources/account_api_description.yaml @@ -0,0 +1,78 @@ +openapi: 3.0.3 +info: + title: Banking API Specification for account interoperations + description: |- + A simple banking API that allows two operations: + - get account balance given account number + - deposit amount to a account + version: 1.0-SNAPSHOT +servers: + - url: https://testenvironment.org/api/v1 + - url: https://prodenvironment.org/api/v1 +tags: + - name: accounts + description: Operations for bank accounts + +paths: + /account: + get: + tags: + - accounts + summary: Get account information + description: Get account information using account number + operationId: getAccount + responses: + 200: + description: Success + content: + application/json: + schema: + $ref: '#/components/schemas/Account' + 404: + description: Account not found + content: + application/json: + schema: + $ref: '#/components/schemas/AccountNotFoundError' + /account/deposit: + post: + tags: + - accounts + summary: Deposit amount to account + description: Initiates a deposit operation of a desired amount to the account specified + operationId: depositToAccount + requestBody: + description: Account number and desired amount to deposit + content: + application/json: + schema: + $ref: '#/components/schemas/DepositRequest' + required: true + responses: + 204: + description: Success + 404: + description: Account not found + content: + application/json: + schema: + $ref: '#/components/schemas/AccountNotFoundError' +components: + schemas: + Account: + type: object + properties: + balance: + type: number + AccountNotFoundError: + type: object + properties: + message: + type: string + DepositRequest: + type: object + properties: + accountNumber: + type: string + depositAmount: + type: number \ No newline at end of file