Skip to content

Commit 1637f26

Browse files
committedMar 26, 2025
Customize Servers via application.yml. Fixes #2948
1 parent fddbf9e commit 1637f26

File tree

13 files changed

+75
-32
lines changed

13 files changed

+75
-32
lines changed
 

‎springdoc-openapi-starter-common/src/main/java/org/springdoc/core/customizers/SpecPropertiesCustomizer.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
package org.springdoc.core.customizers;
2828

29+
import java.util.ArrayList;
2930
import java.util.List;
3031
import java.util.Map;
3132
import java.util.function.Consumer;
@@ -144,6 +145,9 @@ private void customizeOpenApi(OpenAPI openApi, OpenAPI openApiProperties) {
144145
if (!CollectionUtils.isEmpty(securityRequirementsProperties)) {
145146
customizeSecurity(openApi, securityRequirementsProperties);
146147
}
148+
if (!CollectionUtils.isEmpty(openApiProperties.getServers())) {
149+
openApi.setServers(new ArrayList<>(openApiProperties.getServers()));
150+
}
147151
}
148152
}
149153

@@ -364,5 +368,4 @@ private void resolveSet(Consumer<List> setter, Supplier<List> getter) {
364368
}
365369
}
366370

367-
368371
}

‎springdoc-openapi-starter-webmvc-api/src/test/resources/application-212.yml

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
springdoc:
22
open-api:
3+
servers:
4+
- url: "https://api.example.com"
5+
description: "Production Server"
6+
- url: "https://staging.example.com"
7+
description: "Staging Server"
38
info:
49
title: Api info title
510
description: Api info description

‎springdoc-openapi-starter-webmvc-api/src/test/resources/application-217.yml

+12-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ springdoc:
1313
termsOfService: http://localhost:8080/
1414
license:
1515
name: Apache 2.0
16+
servers:
17+
- url: "https://demo.example.com"
18+
description: "demo Server"
1619
components:
1720
schemas:
1821
PersonDTO:
@@ -34,6 +37,9 @@ springdoc:
3437
termsOfService: http://localhost:8080/
3538
license:
3639
name: Apache 2.0
40+
servers:
41+
- url: "https://user.example.com"
42+
description: "user Server"
3743
components:
3844
schemas:
3945
PersonDTO:
@@ -42,7 +48,12 @@ springdoc:
4248
name:
4349
description: Description for 'name' property
4450
example: Example value for 'name' property
45-
open-api:
51+
open-api:
52+
servers:
53+
- url: "https://api.example.com"
54+
description: "Production Server"
55+
- url: "https://staging.example.com"
56+
description: "Staging Server"
4657
info:
4758
title: Api info title
4859
description: Api info description

