Skip to content

Commit

Permalink
[PAGOPA-2426] fix: Update APIs title
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-ang committed Dec 2, 2024
1 parent 1b8adfa commit 80c527e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions openapi/openapi-support-internal.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"openapi" : "3.0.1",
"info" : {
"title" : "pagopa-gpd-upload",
"title" : "GPD-Upload-Support-API",
"description" : "Microservice to manage PagoPA GPD Upload",
"termsOfService" : "https://www.pagopa.gov.it/",
"version" : "0.1.22"
Expand Down Expand Up @@ -659,7 +659,7 @@
"/support/uploads/{upload}/status/refresh" : {
"get" : {
"tags" : [ "Support API" ],
"summary" : "Support API to recover status on CREATE operation",
"summary" : "Support API to recover status on CREATE and DELETE operation",
"description" : "Returns the debt positions upload report recovered.",
"operationId" : "recoverStatus",
"parameters" : [ {
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"openapi" : "3.0.1",
"info" : {
"title" : "pagopa-gpd-upload",
"title" : "GPD-Upload-API",
"description" : "Microservice to manage PagoPA GPD Upload",
"termsOfService" : "https://www.pagopa.gov.it/",
"version" : "0.1.22"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/it/gov/pagopa/gpd/upload/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@OpenAPIDefinition(
info = @Info(
title = "pagopa-gpd-upload",
title = "${info.application.title}",
version = "${openapi.application.version}",
description = "Microservice to manage PagoPA GPD Upload",
termsOfService = "https://www.pagopa.gov.it/"
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
info.application.artifactId=${project.artifactId}
info.application.version=${project.version}
info.application.title=GPD-Upload-API
openapi.application.version=0.1.22
info.properties.environment=env
micronaut.application.name=GPD-Massive-Upload-service
Expand All @@ -16,9 +17,11 @@ micronaut.server.max-request-size.multipart.max-file-size=104857600
micronaut.openapi.groups.external.primary=true
micronaut.openapi.groups.external.filename=pagopa-gpd-upload-${openapi.application.version}
micronaut.openapi.groups.external.display-name=GPD-Upload-API
micronaut.openapi.groups.external.title=GPD-Upload-API
micronaut.openapi.groups.external.packages=it.gov.pagopa.gpd.upload.controller.external.*
micronaut.openapi.groups.internal.primary=false
micronaut.openapi.groups.internal.display-name=GPD-Upload-Support-API
micronaut.openapi.groups.internal.title=GPD-Upload-Support-API
micronaut.openapi.groups.internal.filename=pagopa-gpd-upload-support
micronaut.openapi.groups.internal.packages=it.gov.pagopa.gpd.upload.controller.*

Expand Down
30 changes: 17 additions & 13 deletions src/test/java/it/gov/pagopa/gpd/upload/OpenApiGenerationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,30 @@ class OpenApiGenerationTest {
@Client("/")
HttpClient client;

@Value("${info.application.title}")
String title;

@Test
void swaggerSpringPlugin() throws Exception {
boolean result = saveOpenAPI("/swagger/pagopa-gpd-upload-" + version + ".json", "openapi.json");
boolean result = saveOpenAPI("/swagger/pagopa-gpd-upload-" + version + ".json", "openapi.json", "GPD-Upload-API");
assertTrue(result);

boolean resultSupportAPI = saveOpenAPI("/swagger/pagopa-gpd-upload-support.json", "openapi-support-internal.json");
boolean resultSupportAPI = saveOpenAPI("/swagger/pagopa-gpd-upload-support.json", "openapi-support-internal.json", "GPD-Upload-Support-API");
assertTrue(resultSupportAPI);
}

private boolean saveOpenAPI(String fromUri, String toFile) throws IOException {
HttpResponse<String> response = client.toBlocking().exchange(fromUri, String.class);
ObjectMapper objectMapper = new ObjectMapper();
String responseBody = response.getBody().get();
Object openAPI = objectMapper.readValue(responseBody, Object.class);
String formatted = new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(openAPI);
Path basePath = Paths.get("openapi/");
Files.createDirectories(basePath);
Files.write(basePath.resolve(toFile), formatted.getBytes());
return true;
}
private boolean saveOpenAPI(String fromUri, String toFile, String newTitle) throws IOException {
HttpResponse<String> response = client.toBlocking().exchange(fromUri, String.class);
ObjectMapper objectMapper = new ObjectMapper();
String responseBody = response.getBody().get();
responseBody = responseBody.replace(title, newTitle);
Object openAPI = objectMapper.readValue(responseBody, Object.class);
String formatted = new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(openAPI);
Path basePath = Paths.get("openapi/");
Files.createDirectories(basePath);
Files.write(basePath.resolve(toFile), formatted.getBytes());
return true;
}

@Bean
@Primary
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
info.application.artifactId=gpd-massive-upload
info.application.title=GPD-Upload-API
info.application.version=0.1.22
info.properties.environment=test
openapi.application.version=0.1.22
Expand Down

0 comments on commit 80c527e

Please sign in to comment.