9 Ekim 2021 Cumartesi

Swagger @Operation Anotasyonu - Controller'a Eklenir

Giriş
Şu satırı dahil ederiz
import io.swagger.v3.oas.annotations.Operation;
Açıklaması şöyle
In springfox implementation this tag represents the equivalent of the tag @ApiOperation
Açıklaması şöyle
@Operation - Adds details about what the endpoint does, including some properties to achieve this.

summary - The summary (or title) of an endpoint.
description - The description of the endpoint.
tags - What tags to group the endpoint under. You don’t have to specify an array here if there is a single tag; writing tags = "People" also works.
responses - An array of @ApiResponses that details what the endpoint can return, allowing you to show what happens on successful requests as well as unsuccessful or erroneous requests.
operationId Alanı
Örnek
Şöyle yaparız
@Operation(operationId = "deleteJob", summary = "Delete a scheduled job")
responses Alanı
Örnek
Şöyle yaparız
@GetMapping("/{id}")
@Operation( summary = "Finds a person", description = "Finds a person by their Id.", tags = { "People" }, responses = { @ApiResponse( description = "Success", responseCode = "200", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Person.class)) ), @ApiResponse(description = "Not found", responseCode = "404", content = @Content), @ApiResponse(description = "Internal error", responseCode = "500", content = @Content) } ) public ResponseEntity<Person> get(@PathVariable("id") @Parameter(description = "The Id of the person to find.") UUID id) { return personRepository.findById(id).map(ResponseEntity::ok) .orElseThrow(() -> new NoSuchElementException("Person with id: " + id + " does not exist")); }

summary Alanı
Örnek
Şöyle yaparız
@Operation(summary = "Creates a new book")
@ApiResponses(value = {
  @ApiResponse(responseCode = "201", description = "Created book"),
  @ApiResponse(responseCode = "400", description = "Bad request"),
  @ApiResponse(responseCode = "500", description = "Server Error")
@PostMapping(path = "/books", consumes = {"application/json"})
public ResponseEntity<Void> create(@Valid @RequestBody BookDto bookDto) {
  ...
}

Hiç yorum yok:

Yorum Gönder