-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Swagger 서버 목록 로컬/AWS 동시 노출 #158
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,23 +6,19 @@ | |
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.Primary; | ||
| import org.springframework.core.env.Environment; | ||
| import org.springframework.core.env.Profiles; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| import io.swagger.v3.oas.models.Components; | ||
| import io.swagger.v3.oas.models.OpenAPI; | ||
| import io.swagger.v3.oas.models.info.Info; | ||
| import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
| import io.swagger.v3.oas.models.security.SecurityScheme; | ||
| import io.swagger.v3.oas.models.servers.Server; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Configuration | ||
| @RequiredArgsConstructor | ||
| public class SwaggerConfig { | ||
|
|
||
| private final Environment env; | ||
|
|
||
| @Bean | ||
| public OpenAPI openAPI() { | ||
|
|
||
|
|
@@ -36,14 +32,13 @@ public OpenAPI openAPI() { | |
| SecurityRequirement securityRequirement = new SecurityRequirement() | ||
| .addList("accessTokenAuth"); | ||
|
|
||
| Server server = new Server(); | ||
| if (env.acceptsProfiles(Profiles.of("prod"))) { | ||
| server.setUrl("https://docgrid.com"); | ||
| server.setDescription("운영 서버"); | ||
| } else { | ||
| server.setUrl("http://localhost:8080"); | ||
| server.setDescription("로컬 서버"); | ||
| } | ||
| Server localServer = new Server() | ||
| .url("http://localhost:8080") | ||
| .description("로컬 서버"); | ||
|
|
||
| Server awsServer = new Server() | ||
| .url("http://52.79.212.118:8080") | ||
| .description("운영 서버 (AWS)"); | ||
|
|
||
| return new OpenAPI() | ||
| .info(new Info() | ||
|
|
@@ -53,7 +48,7 @@ public OpenAPI openAPI() { | |
| .components(new Components() | ||
| .addSecuritySchemes("accessTokenAuth", accessTokenAuth)) | ||
| .addSecurityItem(securityRequirement) | ||
| .servers(List.of(server)); | ||
| .servers(List.of(localServer, awsServer)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
base_url="${BASE_URL:?배포된 Swagger 호스트를 BASE_URL로 설정하세요}"
curl -fsS "${base_url%/}/v3/api-docs" | jq '.servers'Repository: DocGrid/backend Length of output: 210 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
printf '%s\n' '--- SwaggerConfig outline ---'
ast-grep outline src/main/java/com/opensource/docgrid/global/config/SwaggerConfig.java --view expanded || true
printf '%s\n' '--- SwaggerConfig ---'
cat -n src/main/java/com/opensource/docgrid/global/config/SwaggerConfig.java
printf '%s\n' '--- springdoc and server configuration references ---'
rg -n -i --glob '!target/**' --glob '!build/**' \
'springdoc|swagger-ui|api-docs|Server\(|servers\(|localhost:8080|awsServer|localServer' .
printf '%s\n' '--- relevant configuration and guidance files ---'
fd -HI '^(AGENTS\.md|code_style\.md|security\.md|application.*\.(yml|yaml|properties))$|^\.Codex$' . \
| sortRepository: DocGrid/backend Length of output: 6073 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
printf '%s\n' '--- project guidance ---'
for f in AGENTS.md .claude/rules/security.md; do
if [ -f "$f" ]; then
printf '\n### %s\n' "$f"
cat -n "$f"
fi
done
printf '%s\n' '--- application configuration ---'
for f in src/main/resources/application.yml \
src/main/resources/application-local.yml \
src/main/resources/application-prod.yml \
src/main/resources/application-test.yml; do
if [ -f "$f" ]; then
printf '\n### %s\n' "$f"
cat -n "$f"
fi
done
printf '%s\n' '--- tests and docs that inspect OpenAPI servers ---'
rg -n -i --glob 'src/test/**' --glob 'docs/**' \
'servers|localhost:8080|52\.79\.212\.118|swaggerUiConfigProperties|springdoc' . || true
printf '%s\n' '--- repository diff summary ---'
git diff --statRepository: DocGrid/backend Length of output: 12955 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
import re
path = Path("src/main/java/com/opensource/docgrid/global/config/SwaggerConfig.java")
text = path.read_text()
servers_call = re.search(r"\.servers\(List\.of\(([^)]*)\)\)", text)
if not servers_call:
raise SystemExit("OpenAPI servers list not found")
servers = [name.strip() for name in servers_call.group(1).split(",")]
urls = dict(re.findall(r"Server\s+(\w+)\s*=\s*new Server\(\)\s*\.url\(\"([^\"]+)\"\)", text))
print("servers_order:", servers)
print("server_urls:", urls)
print("default_server_name:", servers[0])
print("default_server_url:", urls.get(servers[0], "<unresolved>"))
config_text = "\n".join(
p.read_text()
for p in Path("src/main/resources").glob("application*.y*ml")
)
print("springdoc_server_override:", bool(re.search(r"springdoc:.*(?:server|url)", config_text, re.S)))
print("swagger_ui_properties_server_override:",
bool(re.search(r"set(?:Server|Url)\s*\(", text)))
PYRepository: DocGrid/backend Length of output: 446 🌐 Web query:
💡 Result: In the OpenAPI Specification (OAS), the servers array defines the base URLs for an API [1][2]. According to the official specification, if the servers property is not provided or is an empty array, the default value is a Server Object with a URL value of / [3][4][5]. Regarding Swagger UI, when a list of multiple servers is provided in the servers array, Swagger UI defaults to selecting the first server in that list for its Try It Out functionality [6][7]. Because this is the established behavior, it is a common practice to order the servers array so that the most relevant or preferred server (e.g., a production or development host) appears first [6]. If you rely on the implicit default of / by omitting the servers array, Swagger UI interprets this relative URL as being relative to the location where the OpenAPI document itself is being served [8][1]. Citations:
AWS Swagger UI의 기본 서버를 배포 환경에 맞게 설정하세요.
🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| @Bean | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: DocGrid/backend
Length of output: 50374
🏁 Script executed:
Repository: DocGrid/backend
Length of output: 36358
운영 Swagger 서버에 HTTPS 외부 주소를 사용하세요.
awsServer가 공개http://52.79.212.118:8080주소를 사용합니다. Swagger UI의 Bearer JWT가 이 주소로 전송되면 네트워크에서 노출될 수 있습니다.TLS 프록시가 있으면 프록시의
https://외부 주소를SwaggerConfig.java와CorsConfig.java의 운영 설정에 사용하세요. TLS가 없는 주소는운영 서버 (AWS)로 등록하지 마세요.🤖 Prompt for AI Agents