Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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
Spring boot OpenAPI Swagger codegen Spring Boot:将枚举验证为路径变量_Spring Boot_Swagger Codegen - Fatal编程技术网

Spring boot OpenAPI Swagger codegen Spring Boot:将枚举验证为路径变量

Spring boot OpenAPI Swagger codegen Spring Boot:将枚举验证为路径变量,spring-boot,swagger-codegen,Spring Boot,Swagger Codegen,我正在使用swagger 2.0 我的终点 /api/ideas/{idea_id}/{field}: put: tags: - ideas operationId: UpdateIdeaField description: Update a field in an idea parameters: - name: idea_id in: path type: integer required: true - nam

我正在使用swagger 2.0

我的终点

  /api/ideas/{idea_id}/{field}:
put:
  tags:
    - ideas
  operationId: UpdateIdeaField
  description: Update a field in an idea
  parameters:
    - name: idea_id
      in: path
      type: integer
      required: true
    - name: field
      in: path
      required: true
      type: string
      enum: [division,executive_sponsor,platform_contact]
我希望这样,当我使用一个无效的枚举时,它抛出400。但是,现在对于无效的枚举,它接受它

codegen正在产生什么样的狂妄

    @ApiOperation(value = "", nickname = "updateIdeaField", notes = "Update a field in an idea", response = IdeaVM.class, authorizations = {
    @Authorization(value = "openId", scopes = {
        
        })
}, tags={ "ideas", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "Idea updated", response = IdeaVM.class),
    @ApiResponse(code = 400, message = "Bad Request", response = ProblemVM.class),
    @ApiResponse(code = 401, message = "Unauthorized", response = ProblemVM.class),
    @ApiResponse(code = 403, message = "Forbidden", response = ProblemVM.class),
    @ApiResponse(code = 404, message = "Not Found", response = ProblemVM.class),
    @ApiResponse(code = 422, message = "Unprocessable Entity", response = ProblemVM.class),
    @ApiResponse(code = 200, message = "Something went wrong", response = ProblemVM.class) })
@RequestMapping(value = "/api/ideas/{idea_id}/{field}",
    produces = { "application/json", "application/problem+json" }, 
    method = RequestMethod.PUT)
default ResponseEntity<IdeaVM> _updateIdeaField(@ApiParam(value = "",required=true) @PathVariable("idea_id") Integer ideaId,@ApiParam(value = "",required=true, allowableValues = "\"division\", \"executive_sponsor\", \"platform_contact\"") @PathVariable("field") String field) {
    return updateIdeaField(ideaId, field);
}

// Override this method
default ResponseEntity<IdeaVM> updateIdeaField(Integer ideaId,String field) {
    if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
        if (getAcceptHeader().get().contains("application/json")) {
            try {
                return new ResponseEntity<>(getObjectMapper().get().readValue("{  \"submitted_date\" : \"2019-10-03T22:45:465Z\",  \"gp_status\" : \"IN_REVIEW\",  \"challenge_id\" : 897,  \"account_executive\" : \"0f4c0f7e-18ce-4b7c-bd48-f4121790dd90\",  \"platform_contact\" : \"Walter Waldo\",  \"public_id\" : \"201e6466-6924-11ea-bc55-0242ac130003\",  \"entered_gate_date\" : \"2019-10-03T22:45:465Z\",  \"division\" : \"Asett Managment\",  \"idea_type\" : \"201e6466-6924-11ea-bc55-0242ac130003\",  \"read_only\" : false,  \"collaborators\" : [ \"b4bd2cc9-def8-4b85-86d3-40fb0225542a\", \"400f3605-864a-4cb1-8968-03c831fc49e8\" ],  \"publication_date\" : \"2019-10-03T22:45:465Z\",  \"rank\" : 1576844,  \"id\" : 1,  \"views_count\" : 201,  \"pending_collaborators\" : [ \"john.smith1@companydomain.com\", \"john.smith2@companydomain.com\" ],  \"brief\" : \"We want to explore and ideate solutions which can be utilised to increase last minute bookings\",  \"owner\" : \"0f4c0f7e-18ce-4b7c-bd48-f4121790dd90\",  \"image_link\" : \"https\",  \"idea_description\" : {    \"answers\" : [ {      \"answer\" : \"The Answer to the Ultimate Question of Life, the Universe, and Everything is... 42\",      \"question_id\" : 1    }, {      \"answer\" : \"The Answer to the Ultimate Question of Life, the Universe, and Everything is... 42\",      \"question_id\" : 1    } ]  },  \"creation_date\" : \"2019-10-03T22:45:465Z\",  \"modified_date\" : \"2019-10-03T22:45:465Z\",  \"killed_on_hold_date\" : \"2019-10-03T22:45:465Z\",  \"executive_sponsor\" : \"Wally Waldo\",  \"tags\" : [ \"Cancellation\", \"Last minute bookins\", \"Delays\", \"Satisfaction\" ],  \"total_invested\" : 132000,  \"likes_count\" : 126,  \"review_date\" : \"2019-10-03T22:45:465Z\",  \"mentors\" : [ \"b4bd2cc9-def8-4b85-86d3-40fb0225542a\", \"400f3605-864a-4cb1-8968-03c831fc49e8\" ],  \"followers_count\" : 7,  \"name\" : \"Last minute booking promotions\",  \"is_public\" : false,  \"gate\" : {    \"active\" : true,    \"id\" : 1,    \"display_name\" : \"Discovery\",    \"key\" : \"gate_discovery\",    \"order\" : 1  },  \"status\" : \"DRAFT\"}", IdeaVM.class), HttpStatus.NOT_IMPLEMENTED);
            } catch (IOException e) {
                log.error("Couldn't serialize response for content type application/json", e);
                return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
            }
        }
    } else {
        log.warn("ObjectMapper or HttpServletRequest not configured in default IdeasApi interface so no example is generated");
    }
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}

是否尝试创建单独的枚举对象

MyEnum:
  type: string
  enum:
 - value1
 - value2

然后只需对该枚举使用
$ref

您可以尝试创建一个自定义转换器,以将字符串转换为枚举,如下所示:

因此,我尝试了以下操作,但它仍然在生成的代码中映射为字符串,并且仍然相同。我可以向您发送一个无效的枚举,例如您仍然是用户schema+类型。仅使用模式如果我删除模式,则生成失败。您没有获得)离开模式,但在参数声明中远程键入“``-name:field in:path required:true schema:$ref:'#/definitions/MyEnum'```抱歉,请编辑OP以获得正确的格式,而此链接可能会回答问题,最好在这里包括答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能无效。-请不要依赖外部链接来获取答案的“如何”部分。答案应该是自包含的,并且只能链接到其他网站以供参考。如果该站点将来消失或移动,这个答案对其他人仍然有用。
MyEnum:
  type: string
  enum:
 - value1
 - value2
/api/ideas/{idea_id}/{field}:
put:
  tags:
    - ideas
  operationId: UpdateIdeaField
  description: Update a field in an idea
  parameters:
    - name: idea_id
      in: path
      type: integer
      required: true
    - name: field
      in: path
      required: true
      schema:
        $ref: '#/definitions/MyEnum'
    - in: body
      name: value
      required: true
      schema:
        $ref: '#/definitions/UpdateIdeaFieldRequest'