implementation 'org.springdoc:springdoc-openapi-ui:1.6.15'
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
@Configuration
public class OpenApiConfig {
/** * OpenAPI bean 구성 * @return */
@Bean public OpenAPI openAPI() {
Info info = new Info()
.title("swagger 테스트")
.version("1.0")
.description("API에 대한 설명 부분");
return new OpenAPI() .components(new Components()) .info(info);
}
}
예시:
@RestController
@Tag(name = "User",description = "유저 Domain")
@GetMapping("/users/login)
@Operation(summary ="로그인 API ", description = "클라이언트 요구사항 적기 " )
예시 :
@ApiResponses({
@ApiResponse(responseCode = "COMMON200",description = "OK, 성공"),
@ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@ApiResponse(responseCode = "AUTH004", description = "acess 토큰 만료",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@ApiResponse(responseCode = "AUTH006", description = "acess 토큰 모양이 이상함",content = @Content(schema = @Schema(implementation = ApiResponse.class)))})
예:
@Parameter(name = "userId", description = "유저의 아이디입니다.")
@Getter
@AllArgsConstructor
public static class ApiResponse {
@Schema(description = "성공")
private String success;
@Schema(description = "토큰")
private String token;
}