From be76a273722b0c83bb07fcb847aa403aeaf4d82f Mon Sep 17 00:00:00 2001 From: Jacopo Date: Tue, 3 Oct 2023 14:57:18 +0200 Subject: [PATCH 01/12] [PAGOPA-1215] docker --- Dockerfile | 6 ++- pom.xml | 6 +++ .../afm/utils/config/LoggingAspect.java | 46 ++++++++++++++----- .../afm/utils/config/RequestFilter.java | 1 - src/main/resources/logback-spring.xml | 36 +++++++++++++++ 5 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 src/main/resources/logback-spring.xml diff --git a/Dockerfile b/Dockerfile index f0ef9532..51ab19d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,8 @@ RUN java -Djarmode=layertools -jar application.jar extract FROM ghcr.io/pagopa/docker-base-springboot-openjdk11:v1.0.1@sha256:bbbe948e91efa0a3e66d8f308047ec255f64898e7f9250bdb63985efd3a95dbf +ADD --chown=spring:spring https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.25.1/opentelemetry-javaagent.jar . + COPY --chown=spring:spring --from=builder dependencies/ ./ COPY --chown=spring:spring --from=builder snapshot-dependencies/ ./ # https://github.com/moby/moby/issues/37965#issuecomment-426853382 @@ -20,4 +22,6 @@ RUN true COPY --chown=spring:spring --from=builder spring-boot-loader/ ./ COPY --chown=spring:spring --from=builder application/ ./ -EXPOSE 8080 \ No newline at end of file +EXPOSE 8080 + +ENTRYPOINT ["java","-javaagent:opentelemetry-javaagent.jar","--enable-preview","org.springframework.boot.loader.JarLauncher"] diff --git a/pom.xml b/pom.xml index b6e5554d..4efbc7b6 100644 --- a/pom.xml +++ b/pom.xml @@ -165,6 +165,12 @@ test + + co.elastic.logging + logback-ecs-encoder + 1.5.0 + + diff --git a/src/main/java/it/gov/pagopa/afm/utils/config/LoggingAspect.java b/src/main/java/it/gov/pagopa/afm/utils/config/LoggingAspect.java index 3675ac12..9ea8f3fb 100644 --- a/src/main/java/it/gov/pagopa/afm/utils/config/LoggingAspect.java +++ b/src/main/java/it/gov/pagopa/afm/utils/config/LoggingAspect.java @@ -3,14 +3,13 @@ import java.util.Arrays; import java.util.stream.StreamSupport; import javax.annotation.PostConstruct; +import javax.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.AfterReturning; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; -import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.annotation.*; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.EventListener; @@ -18,6 +17,7 @@ import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.Environment; import org.springframework.core.env.MutablePropertySources; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; @Aspect @@ -25,6 +25,12 @@ @Slf4j public class LoggingAspect { + public static final String START_TIME = "startTime"; + public static final String METHOD = "method"; + public static final String STATUS = "status"; + public static final String CODE = "httpCode"; + public static final String RESPONSE_TIME = "responseTime"; + @Value("${info.application.name}") private String name; @@ -34,17 +40,19 @@ public class LoggingAspect { @Value("${info.properties.environment}") private String environment; + @Autowired HttpServletRequest httRequest; + @Pointcut("@within(org.springframework.web.bind.annotation.RestController)") public void restController() { // all rest controllers } - @Pointcut("execution(* it.gov.pagopa.afm.calculator.repository..*.*(..))") + @Pointcut("@within(org.springframework.stereotype.Repository)") public void repository() { // all repository methods } - @Pointcut("execution(* it.gov.pagopa.afm.calculator.service..*.*(..))") + @Pointcut("@within(org.springframework.stereotype.Service)") public void service() { // all service methods } @@ -81,6 +89,9 @@ public void handleContextRefresh(ContextRefreshedEvent event) { @Before(value = "restController()") public void logApiInvocation(JoinPoint joinPoint) { + MDC.put(METHOD, joinPoint.getSignature().getName()); + MDC.put(START_TIME, String.valueOf(System.currentTimeMillis())); + log.info("{} {}", httRequest.getMethod(), httRequest.getRequestURI()); log.info( "Invoking API operation {} - args: {}", joinPoint.getSignature().getName(), @@ -88,15 +99,19 @@ public void logApiInvocation(JoinPoint joinPoint) { } @AfterReturning(value = "restController()", returning = "result") - public void returnApiInvocation(JoinPoint joinPoint, Object result) { + public void returnApiInvocation(JoinPoint joinPoint, ResponseEntity result) { + MDC.put(STATUS, "OK"); + MDC.put(CODE, String.valueOf(result.getStatusCodeValue())); + MDC.put(RESPONSE_TIME, getExecutionTime()); log.info( "Successful API operation {} - result: {}", joinPoint.getSignature().getName(), result); } - @AfterReturning( - value = "execution(* it.gov.pagopa.afm.utils.exception.ErrorHandler.*(..))", - returning = "result") - public void trowingApiInvocation(JoinPoint joinPoint, Object result) { + @AfterReturning(value = "execution(* *..exception.ErrorHandler.*(..))", returning = "result") + public void trowingApiInvocation(JoinPoint joinPoint, ResponseEntity result) { + MDC.put(STATUS, "KO"); + MDC.put(CODE, String.valueOf(result.getStatusCodeValue())); + MDC.put(RESPONSE_TIME, getExecutionTime()); log.info("Failed API operation {} - error: {}", joinPoint.getSignature().getName(), result); } @@ -120,4 +135,11 @@ public Object logTrace(ProceedingJoinPoint joinPoint) throws Throwable { log.debug("Return method {} - result: {}", joinPoint.getSignature().toShortString(), result); return result; } + + private static String getExecutionTime() { + long endTime = System.currentTimeMillis(); + long startTime = Long.parseLong(MDC.get(START_TIME)); + long executionTime = endTime - startTime; + return String.valueOf(executionTime); + } } diff --git a/src/main/java/it/gov/pagopa/afm/utils/config/RequestFilter.java b/src/main/java/it/gov/pagopa/afm/utils/config/RequestFilter.java index 99a719a2..cc638882 100644 --- a/src/main/java/it/gov/pagopa/afm/utils/config/RequestFilter.java +++ b/src/main/java/it/gov/pagopa/afm/utils/config/RequestFilter.java @@ -46,7 +46,6 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha // set requestId in MDC MDC.put("requestId", requestId); - log.debug("{} {}", httRequest.getMethod(), httRequest.getRequestURI()); // set requestId in the response header ((HttpServletResponse) response).setHeader(HEADER_REQUEST_ID, requestId); diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..f7beb7e2 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + %clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m %clr(%mdc){magenta}%n%wEx + + + + + + + + + + + + + + ${OTEL_SERVICE_NAME} + ${ECS_SERVICE_VERSION} + ${ENV} + + + + + + + + + From 3edcd21df0d3fd33ab410cd298d3dd87a2990d46 Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Tue, 3 Oct 2023 12:58:46 +0000 Subject: [PATCH 02/12] Bump to version 0.6.2-1-PAGOPA-1215-afm-calculator-creare-dashboard-elk [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 4 ++-- helm/values-prod.yaml | 4 ++-- helm/values-uat.yaml | 4 ++-- openapi/openapi.json | 2 +- pom.xml | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index eb9ddb0c..b1385eee 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-afm-utils description: Utility microservice for pagoPA AFM type: application -version: 0.8.0 -appVersion: 0.6.2 +version: 0.9.0 +appVersion: 0.6.2-1-PAGOPA-1215-afm-calculator-creare-dashboard-elk dependencies: - name: microservice-chart version: 1.21.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 437f559d..3780f5bb 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2" + tag: "0.6.2-1-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: @@ -84,7 +84,7 @@ microservice-chart: values: - user canaryDelivery: - create: true + create: false ingress: create: true canary: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index d72d03a6..0bc0eece 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2" + tag: "0.6.2-1-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: @@ -84,7 +84,7 @@ microservice-chart: values: - user canaryDelivery: - create: true + create: false ingress: create: true canary: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index b1c84540..7922203f 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2" + tag: "0.6.2-1-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: @@ -84,7 +84,7 @@ microservice-chart: values: - user canaryDelivery: - create: true + create: false ingress: create: true canary: diff --git a/openapi/openapi.json b/openapi/openapi.json index e4c23ac8..de8c2267 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -4,7 +4,7 @@ "description": "Utility microservice for pagoPA AFM", "termsOfService": "https://www.pagopa.gov.it/", "title": "afm-utils", - "version": "0.6.2" + "version": "0.6.2-1-PAGOPA-1215-afm-calculator-creare-dashboard-elk" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 4efbc7b6..49d52f70 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ it.gov.pagopa afm-utils - 0.6.2 + 0.6.2-1-PAGOPA-1215-afm-calculator-creare-dashboard-elk afm-utils Utility microservice for pagoPA AFM jar From 27a478bd2b92ce7fb9d05a64b2add807bfec6c3f Mon Sep 17 00:00:00 2001 From: Jacopo Date: Tue, 3 Oct 2023 16:38:25 +0200 Subject: [PATCH 03/12] [PAGOPA-1215] fix GHA --- .github/workflows/deploy_with_github_runner.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy_with_github_runner.yml b/.github/workflows/deploy_with_github_runner.yml index 21b2edf4..c802f4da 100644 --- a/.github/workflows/deploy_with_github_runner.yml +++ b/.github/workflows/deploy_with_github_runner.yml @@ -42,7 +42,6 @@ jobs: container_app_environment_name: ${{ vars.CONTAINER_APP_ENVIRONMENT_NAME }} resource_group_name: ${{ vars.CONTAINER_APP_ENVIRONMENT_RESOURCE_GROUP_NAME }} # RG of the runner pat_token: ${{ secrets.BOT_TOKEN_GITHUB }} - self_hosted_runner_image_tag: "v1.4.1" deploy: needs: [ create_runner ] From 917ab824403e37e94076e387ef716be3ddcd4aec Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Tue, 3 Oct 2023 14:40:50 +0000 Subject: [PATCH 04/12] Bump to version 0.6.2-2-PAGOPA-1215-afm-calculator-creare-dashboard-elk [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi.json | 2 +- pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index b1385eee..f195f977 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-afm-utils description: Utility microservice for pagoPA AFM type: application -version: 0.9.0 -appVersion: 0.6.2-1-PAGOPA-1215-afm-calculator-creare-dashboard-elk +version: 0.10.0 +appVersion: 0.6.2-2-PAGOPA-1215-afm-calculator-creare-dashboard-elk dependencies: - name: microservice-chart version: 1.21.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 3780f5bb..504f64e1 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2-1-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + tag: "0.6.2-2-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 0bc0eece..4b14116b 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2-1-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + tag: "0.6.2-2-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 7922203f..69127f66 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2-1-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + tag: "0.6.2-2-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi.json b/openapi/openapi.json index de8c2267..17e3ee5a 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -4,7 +4,7 @@ "description": "Utility microservice for pagoPA AFM", "termsOfService": "https://www.pagopa.gov.it/", "title": "afm-utils", - "version": "0.6.2-1-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + "version": "0.6.2-2-PAGOPA-1215-afm-calculator-creare-dashboard-elk" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 49d52f70..1cad5dc4 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ it.gov.pagopa afm-utils - 0.6.2-1-PAGOPA-1215-afm-calculator-creare-dashboard-elk + 0.6.2-2-PAGOPA-1215-afm-calculator-creare-dashboard-elk afm-utils Utility microservice for pagoPA AFM jar From 8c5f2e981024363b74facca5733a6fc960015cf0 Mon Sep 17 00:00:00 2001 From: Jacopo Date: Tue, 3 Oct 2023 16:48:50 +0200 Subject: [PATCH 05/12] [PAGOPA-1215] otel --- helm/values-dev.yaml | 6 ++++++ helm/values-prod.yaml | 6 ++++++ helm/values-uat.yaml | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 3780f5bb..bcb625e0 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -65,10 +65,16 @@ microservice-chart: COSMOS_DATABASE: 'db' COSMOS_QUERY_METRICS: 'false' CDI_CONTAINER_NAME: 'cdis' + OTEL_SERVICE_NAME: "pagopa-afm-calculator" + OTEL_RESOURCE_ATTRIBUTES: "deployment.environment=dev" + OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector.elastic-system.svc:4317" + OTEL_LOGS_EXPORTER: none + OTEL_TRACES_SAMPLER: "always_on" envSecret: APPLICATIONINSIGHTS_CONNECTION_STRING: ai-d-connection-string AFM_MARKETPLACE_SUBSCRIPTION_KEY: afm-marketplace-subscription-key COSMOS_KEY: afm-marketplace-d-cosmos-pkey + OTEL_EXPORTER_OTLP_HEADERS: elastic-apm-secret-token keyvault: name: "pagopa-d-afm-kv" tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d" diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 0bc0eece..0c602442 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -65,10 +65,16 @@ microservice-chart: COSMOS_DATABASE: 'db' COSMOS_QUERY_METRICS: 'false' CDI_CONTAINER_NAME: 'cdis' + OTEL_SERVICE_NAME: "pagopa-afm-calculator" + OTEL_RESOURCE_ATTRIBUTES: "deployment.environment=prod" + OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector.elastic-system.svc:4317" + OTEL_LOGS_EXPORTER: none + OTEL_TRACES_SAMPLER: "always_on" envSecret: APPLICATIONINSIGHTS_CONNECTION_STRING: ai-p-connection-string AFM_MARKETPLACE_SUBSCRIPTION_KEY: afm-marketplace-subscription-key COSMOS_KEY: afm-marketplace-p-cosmos-pkey + OTEL_EXPORTER_OTLP_HEADERS: elastic-apm-secret-token keyvault: name: "pagopa-p-afm-kv" tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d" diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 7922203f..4db34bb8 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -65,10 +65,16 @@ microservice-chart: COSMOS_DATABASE: 'db' COSMOS_QUERY_METRICS: 'false' CDI_CONTAINER_NAME: 'cdis' + OTEL_SERVICE_NAME: "pagopa-afm-calculator" + OTEL_RESOURCE_ATTRIBUTES: "deployment.environment=uat" + OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector.elastic-system.svc:4317" + OTEL_LOGS_EXPORTER: none + OTEL_TRACES_SAMPLER: "always_on" envSecret: APPLICATIONINSIGHTS_CONNECTION_STRING: ai-u-connection-string AFM_MARKETPLACE_SUBSCRIPTION_KEY: afm-marketplace-subscription-key COSMOS_KEY: afm-marketplace-u-cosmos-pkey + OTEL_EXPORTER_OTLP_HEADERS: elastic-apm-secret-token keyvault: name: "pagopa-u-afm-kv" tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d" From 5c4edf4e35d5fbed6a6d967cb9d8a2a467be7747 Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Tue, 3 Oct 2023 14:50:15 +0000 Subject: [PATCH 06/12] Bump to version 0.6.2-3-PAGOPA-1215-afm-calculator-creare-dashboard-elk [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi.json | 2 +- pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index f195f977..5851c5f1 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-afm-utils description: Utility microservice for pagoPA AFM type: application -version: 0.10.0 -appVersion: 0.6.2-2-PAGOPA-1215-afm-calculator-creare-dashboard-elk +version: 0.11.0 +appVersion: 0.6.2-3-PAGOPA-1215-afm-calculator-creare-dashboard-elk dependencies: - name: microservice-chart version: 1.21.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 678f9706..57eb9ff4 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2-2-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + tag: "0.6.2-3-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index dca4638f..56b53c74 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2-2-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + tag: "0.6.2-3-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 80673a8a..ce665a40 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2-2-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + tag: "0.6.2-3-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi.json b/openapi/openapi.json index 17e3ee5a..dce811b9 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -4,7 +4,7 @@ "description": "Utility microservice for pagoPA AFM", "termsOfService": "https://www.pagopa.gov.it/", "title": "afm-utils", - "version": "0.6.2-2-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + "version": "0.6.2-3-PAGOPA-1215-afm-calculator-creare-dashboard-elk" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 1cad5dc4..6c0bae3a 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ it.gov.pagopa afm-utils - 0.6.2-2-PAGOPA-1215-afm-calculator-creare-dashboard-elk + 0.6.2-3-PAGOPA-1215-afm-calculator-creare-dashboard-elk afm-utils Utility microservice for pagoPA AFM jar From 81f26eb0dcc93e7f6b9233021a5fa6aba346b4ee Mon Sep 17 00:00:00 2001 From: Jacopo Date: Tue, 3 Oct 2023 17:03:06 +0200 Subject: [PATCH 07/12] [PAGOPA-1215] service name --- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 678f9706..8ecc6a88 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -65,7 +65,7 @@ microservice-chart: COSMOS_DATABASE: 'db' COSMOS_QUERY_METRICS: 'false' CDI_CONTAINER_NAME: 'cdis' - OTEL_SERVICE_NAME: "pagopa-afm-calculator" + OTEL_SERVICE_NAME: "pagopa-afm-utils" OTEL_RESOURCE_ATTRIBUTES: "deployment.environment=dev" OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector.elastic-system.svc:4317" OTEL_LOGS_EXPORTER: none diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index dca4638f..463d13f7 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -65,7 +65,7 @@ microservice-chart: COSMOS_DATABASE: 'db' COSMOS_QUERY_METRICS: 'false' CDI_CONTAINER_NAME: 'cdis' - OTEL_SERVICE_NAME: "pagopa-afm-calculator" + OTEL_SERVICE_NAME: "pagopa-afm-utils" OTEL_RESOURCE_ATTRIBUTES: "deployment.environment=prod" OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector.elastic-system.svc:4317" OTEL_LOGS_EXPORTER: none diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 80673a8a..4786c1cd 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -65,7 +65,7 @@ microservice-chart: COSMOS_DATABASE: 'db' COSMOS_QUERY_METRICS: 'false' CDI_CONTAINER_NAME: 'cdis' - OTEL_SERVICE_NAME: "pagopa-afm-calculator" + OTEL_SERVICE_NAME: "pagopa-afm-utils" OTEL_RESOURCE_ATTRIBUTES: "deployment.environment=uat" OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector.elastic-system.svc:4317" OTEL_LOGS_EXPORTER: none From 20d48f32cb3019a116e7ad1a4df2cda6581d84a4 Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Tue, 3 Oct 2023 15:04:36 +0000 Subject: [PATCH 08/12] Bump to version 0.6.2-4-PAGOPA-1215-afm-calculator-creare-dashboard-elk [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi.json | 2 +- pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 5851c5f1..898a5fe5 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-afm-utils description: Utility microservice for pagoPA AFM type: application -version: 0.11.0 -appVersion: 0.6.2-3-PAGOPA-1215-afm-calculator-creare-dashboard-elk +version: 0.12.0 +appVersion: 0.6.2-4-PAGOPA-1215-afm-calculator-creare-dashboard-elk dependencies: - name: microservice-chart version: 1.21.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 57eb9ff4..b5ecf29b 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2-3-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + tag: "0.6.2-4-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 56b53c74..7b8f026f 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2-3-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + tag: "0.6.2-4-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index ce665a40..13ddf3be 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2-3-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + tag: "0.6.2-4-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi.json b/openapi/openapi.json index dce811b9..a2365cce 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -4,7 +4,7 @@ "description": "Utility microservice for pagoPA AFM", "termsOfService": "https://www.pagopa.gov.it/", "title": "afm-utils", - "version": "0.6.2-3-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + "version": "0.6.2-4-PAGOPA-1215-afm-calculator-creare-dashboard-elk" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 6c0bae3a..061210a6 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ it.gov.pagopa afm-utils - 0.6.2-3-PAGOPA-1215-afm-calculator-creare-dashboard-elk + 0.6.2-4-PAGOPA-1215-afm-calculator-creare-dashboard-elk afm-utils Utility microservice for pagoPA AFM jar From 23d8fa994d223da5378876089d545566abb47c28 Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Tue, 3 Oct 2023 16:22:50 +0000 Subject: [PATCH 09/12] Bump to version 0.6.2-5-PAGOPA-1215-afm-calculator-creare-dashboard-elk [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi.json | 2 +- pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 898a5fe5..69c43414 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-afm-utils description: Utility microservice for pagoPA AFM type: application -version: 0.12.0 -appVersion: 0.6.2-4-PAGOPA-1215-afm-calculator-creare-dashboard-elk +version: 0.13.0 +appVersion: 0.6.2-5-PAGOPA-1215-afm-calculator-creare-dashboard-elk dependencies: - name: microservice-chart version: 1.21.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index b343b951..9a66d18a 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2-4-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + tag: "0.6.2-5-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 6d971968..f069a24a 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2-4-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + tag: "0.6.2-5-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 2b99e515..b963cc9e 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-utils - tag: "0.6.2-4-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + tag: "0.6.2-5-PAGOPA-1215-afm-calculator-creare-dashboard-elk" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi.json b/openapi/openapi.json index a2365cce..b1b34722 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -4,7 +4,7 @@ "description": "Utility microservice for pagoPA AFM", "termsOfService": "https://www.pagopa.gov.it/", "title": "afm-utils", - "version": "0.6.2-4-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + "version": "0.6.2-5-PAGOPA-1215-afm-calculator-creare-dashboard-elk" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 061210a6..a408ebfd 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ it.gov.pagopa afm-utils - 0.6.2-4-PAGOPA-1215-afm-calculator-creare-dashboard-elk + 0.6.2-5-PAGOPA-1215-afm-calculator-creare-dashboard-elk afm-utils Utility microservice for pagoPA AFM jar From 42a106782d619e98339e2197c59b7855400f9974 Mon Sep 17 00:00:00 2001 From: Jacopo Date: Tue, 10 Oct 2023 10:03:37 +0200 Subject: [PATCH 10/12] [PAGOPA-1215] logging aspect --- .../afm/utils/config/LoggingAspect.java | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/main/java/it/gov/pagopa/afm/utils/config/LoggingAspect.java b/src/main/java/it/gov/pagopa/afm/utils/config/LoggingAspect.java index 9ea8f3fb..8948ecff 100644 --- a/src/main/java/it/gov/pagopa/afm/utils/config/LoggingAspect.java +++ b/src/main/java/it/gov/pagopa/afm/utils/config/LoggingAspect.java @@ -4,10 +4,14 @@ import java.util.stream.StreamSupport; import javax.annotation.PostConstruct; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.*; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -31,8 +35,8 @@ public class LoggingAspect { public static final String CODE = "httpCode"; public static final String RESPONSE_TIME = "responseTime"; - @Value("${info.application.name}") - private String name; + @Value("${info.application.artifactId}") + private String artifactId; @Value("${info.application.version}") private String version; @@ -42,6 +46,8 @@ public class LoggingAspect { @Autowired HttpServletRequest httRequest; + @Autowired HttpServletResponse httpResponse; + @Pointcut("@within(org.springframework.web.bind.annotation.RestController)") public void restController() { // all rest controllers @@ -60,7 +66,7 @@ public void service() { /** Log essential info of application during the startup. */ @PostConstruct public void logStartup() { - log.info("-> Starting {} version {} - environment {}", name, version, environment); + log.info("-> Starting {} version {} - environment {}", artifactId, version, environment); } /** @@ -83,12 +89,14 @@ public void handleContextRefresh(ContextRefreshedEvent event) { !(prop.toLowerCase().contains("credentials") || prop.toLowerCase().contains("password") || prop.toLowerCase().contains("pass") - || prop.toLowerCase().contains("pwd"))) + || prop.toLowerCase().contains("pwd") + || prop.toLowerCase().contains("key") + || prop.toLowerCase().contains("secret"))) .forEach(prop -> log.debug("{}: {}", prop, env.getProperty(prop))); } - @Before(value = "restController()") - public void logApiInvocation(JoinPoint joinPoint) { + @Around(value = "restController()") + public Object logApiInvocation(ProceedingJoinPoint joinPoint) throws Throwable { MDC.put(METHOD, joinPoint.getSignature().getName()); MDC.put(START_TIME, String.valueOf(System.currentTimeMillis())); log.info("{} {}", httRequest.getMethod(), httRequest.getRequestURI()); @@ -96,15 +104,19 @@ public void logApiInvocation(JoinPoint joinPoint) { "Invoking API operation {} - args: {}", joinPoint.getSignature().getName(), joinPoint.getArgs()); - } - @AfterReturning(value = "restController()", returning = "result") - public void returnApiInvocation(JoinPoint joinPoint, ResponseEntity result) { + Object result = joinPoint.proceed(); + MDC.put(STATUS, "OK"); - MDC.put(CODE, String.valueOf(result.getStatusCodeValue())); + MDC.put(CODE, String.valueOf(httpResponse.getStatus())); MDC.put(RESPONSE_TIME, getExecutionTime()); log.info( "Successful API operation {} - result: {}", joinPoint.getSignature().getName(), result); + MDC.remove(STATUS); + MDC.remove(CODE); + MDC.remove(RESPONSE_TIME); + MDC.remove(START_TIME); + return result; } @AfterReturning(value = "execution(* *..exception.ErrorHandler.*(..))", returning = "result") @@ -112,19 +124,11 @@ public void trowingApiInvocation(JoinPoint joinPoint, ResponseEntity result) MDC.put(STATUS, "KO"); MDC.put(CODE, String.valueOf(result.getStatusCodeValue())); MDC.put(RESPONSE_TIME, getExecutionTime()); - log.info("Failed API operation {} - error: {}", joinPoint.getSignature().getName(), result); - } - - @Around(value = "repository() || service()") - public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { - long startTime = System.currentTimeMillis(); - Object result = joinPoint.proceed(); - long endTime = System.currentTimeMillis(); - log.trace( - "Time taken for Execution of {} is: {}ms", - joinPoint.getSignature().toShortString(), - (endTime - startTime)); - return result; + log.info("Failed API operation {} - error: {}", MDC.get(METHOD), result); + MDC.remove(STATUS); + MDC.remove(CODE); + MDC.remove(RESPONSE_TIME); + MDC.remove(START_TIME); } @Around(value = "repository() || service()") From 70eef3915b716b49329fa7a161153c883dec9bf9 Mon Sep 17 00:00:00 2001 From: Jacopo Date: Tue, 10 Oct 2023 10:03:59 +0200 Subject: [PATCH 11/12] [PAGOPA-1215] formatter removed --- .pre-commit-config.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 580c3840..0d2e1f8e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,8 +9,3 @@ repos: - id: ggshield language_version: python3 stages: [ commit ] - - - repo: https://github.com/maltzj/google-style-precommit-hook - rev: b7e9e7fcba4a5aea463e72fe9964c14877bd8130 - hooks: - - id: google-style-java From 953886e2a48d72f2261abe34b394989fe7f298a8 Mon Sep 17 00:00:00 2001 From: Jacopo Date: Tue, 10 Oct 2023 10:20:46 +0200 Subject: [PATCH 12/12] [PAGOPA-1215] fix junit --- openapi/openapi.json | 961 +++++++++--------- pom.xml | 472 ++++----- .../afm/utils/config/OpenApiConfig.java | 2 +- .../afm/utils/controller/BaseController.java | 2 +- .../resources/application-local.properties | 2 +- src/main/resources/application.properties | 2 +- .../afm/utils/OpenApiGenerationTest.java | 50 + src/test/resources/application.properties | 2 +- 8 files changed, 757 insertions(+), 736 deletions(-) create mode 100644 src/test/java/it/gov/pagopa/afm/utils/OpenApiGenerationTest.java diff --git a/openapi/openapi.json b/openapi/openapi.json index b1b34722..604f3d83 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -1,681 +1,646 @@ { - "openapi": "3.0.1", - "info": { - "description": "Utility microservice for pagoPA AFM", - "termsOfService": "https://www.pagopa.gov.it/", - "title": "afm-utils", - "version": "0.6.2-5-PAGOPA-1215-afm-calculator-creare-dashboard-elk" + "openapi" : "3.0.1", + "info" : { + "title" : "afm-utils", + "description" : "Utility microservice for pagoPA AFM", + "termsOfService" : "https://www.pagopa.gov.it/", + "version" : "0.6.2-5-PAGOPA-1215-afm-calculator-creare-dashboard-elk" }, - "servers": [ - { - "description": "Generated server url", - "url": "http://localhost:8586" - } - ], - "paths": { - "/cdis/sync": { - "delete": { - "operationId": "syncCDIDeletion", - "responses": { - "200": { - "description": "Obtained bundle list.", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "servers" : [ { + "url" : "http://localhost", + "description" : "Generated server url" + } ], + "paths" : { + "/cdis/sync" : { + "get" : { + "tags" : [ "Import CDI rest API" ], + "summary" : "API to retry the import of the CDIs and convert to bundles.", + "operationId" : "syncCDI_1", + "responses" : { + "200" : { + "description" : "Obtained bundle list.", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" + } + } + }, + "content" : { + "application/json" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/BundleResponse" + } } } } }, - "401": { - "description": "Unauthorized", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "401" : { + "description" : "Unauthorized", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "403": { - "description": "Forbidden", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "403" : { + "description" : "Forbidden", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "429": { - "description": "Too many requests", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "429" : { + "description" : "Too many requests", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "500": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemJson" + "500" : { + "description" : "Service unavailable.", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } }, - "description": "Service unavailable.", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ProblemJson" } } } } }, - "security": [ - { - "ApiKey": [] - } - ], - "summary": "API to trigger the bulk deletion of the CDIs and its related bundles.", - "tags": [ - "Delete CDI rest API" - ] + "security" : [ { + "ApiKey" : [ ] + } ] }, - "get": { - "operationId": "syncCDI_1", - "responses": { - "200": { - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/BundleResponse" - } + "post" : { + "tags" : [ "Import CDI rest API" ], + "summary" : "API to trigger the import of the CDIs and convert to bundles.", + "operationId" : "syncCDI", + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/CDI" + } + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "Obtained bundle list.", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } }, - "description": "Obtained bundle list.", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "content" : { + "application/json" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/BundleResponse" + } } } } }, - "401": { - "description": "Unauthorized", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "401" : { + "description" : "Unauthorized", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "403": { - "description": "Forbidden", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "403" : { + "description" : "Forbidden", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "429": { - "description": "Too many requests", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "429" : { + "description" : "Too many requests", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "500": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemJson" + "500" : { + "description" : "Service unavailable.", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } }, - "description": "Service unavailable.", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ProblemJson" } } } } }, - "security": [ - { - "ApiKey": [] - } - ], - "summary": "API to retry the import of the CDIs and convert to bundles.", - "tags": [ - "Import CDI rest API" - ] + "security" : [ { + "ApiKey" : [ ] + } ] }, - "parameters": [ - { - "description": "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", - "in": "header", - "name": "X-Request-Id", - "schema": { - "type": "string" - } - } - ], - "post": { - "operationId": "syncCDI", - "requestBody": { - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/CDI" - } - } - } - }, - "required": true - }, - "responses": { - "200": { - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/BundleResponse" - } - } - } - }, - "description": "Obtained bundle list.", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "delete" : { + "tags" : [ "Delete CDI rest API" ], + "summary" : "API to trigger the bulk deletion of the CDIs and its related bundles.", + "operationId" : "syncCDIDeletion", + "responses" : { + "200" : { + "description" : "Obtained bundle list.", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "401": { - "description": "Unauthorized", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "401" : { + "description" : "Unauthorized", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "403": { - "description": "Forbidden", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "403" : { + "description" : "Forbidden", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "429": { - "description": "Too many requests", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "429" : { + "description" : "Too many requests", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "500": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemJson" + "500" : { + "description" : "Service unavailable.", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } }, - "description": "Service unavailable.", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ProblemJson" } } } } }, - "security": [ - { - "ApiKey": [] - } - ], - "summary": "API to trigger the import of the CDIs and convert to bundles.", - "tags": [ - "Import CDI rest API" - ] - } + "security" : [ { + "ApiKey" : [ ] + } ] + }, + "parameters" : [ { + "name" : "X-Request-Id", + "in" : "header", + "description" : "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", + "schema" : { + "type" : "string" + } + } ] }, - "/info": { - "get": { - "description": "Return OK if application is started", - "operationId": "healthCheck", - "responses": { - "200": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AppInfo" + "/info" : { + "get" : { + "tags" : [ "Home" ], + "summary" : "health check", + "description" : "Return OK if application is started", + "operationId" : "healthCheck", + "responses" : { + "200" : { + "description" : "OK", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } }, - "description": "OK", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/AppInfo" } } } }, - "400": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemJson" + "400" : { + "description" : "Bad Request", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } }, - "description": "Bad Request", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ProblemJson" } } } }, - "401": { - "description": "Unauthorized", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "401" : { + "description" : "Unauthorized", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "403": { - "description": "Forbidden", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "403" : { + "description" : "Forbidden", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "429": { - "description": "Too many requests", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "429" : { + "description" : "Too many requests", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "500": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemJson" + "500" : { + "description" : "Service unavailable", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } }, - "description": "Service unavailable", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ProblemJson" } } } } }, - "security": [ - { - "ApiKey": [] - } - ], - "summary": "health check", - "tags": [ - "Home" - ] + "security" : [ { + "ApiKey" : [ ] + } ] }, - "parameters": [ - { - "description": "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", - "in": "header", - "name": "X-Request-Id", - "schema": { - "type": "string" - } + "parameters" : [ { + "name" : "X-Request-Id", + "in" : "header", + "description" : "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", + "schema" : { + "type" : "string" } - ] + } ] }, - "/psps/{pspCode}/cdis/{idCdi}": { - "delete": { - "operationId": "syncBundlesDeletionByIdCDI", - "parameters": [ - { - "description": "CDI identifier", - "in": "path", - "name": "idCdi", - "required": true, - "schema": { - "maxLength": 50, - "minLength": 0, - "type": "string" - } - }, - { - "description": "PSP code", - "in": "path", - "name": "pspCode", - "required": true, - "schema": { - "pattern": "[A-Z0-9_]{6,14}", - "type": "string" - } + "/psps/{pspCode}/cdis/{idCdi}" : { + "delete" : { + "tags" : [ "Delete Bundles by id CDI rest API" ], + "summary" : "API to trigger the deletion of the bundles by a CDI id.", + "operationId" : "syncBundlesDeletionByIdCDI", + "parameters" : [ { + "name" : "idCdi", + "in" : "path", + "description" : "CDI identifier", + "required" : true, + "schema" : { + "maxLength" : 50, + "minLength" : 0, + "type" : "string" + } + }, { + "name" : "pspCode", + "in" : "path", + "description" : "PSP code", + "required" : true, + "schema" : { + "pattern" : "[A-Z0-9_]{6,14}", + "type" : "string" } - ], - "responses": { - "200": { - "description": "OK", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "401": { - "description": "Unauthorized", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "401" : { + "description" : "Unauthorized", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "403": { - "description": "Forbidden", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "403" : { + "description" : "Forbidden", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "404": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemJson" + "404" : { + "description" : "Not Found", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } }, - "description": "Not Found", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ProblemJson" } } } }, - "429": { - "description": "Too many requests", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "429" : { + "description" : "Too many requests", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "500": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemJson" + "500" : { + "description" : "Service unavailable.", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } }, - "description": "Service unavailable.", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ProblemJson" } } } } }, - "security": [ - { - "ApiKey": [] - } - ], - "summary": "API to trigger the deletion of the bundles by a CDI id.", - "tags": [ - "Delete Bundles by id CDI rest API" - ] + "security" : [ { + "ApiKey" : [ ] + } ] }, - "parameters": [ - { - "description": "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", - "in": "header", - "name": "X-Request-Id", - "schema": { - "type": "string" - } + "parameters" : [ { + "name" : "X-Request-Id", + "in" : "header", + "description" : "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", + "schema" : { + "type" : "string" } - ] + } ] } }, - "components": { - "schemas": { - "AppInfo": { - "type": "object", - "properties": { - "environment": { - "type": "string" - }, - "name": { - "type": "string" - }, - "version": { - "type": "string" - } - } - }, - "BundleResponse": { - "type": "object", - "properties": { - "idBundle": { - "type": "string" - } - } - }, - "CDI": { - "type": "object", - "properties": { - "abi": { - "type": "string" - }, - "cdiErrorDesc": { - "type": "string" - }, - "cdiStatus": { - "type": "string", - "enum": [ - "NEW", - "FAILED", - "PROCESSING" - ] - }, - "details": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Detail" - } + "components" : { + "schemas" : { + "CDI" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "string" }, - "digitalStamp": { - "type": "boolean" + "idPsp" : { + "type" : "string" }, - "id": { - "type": "string" + "idCdi" : { + "type" : "string" }, - "idCdi": { - "type": "string" + "abi" : { + "type" : "string" }, - "idPsp": { - "type": "string" + "digitalStamp" : { + "type" : "boolean" }, - "pspBusinessName": { - "type": "string" + "validityDateFrom" : { + "type" : "string" }, - "validityDateFrom": { - "type": "string" + "pspBusinessName" : { + "type" : "string" + }, + "details" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/Detail" + } + }, + "cdiStatus" : { + "type" : "string", + "enum" : [ "NEW", "FAILED", "PROCESSING" ] + }, + "cdiErrorDesc" : { + "type" : "string" } } }, - "Detail": { - "type": "object", - "properties": { - "channelApp": { - "type": "boolean" + "Detail" : { + "type" : "object", + "properties" : { + "idBrokerPsp" : { + "type" : "string" }, - "channelCardsCart": { - "type": "boolean" + "idChannel" : { + "type" : "string" }, - "description": { - "type": "string" + "name" : { + "type" : "string" }, - "idBrokerPsp": { - "type": "string" + "description" : { + "type" : "string" }, - "idChannel": { - "type": "string" + "paymentType" : { + "type" : "string" }, - "name": { - "type": "string" + "channelApp" : { + "type" : "boolean" }, - "paymentType": { - "type": "string" + "channelCardsCart" : { + "type" : "boolean" }, - "serviceAmount": { - "type": "array", - "items": { - "$ref": "#/components/schemas/ServiceAmount" + "serviceAmount" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/ServiceAmount" } } } }, - "ProblemJson": { - "type": "object", - "properties": { - "detail": { - "type": "string", - "description": "A human readable explanation specific to this occurrence of the problem.", - "example": "There was an error processing the request" - }, - "status": { - "maximum": 600, - "minimum": 100, - "type": "integer", - "description": "The HTTP status code generated by the origin server for this occurrence of the problem.", - "format": "int32", - "example": 200 - }, - "title": { - "type": "string", - "description": "A short, summary of the problem type. Written in english and readable for engineers (usually not suited for non technical stakeholders and not localized); example: Service Unavailable" + "ServiceAmount" : { + "type" : "object", + "properties" : { + "paymentAmount" : { + "type" : "integer", + "format" : "int64" + }, + "minPaymentAmount" : { + "type" : "integer", + "format" : "int64" + }, + "maxPaymentAmount" : { + "type" : "integer", + "format" : "int64" + } + } + }, + "ProblemJson" : { + "type" : "object", + "properties" : { + "title" : { + "type" : "string", + "description" : "A short, summary of the problem type. Written in english and readable for engineers (usually not suited for non technical stakeholders and not localized); example: Service Unavailable" + }, + "status" : { + "maximum" : 600, + "minimum" : 100, + "type" : "integer", + "description" : "The HTTP status code generated by the origin server for this occurrence of the problem.", + "format" : "int32", + "example" : 200 + }, + "detail" : { + "type" : "string", + "description" : "A human readable explanation specific to this occurrence of the problem.", + "example" : "There was an error processing the request" } } }, - "ServiceAmount": { - "type": "object", - "properties": { - "maxPaymentAmount": { - "type": "integer", - "format": "int64" - }, - "minPaymentAmount": { - "type": "integer", - "format": "int64" - }, - "paymentAmount": { - "type": "integer", - "format": "int64" + "BundleResponse" : { + "type" : "object", + "properties" : { + "idBundle" : { + "type" : "string" + } + } + }, + "AppInfo" : { + "type" : "object", + "properties" : { + "name" : { + "type" : "string" + }, + "version" : { + "type" : "string" + }, + "environment" : { + "type" : "string" } } } }, - "securitySchemes": { - "ApiKey": { - "description": "The API key to access this function app.", - "in": "header", - "name": "Ocp-Apim-Subscription-Key", - "type": "apiKey" + "securitySchemes" : { + "ApiKey" : { + "type" : "apiKey", + "description" : "The API key to access this function app.", + "name" : "Ocp-Apim-Subscription-Key", + "in" : "header" } } } -} +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index a408ebfd..774bc3c1 100644 --- a/pom.xml +++ b/pom.xml @@ -1,238 +1,244 @@ - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.7.7 - - - - it.gov.pagopa - afm-utils - 0.6.2-5-PAGOPA-1215-afm-calculator-creare-dashboard-elk - afm-utils - Utility microservice for pagoPA AFM - jar - - - 11 - 11 - 11 - - 3.30.0 - UTF-8 - - 1.22.0 - 3.0.0 - 3.2.8 - - - spring-function-resource-group - spring-function-afm-utils - - westeurope - ${project.build.directory}/azure-functions/${functionAppName} - it.gov.pagopa.afm.utils.Application - - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-validation - - - - - org.springframework.cloud - spring-cloud-starter-openfeign - 3.1.5 - - - - org.springframework.retry - spring-retry - - - - - org.springdoc - springdoc-openapi-ui - 1.6.11 - - - - org.springframework.boot - spring-boot-devtools - runtime - true - - - org.springframework.boot - spring-boot-configuration-processor - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-starter-actuator - - - - org.springframework.boot - spring-boot-starter-cache - - - - com.github.ben-manes.caffeine - caffeine - - - - - org.modelmapper - modelmapper - 3.1.0 - - - org.apache.commons - commons-lang3 - - - org.projectlombok - lombok - true - - - - org.springframework.cloud - spring-cloud-function-adapter-azure - - - org.springframework.cloud - spring-cloud-starter-function-webflux - provided - - - - com.azure - azure-spring-data-cosmos - ${cosmos-data-version} - - - - junit - junit - test - - - - org.jeasy - easy-random-core - 5.0.0 - test - - - - com.github.tomakehurst - wiremock - 2.27.2 - test - - - - org.junit.jupiter - junit-jupiter-api - test - - - io.gatling.highcharts - gatling-charts-highcharts - 3.9.0 - test - - - - co.elastic.logging - logback-ecs-encoder - 1.5.0 - - - - - - - - org.springframework.cloud - spring-cloud-function-dependencies - ${spring.cloud.function.dependencies} - pom - import - - - com.microsoft.azure.functions - azure-functions-java-library - ${azure.functions.java.library.version} - - - - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.springframework.boot - spring-boot-maven-plugin - - - org.jacoco - jacoco-maven-plugin - 0.8.7 - - - - - - - - prepare-agent - - - - report - test - - report - - - - - - org.sonarsource.scanner.maven - sonar-maven-plugin - 3.7.0.1746 - - - verify - - sonar - - - - - - + spring-boot-starter-parent + 2.7.7 + + + + it.gov.pagopa + afm-utils + 0.6.2-5-PAGOPA-1215-afm-calculator-creare-dashboard-elk + afm-utils + Utility microservice for pagoPA AFM + jar + + + 11 + 11 + 11 + + 3.30.0 + UTF-8 + + 1.22.0 + 3.0.0 + 3.2.8 + + + spring-function-resource-group + spring-function-afm-utils + + westeurope + ${project.build.directory}/azure-functions/${functionAppName} + it.gov.pagopa.afm.utils.Application + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-validation + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + 3.1.5 + + + + org.springframework.retry + spring-retry + + + + + org.springdoc + springdoc-openapi-ui + 1.6.11 + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.boot + spring-boot-starter-cache + + + + com.github.ben-manes.caffeine + caffeine + + + + + org.modelmapper + modelmapper + 3.1.0 + + + org.apache.commons + commons-lang3 + + + org.projectlombok + lombok + true + + + + org.springframework.cloud + spring-cloud-function-adapter-azure + + + org.springframework.cloud + spring-cloud-starter-function-webflux + provided + + + + com.azure + azure-spring-data-cosmos + ${cosmos-data-version} + + + + junit + junit + test + + + + org.jeasy + easy-random-core + 5.0.0 + test + + + + com.github.tomakehurst + wiremock + 2.27.2 + test + + + + org.junit.jupiter + junit-jupiter-api + test + + + io.gatling.highcharts + gatling-charts-highcharts + 3.9.0 + test + + + + co.elastic.logging + logback-ecs-encoder + 1.5.0 + + + + + + + + org.springframework.cloud + spring-cloud-function-dependencies + ${spring.cloud.function.dependencies} + pom + import + + + com.microsoft.azure.functions + azure-functions-java-library + ${azure.functions.java.library.version} + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.jacoco + jacoco-maven-plugin + 0.8.7 + + + + + + + + prepare-agent + + + + report + test + + report + + + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + 3.7.0.1746 + + + verify + + sonar + + + + + + + + src/test/resources + true + + + diff --git a/src/main/java/it/gov/pagopa/afm/utils/config/OpenApiConfig.java b/src/main/java/it/gov/pagopa/afm/utils/config/OpenApiConfig.java index 41f6b5aa..03d9ef02 100644 --- a/src/main/java/it/gov/pagopa/afm/utils/config/OpenApiConfig.java +++ b/src/main/java/it/gov/pagopa/afm/utils/config/OpenApiConfig.java @@ -25,7 +25,7 @@ public class OpenApiConfig { @Bean public OpenAPI customOpenAPI( - @Value("${info.application.name}") String appName, + @Value("${info.application.artifactId}") String appName, @Value("${info.application.description}") String appDescription, @Value("${info.application.version}") String appVersion) { return new OpenAPI() diff --git a/src/main/java/it/gov/pagopa/afm/utils/controller/BaseController.java b/src/main/java/it/gov/pagopa/afm/utils/controller/BaseController.java index 25b0f63f..18fb8196 100644 --- a/src/main/java/it/gov/pagopa/afm/utils/controller/BaseController.java +++ b/src/main/java/it/gov/pagopa/afm/utils/controller/BaseController.java @@ -18,7 +18,7 @@ @RestController() public class BaseController { - @Value("${info.application.name}") + @Value("${info.application.artifactId}") private String name; @Value("${info.application.version}") diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index 90077003..6923dfcf 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1,4 +1,4 @@ -info.application.name=@project.artifactId@ +info.application.artifactId=@project.artifactId@ info.application.version=@project.version@ info.application.description=@project.description@ info.properties.environment=local diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 19f36095..319b0fed 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ # Info -info.application.name=@project.artifactId@ +info.application.artifactId=@project.artifactId@ info.application.version=@project.version@ info.application.description=@project.description@ info.properties.environment=${ENV:azure} diff --git a/src/test/java/it/gov/pagopa/afm/utils/OpenApiGenerationTest.java b/src/test/java/it/gov/pagopa/afm/utils/OpenApiGenerationTest.java new file mode 100644 index 00000000..cfa40c5e --- /dev/null +++ b/src/test/java/it/gov/pagopa/afm/utils/OpenApiGenerationTest.java @@ -0,0 +1,50 @@ +package it.gov.pagopa.afm.utils; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@SpringBootTest +@AutoConfigureMockMvc +class OpenApiGenerationTest { + + @Autowired + ObjectMapper objectMapper; + + @Autowired + private MockMvc mvc; + + @Test + void swaggerSpringPlugin() throws Exception { + mvc.perform(MockMvcRequestBuilders.get("/v3/api-docs").accept(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) + .andDo( + (result) -> { + assertNotNull(result); + assertNotNull(result.getResponse()); + final String content = result.getResponse().getContentAsString(); + assertFalse(content.isBlank()); + assertFalse(content.contains("${"), "Generated swagger contains placeholders"); + Object swagger = + objectMapper.readValue(result.getResponse().getContentAsString(), Object.class); + String formatted = + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(swagger); + Path basePath = Paths.get("openapi/"); + Files.createDirectories(basePath); + Files.write(basePath.resolve("openapi.json"), formatted.getBytes()); + }); + } +} diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 1754db3c..182fa5ff 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -1,5 +1,5 @@ # Info -info.application.name=@project.artifactId@ +info.application.artifactId=@project.artifactId@ info.application.version=@project.version@ info.application.description=@project.description@ info.properties.environment=test