Skip to content

Commit 0f42129

Browse files
committed
changes merge
1 parent 1230add commit 0f42129

File tree

19 files changed

+259
-66
lines changed

19 files changed

+259
-66
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
6565
<nexus-staging-maven-plugin>1.6.8</nexus-staging-maven-plugin>
6666
<swagger-api.version>2.1.12</swagger-api.version>
67-
<swagger-ui.version>4.2.1</swagger-ui.version>
67+
<swagger-ui.version>4.4.1</swagger-ui.version>
6868
<classgraph.version>4.8.138</classgraph.version>
6969
<webjars-locator-core.version>0.48</webjars-locator-core.version>
7070
<gmavenplus-plugin.version>1.13.1</gmavenplus-plugin.version>

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/extractor/MethodParameterPojoExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private static Stream<MethodParameter> fromSimpleClass(Class<?> paramClass, Fiel
177177
.filter(d -> d.getName().equals(field.getName()))
178178
.map(PropertyDescriptor::getReadMethod)
179179
.filter(Objects::nonNull)
180-
.map(method -> new MethodParameter(method, -1))
180+
.map(method -> new MethodParameter(method, -1).withContainingClass(paramClass))
181181
.map(param -> new DelegatingMethodParameter(param, fieldNamePrefix + field.getName(), finalFieldAnnotations, true, isNotRequired));
182182
}
183183
catch (IntrospectionException e) {
@@ -249,4 +249,4 @@ public static void removeSimpleTypes(Class<?>... classes) {
249249
SIMPLE_TYPES.removeAll(Arrays.asList(classes));
250250
}
251251

252-
}
252+
}

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/OpenAPIService.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,17 @@ public Operation buildTags(HandlerMethod handlerMethod, Operation operation, Ope
339339
}
340340
}
341341

342-
if (!CollectionUtils.isEmpty(tagsStr))
343-
operation.setTags(new ArrayList<>(tagsStr));
342+
if (!CollectionUtils.isEmpty(tagsStr)) {
343+
if(CollectionUtils.isEmpty(operation.getTags()))
344+
operation.setTags(new ArrayList<>(tagsStr));
345+
else
346+
{
347+
Set<String> operationTagsSet = new HashSet<>(operation.getTags());
348+
operationTagsSet.addAll(tagsStr);
349+
operation.getTags().clear();
350+
operation.getTags().addAll(operationTagsSet);
351+
}
352+
}
344353

345354
if (isAutoTagClasses(operation))
346355
operation.addTagsItem(splitCamelCase(handlerMethod.getBeanType().getSimpleName()));

