为什么Swagger在示例中创建了一个systemId字段?

Gan*_*nus 14 java rest json swagger javax

我有一个REST POST函数,它具有以下标题:

@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) {
Run Code Online (Sandbox Code Playgroud)

当我在Swagger UI中查看它时,Swagger会创建一个示例请求体.那个尸体有

systemId (string, optional),
Run Code Online (Sandbox Code Playgroud)

在模型视图和

systemId : "string"
Run Code Online (Sandbox Code Playgroud)

在JSON视图中.但是在整个项目中没有一个名为的字段systemId.我一个接一个地检查了请求类及其祖先,并通过搜索Java检查了整个项目.systemId即使是另一个名称的子字符串,该符号序列也不会出现.

Swagger在哪里得到这个名字,我怎么能阻止它呢?因为我希望它能够创建一个有效的例子.

编辑:API函数本身可以毫无问题地获取JSON输入,并正确地组成声明的类的对象.

进口:

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;
Run Code Online (Sandbox Code Playgroud)

昂首阔步的UI看起来如此:

在此输入图像描述

编辑2.
我删除了@SwaggerDataType,或用@RequestBody替换它,但奇怪的行为仍然存在.

我已将示例设置为显示为具有实际数据的具体字符串:

@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" +
Run Code Online (Sandbox Code Playgroud)

即使这没有帮助!Swagger仍会在某个远程文件中生成一些无意义的字符串(感谢@ xpa1492作为参考),而不是简单地显示准备好的字符串.

更多编辑:

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

Mar*_*min 1

似乎已经在这里得到回答:https://github.com/kongchen/swagger-maven-plugin/issues/608

Swagger 配置未加载 Jackson 注释模块,忽略使用的所有注释。因此 ApiReader 读取了错误的类(https://docs.oracle.com/javase/8/docs/api/org/w3c/dom/DocumentType.html)。