‎springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app212-grouped.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
},
88
"servers": [
99
{
10-
"url": "http://localhost",
11-
"description": "Generated server url"
10+
"url": "https://api.example.com",
11+
"description": "Production Server"
12+
},
13+
{
14+
"url": "https://staging.example.com",
15+
"description": "Staging Server"
1216
}
1317
],
1418
"security": [

‎springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app212.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
},
88
"servers": [
99
{
10-
"url": "http://localhost",
11-
"description": "Generated server url"
10+
"url": "https://api.example.com",
11+
"description": "Production Server"
12+
},
13+
{
14+
"url": "https://staging.example.com",
15+
"description": "Staging Server"
1216
}
1317
],
1418
"security": [

‎springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app217-1.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
},
1212
"servers": [
1313
{
14-
"url": "http://localhost",
15-
"description": "Generated server url"
14+
"url": "https://demo.example.com",
15+
"description": "demo Server"
1616
}
1717
],
1818
"paths": {

‎springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app217-2.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
},
1212
"servers": [
1313
{
14-
"url": "http://localhost",
15-
"description": "Generated server url"
14+
"url": "https://user.example.com",
15+
"description": "user Server"
1616
}
1717
],
1818
"paths": {

‎springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app217.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
},
88
"servers": [
99
{
10-
"url": "http://localhost",
11-
"description": "Generated server url"
10+
"url": "https://api.example.com",
11+
"description": "Production Server"
12+
},
13+
{
14+
"url": "https://staging.example.com",
15+
"description": "Staging Server"
1216
}
1317
],
1418
"paths": {

‎springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app212-grouped.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
},
88
"servers": [
99
{
10-
"url": "http://localhost",
11-
"description": "Generated server url"
10+
"url": "https://api.example.com",
11+
"description": "Production Server"
12+
},
13+
{
14+
"url": "https://staging.example.com",
15+
"description": "Staging Server"
1216
}
1317
],
1418
"security": [
@@ -106,14 +110,14 @@
106110
"schemas": {
107111
"PersonDTO": {
108112
"type": "object",
113+
"description": "Description for PersonDTO component in ApiGroupName",
109114
"properties": {
110115
"name": {
111116
"type": "string",
112117
"description": "Description for 'name' property in ApiGroupName",
113118
"example": "Example value for 'name' property in ApiGroupName"
114119
}
115-
},
116-
"description": "Description for PersonDTO component in ApiGroupName"
120+
}
117121
}
118122
},
119123
"securitySchemes": {

‎springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app212.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
},
88
"servers": [
99
{
10-
"url": "http://localhost",
11-
"description": "Generated server url"
10+
"url": "https://api.example.com",
11+
"description": "Production Server"
12+
},
13+
{
14+
"url": "https://staging.example.com",
15+
"description": "Staging Server"
1216
}
1317
],
1418
"security": [
@@ -104,14 +108,14 @@
104108
"schemas": {
105109
"PersonDTO": {
106110
"type": "object",
111+
"description": "Description for PersonDTO component",
107112
"properties": {
108113
"name": {
109114
"type": "string",
110115
"description": "Description for 'name' property",
111116
"example": "Example value for 'name' property"
112117
}
113-
},
114-
"description": "Description for PersonDTO component"
118+
}
115119
}
116120
},
117121
"securitySchemes": {

‎springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app217-1.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
},
1212
"servers": [
1313
{
14-
"url": "http://localhost",
15-
"description": "Generated server url"
14+
"url": "https://demo.example.com",
15+
"description": "demo Server"
1616
}
1717
],
1818
"paths": {
@@ -41,14 +41,14 @@
4141
"schemas": {
4242
"PersonDTO": {
4343
"type": "object",
44+
"description": "Description for PersonDTO component",
4445
"properties": {
4546
"name": {
4647
"type": "string",
4748
"description": "Description for 'name' property",
4849
"example": "Example value for 'name' property"
4950
}
50-
},
51-
"description": "Description for PersonDTO component"
51+
}
5252
}
5353
}
5454
}

‎springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app217-2.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
},
1212
"servers": [
1313
{
14-
"url": "http://localhost",
15-
"description": "Generated server url"
14+
"url": "https://user.example.com",
15+
"description": "user Server"
1616
}
1717
],
1818
"paths": {
@@ -41,14 +41,14 @@
4141
"schemas": {
4242
"PersonDTO": {
4343
"type": "object",
44+
"description": "Description for PersonDTO component",
4445
"properties": {
4546
"name": {
4647
"type": "string",
4748
"description": "Description for 'name' property",
4849
"example": "Example value for 'name' property"
4950
}
50-
},
51-
"description": "Description for PersonDTO component"
51+
}
5252
}
5353
}
5454
}

‎springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app217.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
},
88
"servers": [
99
{
10-
"url": "http://localhost",
11-
"description": "Generated server url"
10+
"url": "https://api.example.com",
11+
"description": "Production Server"
12+
},
13+
{
14+
"url": "https://staging.example.com",
15+
"description": "Staging Server"
1216
}
1317
],
1418
"paths": {
@@ -37,14 +41,14 @@
3741
"schemas": {
3842
"PersonDTO": {
3943
"type": "object",
44+
"description": "Description for PersonDTO component",
4045
"properties": {
4146
"name": {
4247
"type": "string",
4348
"description": "Description for 'name' property",
4449
"example": "Example value for 'name' property"
4550
}
46-
},
47-
"description": "Description for PersonDTO component"
51+
}
4852
}
4953
}
5054
}

0 commit comments

Comments
 (0)
Failed to load comments.