Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Swagger模型架构不包括body参数的变量名_Java_Json_Swagger_Swagger Ui - Fatal编程技术网

Java Swagger模型架构不包括body参数的变量名

Java Swagger模型架构不包括body参数的变量名,java,json,swagger,swagger-ui,Java,Json,Swagger,Swagger Ui,在我的应用程序的Swagger UI中,我有POST和PUT方法,它们都将POJO作为REST调用中的主体参数。当我查看UI并单击模型模式以自动填充参数框时(只是为了节省键入整个JSON的时间),它不包含参数的名称,因此请求失败。例如: 模型架构: { "first": "string", "last": "string", "address": "string", "email": "string", . . . } 但是,要发出请求,我需要包括参

在我的应用程序的Swagger UI中,我有POST和PUT方法,它们都将POJO作为REST调用中的主体参数。当我查看UI并单击模型模式以自动填充参数框时(只是为了节省键入整个JSON的时间),它不包含参数的名称,因此请求失败。例如:

模型架构:

{ 
   "first": "string",
   "last": "string",
   "address": "string",
   "email": "string",
   .
   .
   .
}
但是,要发出请求,我需要包括参数名称
条目
,如下所示:

{ "entry": {
   "first": "string",
   "last": "string",
   "address": "string",
   "email": "string",
   .
   .
   .
}}

虽然在发出请求之前自己这样做并不太不方便,但这会导致其他开发人员在为我的应用程序使用Swagger UI时出现问题,并且没有意识到他们需要添加
条目
。是否有方法修改模型架构?

参数的
名称
未用作
主体
参数中的属性。为了描述您的模型,您可以使用
对象
类型定义
条目
属性,如下所示:

definitions:
  Entry:
    type: object
    properties:
      entry:
        type: object
        properties:
          first: 
            type: string
          last:
            type: string
          address:
            type: string
          email:
            type: string
您可以将其用作正文模式,如下所示:

post:
  produces:
    - application/json
  parameters:
    - name: body
      in: body
      schema:
        $ref: '#/definitions/Entry'

参数的
名称
未用作
正文
参数中的属性。为了描述您的模型,您可以使用
对象
类型定义
条目
属性,如下所示:

definitions:
  Entry:
    type: object
    properties:
      entry:
        type: object
        properties:
          first: 
            type: string
          last:
            type: string
          address:
            type: string
          email:
            type: string
您可以将其用作正文模式,如下所示:

post:
  produces:
    - application/json
  parameters:
    - name: body
      in: body
      schema:
        $ref: '#/definitions/Entry'

将它放在
定义下
并将其用作主体架构。是否有自动创建正确层次结构的注释??应该可以工作。我在entry类中添加了
ApiModel(value=“entry”)
,但没有在Swagger上的模型架构中添加“entry”。您的
entry
类是否用作api操作中的参数?像
User
一样,将其放在
definitions
下,并将其用作主体架构。是否有自动创建正确层次结构的注释??应该可以工作。我在entry类中添加了
ApiModel(value=“entry”)
,但没有在Swagger上的模型架构中添加“entry”。您的
entry
类是否用作api操作中的参数?像本书中的
User