springdoc-openapi-starter-common/src/main/java/org/springdoc/ui/AbstractSwaggerIndexTransformer.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,20 @@ private String addParameter(String html, String key, String value) {
202202
protected String addCSRF(String html) {
203203
StringBuilder stringBuilder = new StringBuilder();
204204
stringBuilder.append("requestInterceptor: (request) => {\n");
205-
stringBuilder.append("const value = `; ${document.cookie}`;\n");
206-
stringBuilder.append("const parts = value.split(`; ");
205+
stringBuilder.append("\t\t\tconst value = `; ${document.cookie}`;\n");
206+
stringBuilder.append("\t\t\tconst parts = value.split(`; ");
207207
stringBuilder.append(swaggerUiConfig.getCsrf().getCookieName());
208208
stringBuilder.append("=`);\n");
209-
stringBuilder.append("if (parts.length === 2)\n");
209+
stringBuilder.append("\t\t\tconst currentURL = new URL(document.URL);\n");
210+
stringBuilder.append("\t\t\tconst requestURL = new URL(request.url, document.location.origin);\n");
211+
stringBuilder.append("\t\t\tconst isSameOrigin = (currentURL.protocol === requestURL.protocol && currentURL.host === requestURL.host);\n");
212+
stringBuilder.append("\t\t\tif (isSameOrigin && parts.length === 2) ");
210213
stringBuilder.append("request.headers['");
211214
stringBuilder.append(swaggerUiConfig.getCsrf().getHeaderName());
212215
stringBuilder.append("'] = parts.pop().split(';').shift();\n");
213-
stringBuilder.append("return request;\n");
214-
stringBuilder.append("},\n");
215-
stringBuilder.append(PRESETS);
216+
stringBuilder.append("\t\t\treturn request;\n");
217+
stringBuilder.append("\t\t},\n");
218+
stringBuilder.append("\t\t" + PRESETS);
216219
return html.replace(PRESETS, stringBuilder.toString());
217220
}
218221

@@ -225,14 +228,18 @@ protected String addCSRF(String html) {
225228
protected String addCSRFLocalStorage(String html) {
226229
StringBuilder stringBuilder = new StringBuilder();
227230
stringBuilder.append("requestInterceptor: (request) => {\n");
228-
stringBuilder.append("const value = window.localStorage.getItem('");
231+
stringBuilder.append("t\t\tconst value = window.localStorage.getItem('");
229232
stringBuilder.append(swaggerUiConfig.getCsrf().getLocalStorageKey() + "');\n");
233+
stringBuilder.append("t\t\tconst currentURL = new URL(document.URL);\n");
234+
stringBuilder.append("t\t\tconst requestURL = new URL(request.url, document.location.origin);\n");
235+
stringBuilder.append("t\t\tconst isSameOrigin = (currentURL.protocol === requestURL.protocol && currentURL.host === requestURL.host);\n");
236+
stringBuilder.append("t\t\tif (isSameOrigin) ");
230237
stringBuilder.append("request.headers['");
231238
stringBuilder.append(swaggerUiConfig.getCsrf().getHeaderName());
232239
stringBuilder.append("'] = value;\n");
233-
stringBuilder.append("return request;\n");
234-
stringBuilder.append("},\n");
235-
stringBuilder.append(PRESETS);
240+
stringBuilder.append("t\t\treturn request;\n");
241+
stringBuilder.append("\t\t},\n");
242+
stringBuilder.append("\t\t" + PRESETS);
236243
return html.replace(PRESETS, stringBuilder.toString());
237244
}
238245

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/AbstractCommonTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.nio.file.Files;
55
import java.nio.file.Path;
66
import java.nio.file.Paths;
7+
import java.util.List;
78

89
import org.slf4j.Logger;
910
import org.slf4j.LoggerFactory;
@@ -25,8 +26,12 @@ public abstract class AbstractCommonTest {
2526
protected String getContent(String fileName) {
2627
try {
2728
Path path = Paths.get(AbstractCommonTest.class.getClassLoader().getResource(fileName).toURI());
28-
byte[] fileBytes = Files.readAllBytes(path);
29-
return new String(fileBytes, StandardCharsets.UTF_8);
29+
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
30+
StringBuilder sb = new StringBuilder();
31+
for (String line : lines) {
32+
sb.append(line).append("\n");
33+
}
34+
return sb.toString();
3035
}
3136
catch (Exception e) {
3237
throw new RuntimeException("Failed to read file: " + fileName, e);

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/AbstractSpringDocTest.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818

1919
package test.org.springdoc.ui;
2020

21-
import java.nio.charset.StandardCharsets;
22-
import java.nio.file.Files;
23-
import java.nio.file.Path;
24-
import java.nio.file.Paths;
25-
2621
import org.springdoc.core.configuration.SpringDocConfiguration;
2722
import org.springdoc.core.properties.SpringDocConfigProperties;
2823
import org.springdoc.core.properties.SwaggerUiConfigParameters;
@@ -51,26 +46,18 @@ public abstract class AbstractSpringDocTest extends AbstractCommonTest {
5146

5247
private static final String DEFAULT_SWAGGER_UI_URL= Constants.DEFAULT_WEB_JARS_PREFIX_URL + Constants.SWAGGER_UI_URL;
5348

54-
protected String getContent(String fileName) {
55-
try {
56-
Path path = Paths.get(AbstractSpringDocTest.class.getClassLoader().getResource(fileName).toURI());
57-
byte[] fileBytes = Files.readAllBytes(path);
58-
return new String(fileBytes, StandardCharsets.UTF_8);
59-
}
60-
catch (Exception e) {
61-
throw new RuntimeException("Failed to read file: " + fileName, e);
62-
}
63-
}
64-
6549
protected void checkHTML(String fileName, String uri) {
6650
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri(uri)
6751
.exchange()
6852
.expectStatus().isOk()
6953
.expectBody().returnResult();
70-
String result = new String(getResult.getResponseBody());
54+
checkHTMLResult(fileName, new String(getResult.getResponseBody()));
55+
}
56+
57+
protected void checkHTMLResult(String fileName, String result) {
7158
assertTrue(result.contains("Swagger UI"));
7259
String expected = getContent("results/" + fileName);
73-
assertEquals(expected, result);
60+
assertEquals(expected, result.replace("\r", ""));
7461
}
7562

7663
protected void checkHTML(String fileName) {

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app6/SpringDocApp6Test.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ public void transformed_index_with_oauth() throws Exception {
4242
.exchange()
4343
.expectStatus().isOk()
4444
.expectBody().returnResult();
45-
String result = new String(getResult.getResponseBody());
46-
assertTrue(result.contains("Swagger UI"));
47-
String expected = getContent("results/index6");
48-
assertEquals(expected, result);
45+
checkHTMLResult("index6", new String(getResult.getResponseBody()));
4946
}
5047

5148
@SpringBootApplication

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app7/SpringDocApp7Test.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ public void transformed_index_with_oauth() throws Exception {
4242
.exchange()
4343
.expectStatus().isOk()
4444
.expectBody().returnResult();
45-
String result = new String(getResult.getResponseBody());
46-
assertTrue(result.contains("Swagger UI"));
47-
String expected = getContent("results/index7");
48-
assertEquals(expected, result);
45+
checkHTMLResult("index7", new String(getResult.getResponseBody()));
4946
}
5047

5148
@SpringBootApplication
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package test.org.springdoc.api.app181;
2+
3+
import io.swagger.v3.oas.annotations.Parameter;
4+
import io.swagger.v3.oas.annotations.media.Schema;
5+
6+
public class AbstractParameterObject<T> {
7+
8+
int primitiveBaseField;
9+
10+
T genericField;
11+
12+
public int getPrimitiveBaseField() {
13+
return primitiveBaseField;
14+
}
15+
16+
public void setPrimitiveBaseField(int primitiveBaseField) {
17+
this.primitiveBaseField = primitiveBaseField;
18+
}
19+
20+
public T getGenericField() {
21+
return genericField;
22+
}
23+
24+
public void setGenericField(T genericField) {
25+
this.genericField = genericField;
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package test.org.springdoc.api.app181;
2+
3+
public class ConcreteParameterObject extends AbstractParameterObject<String> {
4+
5+
int primitiveConcreteField;
6+
7+
public int getPrimitiveConcreteField() {
8+
return primitiveConcreteField;
9+
}
10+
11+
public void setPrimitiveConcreteField(int primitiveConcreteField) {
12+
this.primitiveConcreteField = primitiveConcreteField;
13+
}
14+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app181;
20+
21+
22+
import org.springdoc.core.annotations.ParameterObject;
23+
24+
import org.springframework.http.HttpStatus;
25+
import org.springframework.http.ResponseEntity;
26+
import org.springframework.web.bind.annotation.GetMapping;
27+
import org.springframework.web.bind.annotation.RestController;
28+
29+
@RestController
30+
public class HelloController {
31+
32+
@GetMapping( "/test1")
33+
public ResponseEntity<String> sayHello( @ParameterObject final ConcreteParameterObject test) {
34+
System.out.println("Field B = " + test);
35+
return new ResponseEntity<String>("{\"Say\": \"Hello\"}", HttpStatus.OK);
36+
}
37+
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app181;
20+
21+
22+
import test.org.springdoc.api.AbstractSpringDocTest;
23+
24+
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
26+
/**
27+
* Tests Spring meta-annotations as method parameters
28+
*/
29+
public class SpringDocApp181Test extends AbstractSpringDocTest {
30+
31+
@SpringBootApplication
32+
static class SpringDocTestApp {}
33+
34+
}

springdoc-openapi-starter-webmvc-api/src/test/resources/results/app1.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@
327327
"/inventory": {
328328
"get": {
329329
"tags": [
330+
"developers",
330331
"inventory"
331332
],
332333
"summary": "By passing in the appropriate options, you can search for available inventory in the system ",
@@ -407,7 +408,8 @@
407408
},
408409
"post": {
409410
"tags": [
410-
"inventory"
411+
"inventory",
412+
"admins"
411413
],
412414
"summary": "Adds an item to the system",
413415
"description": "adds an inventory item",
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/test1": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "sayHello",
20+
"parameters": [
21+
{
22+
"name": "primitiveConcreteField",
23+
"in": "query",
24+
"required": false,
25+
"schema": {
26+
"type": "integer",
27+
"format": "int32"
28+
}
29+
},
30+
{
31+
"name": "primitiveBaseField",
32+
"in": "query",
33+
"required": false,
34+
"schema": {
35+
"type": "integer",
36+
"format": "int32"
37+
}
38+
},
39+
{
40+
"name": "genericField",
41+
"in": "query",
42+
"required": false,
43+
"schema": {
44+
"type": "string"
45+
}
46+
}
47+
],
48+
"responses": {
49+
"200": {
50+
"description": "OK",
51+
"content": {
52+
"*/*": {
53+
"schema": {
54+
"type": "string"
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}
61+
}
62+
},
63+
"components": {}
64+
}

0 commit comments

Comments
 (0)