Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20210421] Spring Swagger API #104

Open
JuHyun419 opened this issue Apr 21, 2021 · 0 comments
Open

[20210421] Spring Swagger API #104

JuHyun419 opened this issue Apr 21, 2021 · 0 comments
Labels

Comments

@JuHyun419
Copy link
Owner

JuHyun419 commented Apr 21, 2021

Swagger API

// pom.xml
<dependency>
    <groupId>io.springfox</groupId>
    <version>2.9.2</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>


// Config
package com.github.oneline.onelinecourse.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Oneline-Course")
                .description("Hello world")
                .version("v1.0")
                .build();
    }

}


    // Controller
    @DeleteMapping("/{commentId}")
    @ApiOperation(value = "댓글 삭제")
    public ResponseEntity<Void> deleteComment(
            @PathVariable @ApiParam(value = "댓글 ID", example = "1") Long commentId) {
        commentService.deleteComment(commentId);
        return ResponseEntity.noContent()
                .build();
    }


    // Dto
    @ApiModelProperty(value = "PK", required = true)
    private Long id;

    @ApiModelProperty(value = "댓글 내용", required = true)
    private String content;

    @ApiModelProperty(value = "댓글 작성일시", required = true)
    private LocalDateTime createdAt;

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant