Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/393.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 maven插件仅生成实际需要的参数属性_Java_Maven_Swagger Maven Plugin - Fatal编程技术网

使用Java中的swagger maven插件仅生成实际需要的参数属性

使用Java中的swagger maven插件仅生成实际需要的参数属性,java,maven,swagger-maven-plugin,Java,Maven,Swagger Maven Plugin,我想为swagger maven插件注释我的请求方法,以便在swagger请求参数模式中只显示我实际需要的属性,而不是类的所有属性。例如,如果我有一个带有电子邮件和物理地址的person类,我只需要指定发送普通邮件的物理地址,反之亦然,但生成的招摇过市显示两个呼叫的物理地址 例如: 示例person类: public class Person { private String name; private String email; private String addre

我想为swagger maven插件注释我的请求方法,以便在swagger请求参数模式中只显示我实际需要的属性,而不是类的所有属性。例如,如果我有一个带有电子邮件和物理地址的person类,我只需要指定发送普通邮件的物理地址,反之亦然,但生成的招摇过市显示两个呼叫的物理地址

例如:

示例person类:

public class Person {
    private String name;
    private String email;
    private String address;
    /* getters / setters */
}
我需要注释的资源类:

@Api
@RequestScoped
@Path("odpiranjeRacuna")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class PersonResource {
    @EJB
    PersonSB personSB;

    @ApiOperation(value="Send an email")
    @POST
    @Path("email")
    public Response sendEmail(@ApiParam Person person){
        return Response.ok().entity(personSB.sendMail(person.getEmail(), person.getName())).build();
    }

    @ApiOperation(value="Send a regular mail")
    @POST
    @Path("snailmail")
    public Response sendSnailmail(@ApiParam Person person){
        return Response.ok().entity(personSB.sendSnailmail(person.getAddress(), person.getName())).build();
    }
}
(缩写)生成的招摇过市:

{
  "swagger" : "2.0",
  "paths":{
    "/email" : {
      "post" : {
        "summary" : "Send an email",
        "parameters" : [ {
          "in" : "body",
          "name" : "body",
          "required" : false,
          "schema" : {
            "$ref" : "#/definitions/Person"
          }
        } ]
      }
    },
    "/snailmail" : {
      "post" : {
        "summary" : "Send a regular mail",
        "parameters" : [ {
          "in" : "body",
          "name" : "body",
          "required" : false,
          "schema" : {
            "$ref" : "#/definitions/Person"
          }
        } ]
      }
    }
  },
  "definitions":{
    "Person" : {
      "type" : "object",
      "properties" : {
        "name" : {
          "type" : "string"
        },
        "email" : {
          "type" : "string"
        },
        "address" : {
          "type" : "string"
        }
      }
    }
  }
}
{
  "swagger" : "2.0",
  "paths":{
    "/email" : {
      "post" : {
        "summary" : "Send an email",
        "parameters" : [ {
          "in" : "body",
          "name" : "body",
          "required" : false,
          "schema" : {
            "$ref" : "#/definitions/PersonWithEmail"
          }
        } ]
      }
    },
    "/snailmail" : {
      "post" : {
        "summary" : "Send a regular mail",
        "parameters" : [ {
          "in" : "body",
          "name" : "body",
          "required" : false,
          "schema" : {
            "$ref" : "#/definitions/PersonWithAddress"
          }
        } ]
      }
    }
  },
  "definitions":{
    "PersonWithEmail" : {
      "type" : "object",
      "properties" : {
        "name" : {
          "type" : "string"
        },
        "email" : {
          "type" : "string"
        }
      }
    },
    "PersonWithAddress" : {
      "type" : "object",
      "properties" : {
        "name" : {
          "type" : "string"
        },
        "address" : {
          "type" : "string"
        }
      }
    }
  }
}
(缩写)想要的昂首阔步:

{
  "swagger" : "2.0",
  "paths":{
    "/email" : {
      "post" : {
        "summary" : "Send an email",
        "parameters" : [ {
          "in" : "body",
          "name" : "body",
          "required" : false,
          "schema" : {
            "$ref" : "#/definitions/Person"
          }
        } ]
      }
    },
    "/snailmail" : {
      "post" : {
        "summary" : "Send a regular mail",
        "parameters" : [ {
          "in" : "body",
          "name" : "body",
          "required" : false,
          "schema" : {
            "$ref" : "#/definitions/Person"
          }
        } ]
      }
    }
  },
  "definitions":{
    "Person" : {
      "type" : "object",
      "properties" : {
        "name" : {
          "type" : "string"
        },
        "email" : {
          "type" : "string"
        },
        "address" : {
          "type" : "string"
        }
      }
    }
  }
}
{
  "swagger" : "2.0",
  "paths":{
    "/email" : {
      "post" : {
        "summary" : "Send an email",
        "parameters" : [ {
          "in" : "body",
          "name" : "body",
          "required" : false,
          "schema" : {
            "$ref" : "#/definitions/PersonWithEmail"
          }
        } ]
      }
    },
    "/snailmail" : {
      "post" : {
        "summary" : "Send a regular mail",
        "parameters" : [ {
          "in" : "body",
          "name" : "body",
          "required" : false,
          "schema" : {
            "$ref" : "#/definitions/PersonWithAddress"
          }
        } ]
      }
    }
  },
  "definitions":{
    "PersonWithEmail" : {
      "type" : "object",
      "properties" : {
        "name" : {
          "type" : "string"
        },
        "email" : {
          "type" : "string"
        }
      }
    },
    "PersonWithAddress" : {
      "type" : "object",
      "properties" : {
        "name" : {
          "type" : "string"
        },
        "address" : {
          "type" : "string"
        }
      }
    }
  }
}
区别在于请求模式引用和模式