From 7a35847b8ba4c58fef480095982da87efe38d666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Pit=C3=A1k?= <xpitak@fi.muni.cz> Date: Wed, 17 Apr 2024 03:55:58 +0200 Subject: [PATCH] Externalize service API yaml contracts --- account-management/pom.xml | 30 +- account-query/pom.xml | 33 +- m2m-banking-api/README.md | 7 + .../account-management-api}/openapi.yaml | 574 +++++++++--------- .../account-management-api/pom.xml | 29 + .../account-query-api}/openapi.yaml | 0 m2m-banking-api/account-query-api/pom.xml | 29 + m2m-banking-api/pom.xml | 18 + .../transaction-api}/openapi.yaml | 0 m2m-banking-api/transaction-api/pom.xml | 29 + transaction-processor/pom.xml | 30 +- 11 files changed, 485 insertions(+), 294 deletions(-) create mode 100644 m2m-banking-api/README.md rename {account-management/src/main/resources => m2m-banking-api/account-management-api}/openapi.yaml (96%) create mode 100644 m2m-banking-api/account-management-api/pom.xml rename {account-query/src/main/resources => m2m-banking-api/account-query-api}/openapi.yaml (100%) create mode 100644 m2m-banking-api/account-query-api/pom.xml create mode 100644 m2m-banking-api/pom.xml rename {transaction-processor/src/main/resources => m2m-banking-api/transaction-api}/openapi.yaml (100%) create mode 100644 m2m-banking-api/transaction-api/pom.xml diff --git a/account-management/pom.xml b/account-management/pom.xml index 903f0c6..4d6a178 100644 --- a/account-management/pom.xml +++ b/account-management/pom.xml @@ -20,12 +20,20 @@ <maven.compiler.target>21</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <account-management-api.version>1.0-SNAPSHOT</account-management-api.version> + <spring.version>3.2.4</spring.version> <org.mapstruct.version>1.5.5.Final</org.mapstruct.version> <swagger-ui.version>2.3.0</swagger-ui.version> </properties> <dependencies> + <dependency> + <groupId>cz.muni.pa165.banking</groupId> + <artifactId>account-management-api</artifactId> + <version>${account-management-api.version}</version> + </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> @@ -57,6 +65,26 @@ <build> <plugins> + <!-- Copy OpenApi resources --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <version>${maven-dependency-plugin.version}</version> + <executions> + <execution> + <id>unpack</id> + <phase>validate</phase> + <goals> + <goal>unpack-dependencies</goal> + </goals> + <configuration> + <includeArtifactIds>account-management-api</includeArtifactIds> + <includes>**/openapi.yaml</includes> + <outputDirectory>${project.build.directory}/account-management-api</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> <plugin> <groupId>org.openapitools</groupId> <artifactId>openapi-generator-maven-plugin</artifactId> @@ -68,7 +96,7 @@ <goal>generate</goal> </goals> <configuration> - <inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec> + <inputSpec>${project.build.directory}/account-management-api/openapi.yaml</inputSpec> <generatorName>spring</generatorName> <apiPackage>cz.muni.pa165.banking.account.management</apiPackage> <modelPackage>cz.muni.pa165.banking.account.management.dto</modelPackage> diff --git a/account-query/pom.xml b/account-query/pom.xml index 77e9c70..e062eae 100644 --- a/account-query/pom.xml +++ b/account-query/pom.xml @@ -20,14 +20,35 @@ <maven.compiler.target>21</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <account-query-api.version>1.0-SNAPSHOT</account-query-api.version> + <spring.version>3.2.4</spring.version> <org.mapstruct.version>1.5.5.Final</org.mapstruct.version> </properties> <build> - <finalName>server_generated</finalName> - <plugins> + <!-- Copy OpenApi resources --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <version>${maven-dependency-plugin.version}</version> + <executions> + <execution> + <id>unpack</id> + <phase>validate</phase> + <goals> + <goal>unpack-dependencies</goal> + </goals> + <configuration> + <includeArtifactIds>account-query-api</includeArtifactIds> + <includes>**/openapi.yaml</includes> + <outputDirectory>${project.build.directory}/account-query-api</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> + <plugin> <groupId>org.openapitools</groupId> <artifactId>openapi-generator-maven-plugin</artifactId> @@ -39,7 +60,7 @@ <goal>generate</goal> </goals> <configuration> - <inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec> + <inputSpec>${project.build.directory}/account-query-api/openapi.yaml</inputSpec> <generatorName>spring</generatorName> <apiPackage>cz.muni.pa165.banking.account.query</apiPackage> <modelPackage>cz.muni.pa165.banking.account.query.dto</modelPackage> @@ -97,6 +118,12 @@ </build> <dependencies> + <dependency> + <groupId>cz.muni.pa165.banking</groupId> + <artifactId>account-query-api</artifactId> + <version>${account-query-api.version}</version> + </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> diff --git a/m2m-banking-api/README.md b/m2m-banking-api/README.md new file mode 100644 index 0000000..877f428 --- /dev/null +++ b/m2m-banking-api/README.md @@ -0,0 +1,7 @@ +# Banking Module 2 Module (M2M) API + +Module represents a series of libraries of module/service API YAML contracts, enabling modules to generate and use sources +in order to either implement endpoints or use sources for service calls. + +## Map of dependencies +TODO \ No newline at end of file diff --git a/account-management/src/main/resources/openapi.yaml b/m2m-banking-api/account-management-api/openapi.yaml similarity index 96% rename from account-management/src/main/resources/openapi.yaml rename to m2m-banking-api/account-management-api/openapi.yaml index 237316e..8e288f7 100644 --- a/account-management/src/main/resources/openapi.yaml +++ b/m2m-banking-api/account-management-api/openapi.yaml @@ -1,287 +1,287 @@ -openapi: 3.0.1 -info: - title: Pa165 Project Banking Application Account Query - description: | - Hand-made OpenAPI document. - version: 1.0.0 -servers: - - url: "http://localhost:8080" -tags: - - name: User - description: Service to be used by employee of the bank - - name: Account - description: Service to be used by customer of bank - -components: - schemas: - UserTypeDto: - type: string - enum: [ REGULAR, EMPLOYEE ] - - NewUserDto: - title: New bank user - description: A object representing a new bank user for creation - required: - - email - - password - - firstName - - lastName - - userType - properties: - email: - type: string - format: email - description: unused user email - password: - type: string - format: password - description: password used to log in user - firstName: - type: string - description: user's first name - lastName: - type: string - description: user's last name - userType: - $ref: '#/components/schemas/UserTypeDto' - accounts: - type: array - items: - type: string - description: id of every account owned by the user - - UserDto: - title: Bank user - description: A object representing a bank user - required: - - id - - email - - password - - firstName - - lastName - - userType - properties: - id: - type: integer - format: int64 - description: unique user id - email: - type: string - format: email - description: unused user email - password: - type: string - format: password - description: password used to log in user - firstName: - type: string - description: user's first name - lastName: - type: string - description: user's last name - userType: - $ref: '#/components/schemas/UserTypeDto' - accounts: - type: array - items: - type: string - description: id of every account owned by the user - - - AccountTypeDto: - type: string - enum: [ SPENDING, SAVING, CREDIT ] - - NewAccountDto: - title: An account - description: Bank account of registered bank user - properties: - userId: - type: integer - format: int64 - type: - $ref: '#/components/schemas/AccountTypeDto' - maxSpendingLimit: - type: integer - description: max limit of one transaction from this account - - AccountDto: - title: An account - description: Bank account of registered bank user - properties: - id: - type: integer - format: int64 - userId: - type: integer - format: int64 - type: - $ref: '#/components/schemas/AccountTypeDto' - maxSpendingLimit: - type: integer - description: max limit of one transaction from this account - - ScheduledPaymentDto: - title: Scheduled payment - description: Scheduled payment - required: - - id - - senderAccountId - - receiverAccountId - - amount - properties: - id: - type: integer - format: int64 - description: unique id of this scheduled payment - senderAccountId: - type: integer - format: int64 - description: unique id of the sender account - receiverAccountId: - type: integer - format: int64 - description: unique id of the receiver account - amount: - type: integer - description: amount of money to send - - ScheduledPaymentsDto: - title: List of Scheduled payments - description: List of Scheduled payments - properties: - scheduledPayments: - type: array - items: - $ref: '#/components/schemas/ScheduledPaymentDto' - -paths: - - /user: - get: - tags: - - User - summary: find a user with given id - operationId: getUser - parameters: - - name: userId - in: query - required: true - schema: - type: integer - format: int64 - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/UserDto' - "400": - description: NOK - - post: - tags: - - User - summary: creates a user - operationId: createUser - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/NewUserDto' - responses: - "201": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/UserDto' - "400": - description: NOK - - - /account: - get: - tags: - - Account - summary: get an account with given id - operationId: getAccount - parameters: - - name: accountNumber - in: header - required: true - schema: - type: string - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/AccountDto' - "400": - description: NOK - post: - tags: - - Account - summary: create new user account - operationId: createAccount - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/NewAccountDto' - responses: - "201": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/AccountDto' - "400": - description: NOK - - /account/scheduled: - get: - tags: - - Account - summary: get scheduled payments of an account - operationId: getScheduledPayments - parameters: - - name: accountNumber - in: header - required: true - schema: - type: string - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/ScheduledPaymentsDto' - "400": - description: NOK - post: - tags: - - Account - summary: create scheduled payment - operationId: schedulePayment - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/ScheduledPaymentDto' - responses: - "201": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/ScheduledPaymentDto' - "400": - description: NOK +openapi: 3.0.1 +info: + title: Pa165 Project Banking Application Account Query + description: | + Hand-made OpenAPI document. + version: 1.0.0 +servers: + - url: "http://localhost:8080" +tags: + - name: User + description: Service to be used by employee of the bank + - name: Account + description: Service to be used by customer of bank + +components: + schemas: + UserTypeDto: + type: string + enum: [ REGULAR, EMPLOYEE ] + + NewUserDto: + title: New bank user + description: A object representing a new bank user for creation + required: + - email + - password + - firstName + - lastName + - userType + properties: + email: + type: string + format: email + description: unused user email + password: + type: string + format: password + description: password used to log in user + firstName: + type: string + description: user's first name + lastName: + type: string + description: user's last name + userType: + $ref: '#/components/schemas/UserTypeDto' + accounts: + type: array + items: + type: string + description: id of every account owned by the user + + UserDto: + title: Bank user + description: A object representing a bank user + required: + - id + - email + - password + - firstName + - lastName + - userType + properties: + id: + type: integer + format: int64 + description: unique user id + email: + type: string + format: email + description: unused user email + password: + type: string + format: password + description: password used to log in user + firstName: + type: string + description: user's first name + lastName: + type: string + description: user's last name + userType: + $ref: '#/components/schemas/UserTypeDto' + accounts: + type: array + items: + type: string + description: id of every account owned by the user + + + AccountTypeDto: + type: string + enum: [ SPENDING, SAVING, CREDIT ] + + NewAccountDto: + title: An account + description: Bank account of registered bank user + properties: + userId: + type: integer + format: int64 + type: + $ref: '#/components/schemas/AccountTypeDto' + maxSpendingLimit: + type: integer + description: max limit of one transaction from this account + + AccountDto: + title: An account + description: Bank account of registered bank user + properties: + id: + type: integer + format: int64 + userId: + type: integer + format: int64 + type: + $ref: '#/components/schemas/AccountTypeDto' + maxSpendingLimit: + type: integer + description: max limit of one transaction from this account + + ScheduledPaymentDto: + title: Scheduled payment + description: Scheduled payment + required: + - id + - senderAccountId + - receiverAccountId + - amount + properties: + id: + type: integer + format: int64 + description: unique id of this scheduled payment + senderAccountId: + type: integer + format: int64 + description: unique id of the sender account + receiverAccountId: + type: integer + format: int64 + description: unique id of the receiver account + amount: + type: integer + description: amount of money to send + + ScheduledPaymentsDto: + title: List of Scheduled payments + description: List of Scheduled payments + properties: + scheduledPayments: + type: array + items: + $ref: '#/components/schemas/ScheduledPaymentDto' + +paths: + + /user: + get: + tags: + - User + summary: find a user with given id + operationId: getUser + parameters: + - name: userId + in: query + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/UserDto' + "400": + description: NOK + + post: + tags: + - User + summary: creates a user + operationId: createUser + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/NewUserDto' + responses: + "201": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/UserDto' + "400": + description: NOK + + + /account: + get: + tags: + - Account + summary: get an account with given id + operationId: getAccount + parameters: + - name: accountNumber + in: header + required: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/AccountDto' + "400": + description: NOK + post: + tags: + - Account + summary: create new user account + operationId: createAccount + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/NewAccountDto' + responses: + "201": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/AccountDto' + "400": + description: NOK + + /account/scheduled: + get: + tags: + - Account + summary: get scheduled payments of an account + operationId: getScheduledPayments + parameters: + - name: accountNumber + in: header + required: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ScheduledPaymentsDto' + "400": + description: NOK + post: + tags: + - Account + summary: create scheduled payment + operationId: schedulePayment + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ScheduledPaymentDto' + responses: + "201": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ScheduledPaymentDto' + "400": + description: NOK diff --git a/m2m-banking-api/account-management-api/pom.xml b/m2m-banking-api/account-management-api/pom.xml new file mode 100644 index 0000000..815d8ae --- /dev/null +++ b/m2m-banking-api/account-management-api/pom.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>cz.muni.pa165.banking.api</groupId> + <artifactId>m2m-banking-api</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <groupId>cz.muni.pa165.banking</groupId> + <artifactId>account-management-api</artifactId> + + <packaging>jar</packaging> + + <build> + <resources> + <resource> + <directory>${project.basedir}</directory> + <includes> + <include>openapi.yaml</include> + </includes> + <filtering>false</filtering> + </resource> + </resources> + </build> + +</project> \ No newline at end of file diff --git a/account-query/src/main/resources/openapi.yaml b/m2m-banking-api/account-query-api/openapi.yaml similarity index 100% rename from account-query/src/main/resources/openapi.yaml rename to m2m-banking-api/account-query-api/openapi.yaml diff --git a/m2m-banking-api/account-query-api/pom.xml b/m2m-banking-api/account-query-api/pom.xml new file mode 100644 index 0000000..303ac07 --- /dev/null +++ b/m2m-banking-api/account-query-api/pom.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>cz.muni.pa165.banking.api</groupId> + <artifactId>m2m-banking-api</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <groupId>cz.muni.pa165.banking</groupId> + <artifactId>account-query-api</artifactId> + + <packaging>jar</packaging> + + <build> + <resources> + <resource> + <directory>${project.basedir}</directory> + <includes> + <include>openapi.yaml</include> + </includes> + <filtering>false</filtering> + </resource> + </resources> + </build> + +</project> \ No newline at end of file diff --git a/m2m-banking-api/pom.xml b/m2m-banking-api/pom.xml new file mode 100644 index 0000000..aa166d8 --- /dev/null +++ b/m2m-banking-api/pom.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>cz.muni.pa165.banking.api</groupId> + <artifactId>m2m-banking-api</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <modules> + <module>transaction-api</module> + <module>account-management-api</module> + <module>account-query-api</module> + </modules> + +</project> \ No newline at end of file diff --git a/transaction-processor/src/main/resources/openapi.yaml b/m2m-banking-api/transaction-api/openapi.yaml similarity index 100% rename from transaction-processor/src/main/resources/openapi.yaml rename to m2m-banking-api/transaction-api/openapi.yaml diff --git a/m2m-banking-api/transaction-api/pom.xml b/m2m-banking-api/transaction-api/pom.xml new file mode 100644 index 0000000..96b272d --- /dev/null +++ b/m2m-banking-api/transaction-api/pom.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>cz.muni.pa165.banking.api</groupId> + <artifactId>m2m-banking-api</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <groupId>cz.muni.pa165.banking</groupId> + <artifactId>transaction-api</artifactId> + + <packaging>jar</packaging> + + <build> + <resources> + <resource> + <directory>${project.basedir}</directory> + <includes> + <include>openapi.yaml</include> + </includes> + <filtering>false</filtering> + </resource> + </resources> + </build> + +</project> \ No newline at end of file diff --git a/transaction-processor/pom.xml b/transaction-processor/pom.xml index 9cf4516..61821a9 100644 --- a/transaction-processor/pom.xml +++ b/transaction-processor/pom.xml @@ -21,9 +21,8 @@ <maven.compiler.target>21</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <!-- External project artifact versions --> <banking-infrastructure.version>1.0-SNAPSHOT</banking-infrastructure.version> - <banking-openapi.version>1.0-SNAPSHOT</banking-openapi.version> + <transaction-api.version>1.0-SNAPSHOT</transaction-api.version> <spring.version>3.2.4</spring.version> <openapi-generator.version>6.6.0</openapi-generator.version> @@ -32,6 +31,11 @@ <dependencies> + <dependency> + <groupId>cz.muni.pa165.banking</groupId> + <artifactId>transaction-api</artifactId> + <version>${transaction-api.version}</version> + </dependency> <dependency> <groupId>cz.muni.pa165.banking</groupId> <artifactId>infrastructure</artifactId> @@ -84,6 +88,26 @@ <build> <plugins> + <!-- Copy OpenApi resources --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <version>${maven-dependency-plugin.version}</version> + <executions> + <execution> + <id>unpack</id> + <phase>validate</phase> + <goals> + <goal>unpack-dependencies</goal> + </goals> + <configuration> + <includeArtifactIds>transaction-api</includeArtifactIds> + <includes>**/openapi.yaml</includes> + <outputDirectory>${project.build.directory}/transaction-api</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> <!-- OpenApi generator --> <plugin> <groupId>org.openapitools</groupId> @@ -96,7 +120,7 @@ <goal>generate</goal> </goals> <configuration> - <inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec> + <inputSpec>${project.build.directory}/transaction-api/openapi.yaml</inputSpec> <generatorName>spring</generatorName> <apiPackage>cz.muni.pa165.banking.transaction.processor</apiPackage> <modelPackage>cz.muni.pa165.banking.transaction.processor.dto</modelPackage> -- GitLab