Post

πŸ’₯ Swagger 클래슀λͺ… 쀑볡

πŸ’₯ Swagger 클래슀λͺ… 쀑볡

문제 상황

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* NoticeRequestDto$CREATE */
@Schema(description = "곡지사항 μš”μ²­ DTO")
class NoticeRequestDto {
	@Schema(description = "곡지사항 등둝 μš”μ²­")
	class CREATE (
		@Schema(description = "제λͺ©")
		val title: String,
		
		@Schema(description = "λ‚΄μš©")
		val content: String,
		
		@Schema(description = "μž‘μ„±μž 이메일")
		val writerEmail: String
	)
}

/*Β InquiryRequestDto$CREATE */
@Schema(description = "문의 μš”μ²­ DTO")
class InquiryRequestDto {
	@Schema(description = "문의 등둝 μš”μ²­")
	class CREATE (
		@Schema(description = "제λͺ©")
		val title: String,
		
		@Schema(description = "λ‚΄μš©")
		val content: String,
		
		@Schema(description = "μž‘μ„±μž 이메일")
		val writerEmail: String,
		
		@Schema(description = "μž‘μ„±μž μ „ν™”λ²ˆν˜Έ")
		val writerPhoneNumber: String? = null
	)
}
  • Swagger UIμ—μ„œ 곡지사항 μš”μ²­ DTOκ°€ InquiryRequestDto$CREATE와 잘λͺ» λ§€ν•‘ λ˜μ—ˆλ‹€.

문제 원인

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
NoticeRequestDto.class
β”œβ”€β”€ CREATE.class
β”œβ”€β”€ READ.class
β”œβ”€β”€ UPDATE.class
└── DELETE.class

InquiryRequestDto.class
β”œβ”€β”€ CREATE.class
β”œβ”€β”€ READ.class
β”œβ”€β”€ UPDATE.class
└── DELETE.class

UserRequestDto.class
β”œβ”€β”€ CREATE.class
β”œβ”€β”€ READ.class
β”œβ”€β”€ UPDATE.class
└── DELETE.class
  • ν•„μžμ˜ μš”μ²­ DTO ꡬ쑰인데, Swaggerμ—μ„œλŠ” νŒ¨ν‚€μ§€ μ •λ³΄λŠ” κ΄€λ¦¬ν•˜μ§€ μ•ŠκΈ° λ•Œλ¬Έμ— Nested Class λͺ…이 쀑볡될 경우 맀핑이 μ œλŒ€λ‘œ λ˜μ§€ μ•ŠλŠ”λ‹€κ³  ν•œλ‹€.

ν•΄κ²° 방법

βœ… @Schema μ„ μ–Έ μ‹œ name μ§€μ •

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@Schema(
	name = "createNoticeDto",
	description = "곡지사항 등둝 μš”μ²­"
)
class CREATE (
	@Schema(description = "제λͺ©")
	val title: String,
	
	@Schema(description = "λ‚΄μš©")
	val content: String,
	
	@Schema(description = "μž‘μ„±μž 이메일")
	val writerEmail: String
)
  • name 값은 λ‹€λ₯Έ ν΄λž˜μŠ€μ™€ 겹치면 μ•ˆ λœλ‹€.Β 

βœ… application.properties μ„€μ •

1
springdoc.use-fqn=true
  • 클래슀λ₯Ό νŒ¨ν‚€μ§€λ‘œ κ΅¬λΆ„ν•˜λ„λ‘ ν•˜λŠ” 섀정이라고 ν•œλ‹€.

회고

  • 아직은 Nested Class 기반의 μš”μ²­ DTO ꡬ쑰가 가독성 μΈ‘λ©΄μ—μ„œ μ’‹λ‹€κ³  μƒκ°ν•˜κ³  μžˆλŠ”λ°, λ‹€λ₯Έ λ°©ν–₯도 생각해봐야겠닀고 λŠκΌˆλ‹€.
This post is licensed under CC BY 4.0 by the author.