Change API Input from STRING to WRAPPER - Java Jersey with Swagger

23 views Asked by At

I'm currently trying to integrate Swagger with a Java EE project (maven-based) jersey jax-rs built. I've been able to finally expose MyResource.java to the Swagger and on SwaggerUI I can finally see my API endpoints. The issue that faces me right now is that each endpoint has the input as (string) which is very vague when it comes to documentation, check

this screenshot

However, what I want to do is to show a more detailed structure to this input so that it appears more appropriate and self-explanatory to others. This string is meant to be a JSON string that will contain a customer code, of course, that's only one example. I've been asked to convert this "String req" to a "Wrapper?". I'm not sure what is entirely meant by this, but what I explained above is the required output. Here's a code snippet of the service input from MyResource.java that the swagger reads from:

@POST
    @Path("GetCustomerData")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)

    public GetCustomerDataRes GetCustomerData(String req) throws IOException, Exception {
        logger.info("GetCustomerData Request: " + req);

        GetCustomerDataRes res = new GetCustomerDataRes();
        CommonResMsgHdr MsgHdr = new CommonResMsgHdr();
        CommonResponse comres = new CommonResponse();

        GetCustomerDataRes_Data data = new GetCustomerDataRes_Data();

        String facility1 = "";
        String macroFacility1 = "";
        String productCode1 = "";

        String reqRecievedAt = new Timestamp(System.currentTimeMillis()).toString();
        String callName = "GetCustomerData";

        try {

            JSONObject requestJOSN = new JSONObject(req);
            String cic = requestJOSN.getString("cic");

            if (requestJOSN.has("productKey")) {
                if (requestJOSN.get("productKey") instanceof JSONObject) {
                    if (requestJOSN.getJSONObject("productKey").has("facility"))
                        facility1 = (requestJOSN.getJSONObject("productKey").getString("facility"));
                    if (requestJOSN.getJSONObject("productKey").has("macroFacility"))
                        macroFacility1 = (requestJOSN.getJSONObject("productKey").getString("macroFacility"));
                    if (requestJOSN.getJSONObject("productKey").has("productCode"))
                        productCode1 = (requestJOSN.getJSONObject("productKey").getString("productCode"));
                }
            }

Of course, I want the structure to follow something like the check conditions, etc.

I tried using annotations, but I've been asked to not use annotations and change the type/structure of the input. Is there a specific way to do that or a convention for this? I'm fairly new to JavaEE and Java Web.

0

There are 0 answers