Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.

Commit 7714bda

Browse files
authored
Merge pull request swagger-api#977 from fujigon/feature/validation-recognize-ref
fix bug of validation failure when path parameter contains ref
2 parents a4d65b4 + d7042a4 commit 7714bda

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ private boolean isPathParamDefined(String pathParam, List<Parameter> parameters)
560560
return false;
561561
} else {
562562
Parameter pathParamDefined = parameters.stream()
563-
.filter(parameter -> pathParam.equals(parameter.getName()) && "path".equals(parameter.getIn()))
563+
.filter(parameter -> (parameter.get$ref() != null) || (pathParam.equals(parameter.getName()) && "path".equals(parameter.getIn())))
564564
.findFirst()
565565
.orElse(null);
566566
if (pathParamDefined == null) {

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import io.swagger.v3.parser.core.models.SwaggerParseResult;
3838
import mockit.Injectable;
3939
import org.apache.commons.io.FileUtils;
40+
import org.hamcrest.CoreMatchers;
4041
import org.testng.Assert;
4142
import org.testng.annotations.AfterClass;
4243
import org.testng.annotations.BeforeClass;
@@ -51,6 +52,7 @@
5152
import java.util.*;
5253

5354
import static com.github.tomakehurst.wiremock.client.WireMock.*;
55+
import static org.junit.Assert.assertThat;
5456
import static org.testng.Assert.*;
5557

5658

@@ -70,7 +72,7 @@ public void testIssueIntegerDefault() {
7072
Assert.assertNull ( openAPI.getPaths().get("/issue-125").getGet().getResponses().get("200").getContent().get("*/*").getSchema().getFormat());
7173
Assert.assertNull (openAPI.getPaths().get("/primitiveBody/binary").getPost().getRequestBody().getContent().get("application/octet-stream").getSchema().getFormat());
7274
}
73-
75+
7476
@Test
7577
public void testIssue983() {
7678
OpenAPIV3Parser parser = new OpenAPIV3Parser();
@@ -81,7 +83,7 @@ public void testIssue983() {
8183
Yaml.prettyPrint(openAPI);
8284
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("InventoryId"));
8385
}
84-
86+
8587
@Test
8688
public void testIssue913() {
8789
OpenAPIV3Parser parser = new OpenAPIV3Parser();
@@ -162,7 +164,7 @@ public void testIssue837() {
162164
Assert.assertEquals(examples.get("local").get$ref(), "#/components/examples/LocalRef");
163165
Assert.assertEquals(examples.get("external").get$ref(), "#/components/examples/ExternalRef");
164166
}
165-
167+
166168
@Test
167169
public void testIssue834() {
168170
ParseOptions options = new ParseOptions();
@@ -1755,6 +1757,14 @@ public void testIssue975_allOf() {
17551757
assertEquals(composed.getAllOf().get(0).get$ref(), "#/components/schemas/Image");
17561758
}
17571759

1760+
@Test
1761+
public void testValidationIssue() {
1762+
ParseOptions parseOptions = new ParseOptions();
1763+
parseOptions.setResolveFully(true);
1764+
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("src/test/resources/validation/path-parameter-validation.yaml", null, parseOptions);
1765+
assertThat(result.getMessages().size(), CoreMatchers.is(0));
1766+
}
1767+
17581768
private static int getDynamicPort() {
17591769
return new Random().ints(10000, 20000).findFirst().getAsInt();
17601770
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Sample APIs
4+
version: 1.0.0
5+
description:
6+
Sample API
7+
8+
components:
9+
parameters:
10+
accountId:
11+
name: accountId
12+
schema:
13+
type: string
14+
in: path
15+
required: true
16+
17+
paths:
18+
/users/{accountId}:
19+
get:
20+
operationId: ReadUser
21+
parameters:
22+
- $ref: '#/components/parameters/accountId'
23+
responses:
24+
'200':
25+
description: 200 response

0 commit comments

Comments
 (0)