Skip to content

Commit

Permalink
fix: increase size of detail error message
Browse files Browse the repository at this point in the history
  • Loading branch information
simone-lungarella committed May 14, 2024
1 parent 6dcbba5 commit f0b650d
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,13 @@
import io.swagger.v3.oas.models.responses.ApiResponses;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.servers.Server;
import io.swagger.v3.oas.models.tags.Tag;

@Configuration
@SecuritySchemes( {
@SecurityScheme(
name = "bearerAuth",
type = SecuritySchemeType.HTTP,
bearerFormat = "JWT",
scheme = "bearer",
description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token} [RFC8725](https://tools.ietf.org/html/RFC8725).\""),
@SecurityScheme(
name = "FSE-JWT-Signature",
type = SecuritySchemeType.APIKEY,
in = SecuritySchemeIn.HEADER)
}
)
@Configuration
@SecuritySchemes({
@SecurityScheme(name = "bearerAuth", type = SecuritySchemeType.HTTP, bearerFormat = "JWT", scheme = "bearer", description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token} [RFC8725](https://tools.ietf.org/html/RFC8725).\""),
@SecurityScheme(name = "FSE-JWT-Signature", type = SecuritySchemeType.APIKEY, in = SecuritySchemeIn.HEADER)
})
public class OpenApiCFG {

@Autowired
Expand All @@ -60,7 +52,7 @@ public class OpenApiCFG {
public OpenApiCFG() {
// Empty constructor.
}

@Bean
public OpenApiCustomiser openApiCustomiser() {

Expand All @@ -76,6 +68,13 @@ public OpenApiCustomiser openApiCustomiser() {
openApi.getInfo().setDescription(customOpenapi.getDescription());
openApi.getInfo().setTermsOfService(customOpenapi.getTermsOfService());

List<Tag> tags = new ArrayList<>();
tags.add(new Tag().name("Servizio ispezione transazioni"));
tags.add(new Tag().name("Servizio validazione documenti"));
tags.add(new Tag().name("Servizio pubblicazione documenti"));
tags.add(new Tag().name("Health check Status Actuator"));
openApi.setTags(tags);

// Adding contact to info section
final Contact contact = new Contact();
contact.setName(customOpenapi.getContactName());
Expand All @@ -98,14 +97,14 @@ public OpenApiCustomiser openApiCustomiser() {
});

openApi.getPaths().values()
.stream()
.map(item -> getFileSchema(item))
.filter(Objects::nonNull)
.forEach(schema -> {
schema.additionalProperties(false);
schema.getProperties().get("file").setMaxLength(customOpenapi.getFileMaxLength());
schema.required(required);
});
.stream()
.map(item -> getFileSchema(item))
.filter(Objects::nonNull)
.forEach(schema -> {
schema.additionalProperties(false);
schema.getProperties().get("file").setMaxLength(customOpenapi.getFileMaxLength());
schema.required(required);
});
};
}

Expand Down Expand Up @@ -138,24 +137,31 @@ public OpenApiCustomiser customerGlobalHeaderOpenApiCustomiser() {

private Schema<?> getFileSchema(PathItem item) {
MediaType mediaType = getMultipartFile(item);
if (mediaType == null) return null;
if (mediaType == null)
return null;
return mediaType.getSchema();
}

private Operation getOperation(PathItem item) {
if (item.getPost() != null) return item.getPost();
if (item.getPatch() != null) return item.getPatch();
if (item.getPut() != null) return item.getPut();
if (item.getPost() != null)
return item.getPost();
if (item.getPatch() != null)
return item.getPatch();
if (item.getPut() != null)
return item.getPut();
return null;
}

private MediaType getMultipartFile(PathItem item) {
Operation operation = getOperation(item);
if (operation == null) return null;
if (operation == null)
return null;
RequestBody body = operation.getRequestBody();
if (body == null) return null;
if (body == null)
return null;
Content content = body.getContent();
if (content == null) return null;
if (content == null)
return null;
MediaType mediaType = content.get(org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE);
return mediaType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
import lombok.Data;
import lombok.EqualsAndHashCode;


/**
* The Class ErrorResponseDTO.
*/
@Data
@Builder
@AllArgsConstructor
@EqualsAndHashCode(callSuper=false)
@EqualsAndHashCode(callSuper = false)
public class ErrorResponseDTO {

/**
Expand All @@ -37,7 +36,7 @@ public class ErrorResponseDTO {
@Schema(description = "Indentificativo univoco della richiesta dell'utente")
@Size(min = 0, max = 100)
private String traceID;

/**
* Span id log.
*/
Expand All @@ -48,25 +47,26 @@ public class ErrorResponseDTO {
@Schema(description = "URI da utilizzare come identificativo del problema che si è verificato")
@Size(min = 0, max = 100)
private String type;
@Schema(description = "Descrizione sintetica della tipologia derrore")

@Schema(description = "Descrizione sintetica della tipologia d'errore")
@Size(min = 0, max = 1000)
private String title;

@Schema(description = "Dettaglio della tipologia derrore")
@Size(min = 0, max = 200000)
@Schema(description = "Dettaglio della tipologia d'errore")
@Size(min = 0, max = Integer.MAX_VALUE)
private String detail;

@Schema(description = "Stato http")
@Min(value = 100)
@Max(value = 599)
private Integer status;

@Schema(description = "URI che identifica la specifica occorrenza del problema")
@Size(min = 0, max = 100)
private String instance;

public ErrorResponseDTO(final LogTraceInfoDTO traceInfo, final String inType, final String inTitle, final String inDetail, final Integer inStatus, final String inInstance) {
public ErrorResponseDTO(final LogTraceInfoDTO traceInfo, final String inType, final String inTitle,
final String inDetail, final Integer inStatus, final String inInstance) {
traceID = traceInfo.getTraceID();
spanID = traceInfo.getSpanID();
type = inType;
Expand All @@ -78,7 +78,7 @@ public ErrorResponseDTO(final LogTraceInfoDTO traceInfo, final String inType, fi

public ErrorResponseDTO(final LogTraceInfoDTO traceInfo) {
traceID = traceInfo.getTraceID();
spanID = traceInfo.getSpanID();
spanID = traceInfo.getSpanID();
}

}
Loading

0 comments on commit f0b650d

Please sign in to comment.