30 Eylül 2021 Perşembe

Swagger @ApiResponse Anotasyonu

Giriş
Şu satırı dahil ederiz
import io.swagger.annotations.ApiResponses;
content Alanı
Örnek
Şöyle yaparız
@GetMapping
@Operation(summary = "Get the universities for a given country")
@ApiResponses(value = {
  @ApiResponse(responseCode = "200", description = "...",
               content = {@Content(mediaType = "application/json",
                                schema = @Schema(implementation = UniversityDTO.class))}),
  @ApiResponse(responseCode = "400", description = "Invalid id ",content = @Content),
  @ApiResponse(responseCode = "404", description = "...", content = @Content)})
  public List<UniversityDTO> getUniversitiesForCountry(@RequestParam String country) {
    ...
  }
}
responseCode Alanı
Örnek 
Şöyle yaparız
@Operation(summary = "Create customer")
@ApiResponses(value = {
  @ApiResponse(responseCode = "201", description = "Successfully created a customer"),
  @ApiResponse(responseCode = "400", description = "Bad Request"),
  @ApiResponse(responseCode = "401", description = "Authorization denied"),
  @ApiResponse(responseCode = "500", description = "Unexpected system exception"),
  @ApiResponse(responseCode = "502", description = "An error has occurred with an upstream service")
})
@PostMapping(consumes = JSON)
public ResponseEntity createCustomer(@Valid @RequestBody CustomerInfo customerInfo, UriComponentsBuilder uriBuilder)
  throws Exception {
  ...
}

Hiç yorum yok:

Yorum Gönder