Skip to content

Commit

Permalink
Insert of ProblemJson class in swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoRuzzier committed Nov 3, 2022
1 parent 28a6c4f commit 9356147
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ See the [Openapi here](https://github.com/pagopa/poc-quarkus/openapi/openapi.jso

## Contributors 👥

Created by PagoPa S.p.A
Made with ❤️ by PagoPa S.p.A

### Mainteiners

Expand Down
74 changes: 62 additions & 12 deletions openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@
"500": {
"description": "Service unavailable.",
"content": {
"application/json": {}
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemJson"
}
}
}
}
}
Expand Down Expand Up @@ -103,13 +107,21 @@
"404": {
"description": "Not found the enroll service.",
"content": {
"application/json": {}
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemJson"
}
}
}
},
"500": {
"description": "Service unavailable.",
"content": {
"application/json": {}
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemJson"
}
}
}
}
}
Expand Down Expand Up @@ -139,22 +151,30 @@
}
}
},
"409": {
"description": "Conflict",
"401": {
"description": "Unauthorized",
"content": {
"application/json": {}
}
},
"401": {
"description": "Unauthourized",
"409": {
"description": "Conflict",
"content": {
"application/json": {}
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemJson"
}
}
}
},
"500": {
"description": "Internal server error",
"content": {
"application/json": {}
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemJson"
}
}
}
}
}
Expand Down Expand Up @@ -185,7 +205,7 @@
}
},
"401": {
"description": "Unauthourized.",
"description": "Unauthorized.",
"content": {
"application/json": {
"schema": {}
Expand All @@ -195,13 +215,21 @@
"404": {
"description": "Not found the creditor institution.",
"content": {
"application/json": {}
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemJson"
}
}
}
},
"500": {
"description": "Service unavailable.",
"content": {
"application/json": {}
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemJson"
}
}
}
}
}
Expand Down Expand Up @@ -239,6 +267,28 @@
"$ref": "#/components/schemas/LocalDateTime"
}
}
},
"ProblemJson": {
"type": "object",
"properties": {
"title": {
"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",
"type": "string"
},
"status": {
"format": "int32",
"description": "The HTTP status code generated by the origin server for this occurrence of the problem.",
"maximum": 600,
"minimum": 100,
"type": "integer",
"example": 200
},
"detail": {
"description": "A human readable explanation specific to this occurrence of the problem.",
"type": "string",
"example": "There was an error processing the request"
}
}
}
}
}
Expand Down
61 changes: 52 additions & 9 deletions openapi/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@
"schema": {}
},
"500": {
"description": "Service unavailable."
"description": "Service unavailable.",
"schema": {
"$ref": "#/definitions/ProblemJson"
}
}
},
"tags": [
Expand Down Expand Up @@ -77,14 +80,20 @@
}
},
"401": {
"description": "Unauthourized.",
"description": "Unauthorized.",
"schema": {}
},
"404": {
"description": "Not found the creditor institution."
"description": "Not found the creditor institution.",
"schema": {
"$ref": "#/definitions/ProblemJson"
}
},
"500": {
"description": "Service unavailable."
"description": "Service unavailable.",
"schema": {
"$ref": "#/definitions/ProblemJson"
}
}
},
"tags": [
Expand Down Expand Up @@ -115,10 +124,16 @@
"schema": {}
},
"404": {
"description": "Not found the enroll service."
"description": "Not found the enroll service.",
"schema": {
"$ref": "#/definitions/ProblemJson"
}
},
"500": {
"description": "Service unavailable."
"description": "Service unavailable.",
"schema": {
"$ref": "#/definitions/ProblemJson"
}
}
},
"tags": [
Expand All @@ -145,13 +160,19 @@
}
},
"401": {
"description": "Unauthourized"
"description": "Unauthorized"
},
"409": {
"description": "Conflict"
"description": "Conflict",
"schema": {
"$ref": "#/definitions/ProblemJson"
}
},
"500": {
"description": "Internal server error"
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/ProblemJson"
}
}
},
"tags": [
Expand Down Expand Up @@ -190,6 +211,28 @@
}
},
"type": "object"
},
"ProblemJson": {
"properties": {
"detail": {
"description": "A human readable explanation specific to this occurrence of the problem.",
"example": "There was an error processing the request",
"type": "string"
},
"status": {
"description": "The HTTP status code generated by the origin server for this occurrence of the problem.",
"example": 200,
"format": "int32",
"maximum": 600,
"minimum": 100,
"type": "integer"
},
"title": {
"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",
"type": "string"
}
},
"type": "object"
}
},
"x-components": {}
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/it/gov/pagopa/Controller/EnrollmentsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


import it.gov.pagopa.Model.OrganizationModelResponse;
import it.gov.pagopa.Model.ProblemJson;
import it.gov.pagopa.Service.EnrollmentsService;
import it.gov.pagopa.Mapper.OrganizationMapper;

