Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Swagger created a systemId field in example?

I have a REST POST function that has the following header:

@POST
@Consumes(value = { MediaType.APPLICATION_JSON + ";charset=utf-8" })
@Produces(value = { MediaType.APPLICATION_JSON + ";charset=utf-8" })
@ApiOperation(value = "Create a document type", notes = "creates a document type from Json and returns the created type", response = Response.class)
@Session(roles = { Role.ROLE_ADMINISTRATOR })
@PublicApi
public Response create(
        @ApiParam(value = "Created DocumentType", required = true)
        @SwaggerDataType(type = 
           com.infor.daf.icp.internal.rest.models.DocumentType.class) 
        com.infor.daf.icp.internal.rest.models.DocumentType documentType) {

When I look at it in Swagger UI, the Swagger creates an example request body. That body has

systemId (string, optional),

in Model view and

systemId : "string"

in the JSON view. But in the whole project there is not a field named systemId. I had checked the request class and its ancestors one by one, and the whole project by search Java. That symbol sequence systemId does not appear even as a substring of another name.

Where does Swagger gets that name and how can I stop it? For I want it to create a valid example, of course.

Edit: The API function itself takes JSON input without problems and correctly composes an object of the declared class.

Imports :

package com....documentarchive.rest.v1

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

The swagger UI looks so:

enter image description here

Edit 2.
I have removed @SwaggerDataType, or replaced it with @RequestBody, but the strange behaviour remains.

I have set the example to be shown as a concrete string with real data:

@ApiParam(example = DOC_TYPE_EXAMPLE, value = "Created DocumentType", required = true) @RequestBody com.infor.daf.icp.internal.rest.models.DocumentType documentType) {
....
    static final private String DOC_TYPE_EXAMPLE = "{'entityModel':\n" +
        "    {'name':'Anatemplate',\n" +
        "     'desc':'Ana-template',\n" +

And even that didn't help! Swagger still generates some senseless string from some distant file (thanks to @xpa1492 for the reference) somewhere on the internet, instead of simply showing out the prepared string.

More edit:

The pom file: https://drive.google.com/file/d/16fOCq5EFZYVBJRPg0HeiP102eRzEaH6W/view?usp=sharing

like image 709
Gangnus Avatar asked Apr 20 '18 12:04

Gangnus


1 Answers

Seems to have been answered here: https://github.com/kongchen/swagger-maven-plugin/issues/608

Swagger configuration was not loading the Jackson annotation module, ignoring all annotations used. Therefore ApiReader was reading wrong class (https://docs.oracle.com/javase/8/docs/api/org/w3c/dom/DocumentType.html).

like image 69
Mario Varchmin Avatar answered Sep 26 '22 00:09

Mario Varchmin