0

micronaut 有没有办法像我们在 spring-boot 中通过 spec.yaml 文件那样生成端点?

我们的代码代表一个端点

@Override
public ResponseEntity<UserDetailsDto> createUser(UserDto userDto) {
    User user = repository.save(new User(userDto.getName(), userDto.getEmail()));
    return ResponseEntity.ok().body(new UserDetailsDto(user.getId(), userDto.getName(), userDto.getEmail()));
}

通过 Spring Boot OpenAPI 生成器生成的端点

/**
 * POST /users : Create a new user
 * Create a new user
 *
 * @param userDto  (required)
 * @return successful operation (status code 200)
 */
@ApiOperation(value = "Create a new user", nickname = "createUser", notes = "Create a new user", response = UserDetailsDto.class, tags={ "users", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "successful operation", response = UserDetailsDto.class) })
@RequestMapping(value = "/users",
    produces = { "application/json" }, 
    consumes = { "application/json" },
    method = RequestMethod.POST)
ResponseEntity<UserDetailsDto> createUser(@ApiParam(value = "" ,required=true )  @Valid @RequestBody UserDto userDto);
4

1 回答 1

0

我找到了解决方案。我使用了 java-micronaut-client,它生成了 spec.yaml 文件和 DTO 中描述的端点。但是 micronaut 客户端生成器只有一个 beta 版本。

于 2021-11-12T06:37:28.783 回答