Expand All @@ -34,9 +35,9 @@ public class EnrollmentsController {

@APIResponses(value = {
@APIResponse(responseCode = "201", description = "Created", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = OrganizationModelResponse.class))),
@APIResponse(responseCode = "409", description = "Conflict", content = @Content(mediaType = MediaType.APPLICATION_JSON)),
@APIResponse(responseCode = "401", description = "Unauthourized", content = @Content(mediaType = MediaType.APPLICATION_JSON)),
@APIResponse(responseCode = "500", description = "Internal server error", content = @Content(mediaType = MediaType.APPLICATION_JSON))
@APIResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON)),
@APIResponse(responseCode = "409", description = "Conflict", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ProblemJson.class))),
@APIResponse(responseCode = "500", description = "Internal server error", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ProblemJson.class)))
})
@Path("/{organizationFiscalCode}")
@POST
Expand All @@ -46,9 +47,9 @@ public Response createOrganization(@PathParam("organizationFiscalCode")String or

@APIResponses(value = {
@APIResponse(responseCode = "200", description = "Request deleted.", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(name = "StringResponse", implementation = OrganizationModelResponse.class))),
@APIResponse(responseCode = "401", description = "Unauthourized.", content = @Content(schema = @Schema())),
@APIResponse(responseCode = "404", description = "Not found the creditor institution.", content = @Content(mediaType = MediaType.APPLICATION_JSON)),
@APIResponse(responseCode = "500", description = "Service unavailable.", content = @Content(mediaType = MediaType.APPLICATION_JSON))
@APIResponse(responseCode = "401", description = "Unauthorized.", content = @Content(schema = @Schema())),
@APIResponse(responseCode = "404", description = "Not found the creditor institution.", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ProblemJson.class))),
@APIResponse(responseCode = "500", description = "Service unavailable.", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ProblemJson.class)))
})
@Path("/{organizationFiscalCode}")
@DELETE
Expand All @@ -59,8 +60,8 @@ public Response removeOrganization(@PathParam("organizationFiscalCode")String or
@APIResponses(value = {
@APIResponse(responseCode = "200", description = "Obtained single enrollment.", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(name = "OrganizationModelResponse", implementation = OrganizationModelResponse.class))),
@APIResponse(responseCode = "401", description = "Unauthorized.", content = @Content(schema = @Schema())),
@APIResponse(responseCode = "404", description = "Not found the enroll service.", content = @Content(mediaType = MediaType.APPLICATION_JSON)),
@APIResponse(responseCode = "500", description = "Service unavailable.", content = @Content(mediaType = MediaType.APPLICATION_JSON))
@APIResponse(responseCode = "404", description = "Not found the enroll service.", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ProblemJson.class))),
@APIResponse(responseCode = "500", description = "Service unavailable.", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ProblemJson.class)))
})
@Path("/{organizationFiscalCode}")
@GET
Expand All @@ -71,7 +72,7 @@ public Response getOrganization(@PathParam("organizationFiscalCode")String organ
@APIResponses(value = {
@APIResponse(responseCode = "200", description = "Obtained all enrollments.", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(type = SchemaType.ARRAY, implementation = OrganizationModelResponse.class))),
@APIResponse(responseCode = "401", description = "Unauthorized.", content = @Content(schema = @Schema())),
@APIResponse(responseCode = "500", description = "Service unavailable.", content = @Content(mediaType = MediaType.APPLICATION_JSON))
@APIResponse(responseCode = "500", description = "Service unavailable.", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ProblemJson.class)))
})
@GET
public Response getOrganizations(){
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/it/gov/pagopa/Exception/AppError.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
@Getter
public enum AppError {

ORGANIZATION_NOT_FOUND(404, "Organization not found", "Not found the Organization Fiscal Code \"%s\""),
ORGANIZATION_DUPLICATED(409, "Organization with the specified organization fiscal code already exists in the system", "Already exists an organization with Organization Fiscal Code \"%s\""),
INTERNAL_ERROR(500, "Error enrollment processing ", "Error enrollment processing [Organization Fiscal Code = \"%s\"]"),
ORGANIZATION_NOT_FOUND(404, "Organization not found", "Not found the Organization Fiscal Code %s"),
ORGANIZATION_DUPLICATED(409, "Organization with the specified organization fiscal code already exists in the system", "Already exists an organization with Organization Fiscal Code %s"),
INTERNAL_ERROR(500, "Error enrollment processing ", "Error enrollment processing [Organization Fiscal Code = %s]"),
UNKNOWN(520, null, null);


Expand Down
3 changes: 3 additions & 0 deletions src/main/java/it/gov/pagopa/Exception/AppException.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import javax.validation.constraints.NotNull;

import lombok.Getter;

import java.util.Formatter;

@Getter
public class AppException extends RuntimeException{

String title;
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/it/gov/pagopa/Exception/ErrorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@


import io.quarkus.logging.Log;
import it.gov.pagopa.Model.ProblemJson;

@Provider
public class ErrorHandler implements ExceptionMapper<AppException>{

@Override
public Response toResponse(AppException appException) {
Log.info(appException.getCause());
return Response.status(appException.httpStatus).entity(appException.getMessage()).build();
var errorResponse = ProblemJson.builder()
.status(appException.getHttpStatus())
.title(appException.getTitle())
.detail(appException.getMessage())
.build();
return Response.status(appException.httpStatus).entity(errorResponse).build();
}
}
42 changes: 42 additions & 0 deletions src/main/java/it/gov/pagopa/Model/ProblemJson.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package it.gov.pagopa.Model;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
* Object returned as response in case of an error.
* <p> See {@link it.gov.pagopa.spontaneouspayment.exception.ErrorHandler}
*/
@Data
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@ToString
@JsonIgnoreProperties(ignoreUnknown = true)
public class ProblemJson {

@JsonProperty("title")
@Schema(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")
private String title;

@JsonProperty("status")
@Schema(example = "200", description = "The HTTP status code generated by the origin server for this occurrence of the problem.")
@Min(100)
@Max(600)
private Integer status;

@JsonProperty("detail")
@Schema(example = "There was an error processing the request", description = "A human readable explanation specific to this occurrence of the problem.")
private String detail;

}

0 comments on commit 9356147

Please sign in to comment.