Skip to content

Commit 60c505f

Browse files
Fix PathMatcher Regression in springdoc#2031
1 parent 57fb0f6 commit 60c505f

File tree

4 files changed

+120
-1
lines changed

4 files changed

+120
-1
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/api/AbstractOpenApiResource.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ private PathItem buildPathItem(RequestMethod requestMethod, Operation operation,
10831083
Parameter parameter = paramIt.next();
10841084
if(ParameterIn.PATH.toString().equals(parameter.getIn())){
10851085
// check it's present in the path
1086-
if(!operationPath.contains("{" + parameter.getName() + "}"))
1086+
if(!StringUtils.containsAny(operationPath, "{" + parameter.getName() + "}", "{*" + parameter.getName() + "}"))
10871087
paramIt.remove();
10881088
}
10891089
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package test.org.springdoc.api.v30.app204;
2+
3+
import org.springdoc.core.customizers.GlobalOpenApiCustomizer;
4+
import org.springdoc.core.customizers.OpenApiCustomiser;
5+
import org.springframework.core.annotation.Order;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.PathVariable;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
import io.swagger.v3.oas.models.OpenAPI;
11+
import io.swagger.v3.oas.models.tags.Tag;
12+
13+
14+
public class OrderDemo {
15+
16+
@RestController
17+
public static class MyController {
18+
19+
@GetMapping("/test/{*param}")
20+
public String testingMethod(@PathVariable("param") String param) {
21+
return "foo";
22+
}
23+
}
24+
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2023 the original author or authors.
6+
* * * *
7+
* * * * Licensed under the Apache License, Version 2.0 (the "License");
8+
* * * * you may not use this file except in compliance with the License.
9+
* * * * You may obtain a copy of the License at
10+
* * * *
11+
* * * * https://www.apache.org/licenses/LICENSE-2.0
12+
* * * *
13+
* * * * Unless required by applicable law or agreed to in writing, software
14+
* * * * distributed under the License is distributed on an "AS IS" BASIS,
15+
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* * * * See the License for the specific language governing permissions and
17+
* * * * limitations under the License.
18+
* * *
19+
* *
20+
*
21+
*/
22+
23+
package test.org.springdoc.api.v30.app204;
24+
25+
import static org.hamcrest.Matchers.is;
26+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
27+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
28+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
29+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
30+
31+
import org.junit.jupiter.api.Test;
32+
import org.springdoc.core.Constants;
33+
import org.springframework.boot.autoconfigure.SpringBootApplication;
34+
import org.springframework.context.annotation.Import;
35+
import org.springframework.test.context.TestPropertySource;
36+
37+
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
38+
39+
/**
40+
* Fix regression in #2031
41+
*/
42+
@TestPropertySource(properties = { "springdoc.group-configs[0].group=mygroup", "springdoc.group-configs[0].paths-to-match=/test" })
43+
public class SpringDocApp204Test extends AbstractSpringDocV30Test {
44+
45+
@SpringBootApplication
46+
static class SpringDocTestApp {}
47+
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
"/test/{*param}": {
15+
"get": {
16+
"tags": [
17+
"my-controller"
18+
],
19+
"operationId": "testingMethod",
20+
"parameters": [
21+
{
22+
"name": "param",
23+
"in": "path",
24+
"required": true,
25+
"schema": {
26+
"type": "string"
27+
}
28+
}
29+
],
30+
"responses": {
31+
"200": {
32+
"description": "OK",
33+
"content": {
34+
"*/*": {
35+
"schema": {
36+
"type": "string"
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
}
44+
},
45+
"components": {}
46+
}

0 commit comments

Comments
 (0)