Skip to content

Commit b9c5286

Browse files
committed
Merge branch 'master' of https://github.com/swagger-api/swagger-parser into parser-resolving-duplicated-path
2 parents cdd5251 + 8d5b569 commit b9c5286

File tree

6 files changed

+172
-28
lines changed

6 files changed

+172
-28
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ updates:
55
directory: "/"
66
schedule:
77
interval: "daily"
8-
allow:
9-
- dependency-name: "io.swagger.core.v3:*"
10-
- dependency-name: "io.swagger:*"
8+
ignore:
9+
- dependency-name: "*"
10+
update-types: ["version-update:semver-major"]
1111
- package-ecosystem: "maven"
1212
target-branch: "v1"
1313
directory: "/"
1414
schedule:
1515
interval: "daily"
16-
allow:
17-
- dependency-name: "io.swagger.core.v3:*"
18-
- dependency-name: "io.swagger:*"
16+
ignore:
17+
- dependency-name: "*"
18+
update-types: ["version-update:semver-major"]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: 'Dependency Review'
2+
on: [pull_request]
3+
4+
permissions:
5+
contents: read
6+
7+
jobs:
8+
dependency-review:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: 'Checkout Repository'
12+
uses: actions/checkout@v4
13+
- name: Dependency Review
14+
uses: actions/dependency-review-action@v3
15+
with:
16+
fail-on-severity: high

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4155,10 +4155,9 @@ public Schema getJsonSchema(JsonNode jsonNode, String location, ParseResult resu
41554155
schema.setPatternProperties(patternProperties);
41564156
}
41574157

4158-
//const is a String
4159-
value = getString("const", node, false, location, result);
4160-
if (value != null) {
4161-
schema.setConst(value);
4158+
Object constValue = getAnyType("const", node, location, result);
4159+
if (constValue != null) {
4160+
schema.setConst(constValue);
41624161
}
41634162

41644163
value = getString("contentEncoding", node, false, location, result);

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

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package io.swagger.v3.parser.test;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.databind.node.ArrayNode;
5+
import com.fasterxml.jackson.databind.node.NullNode;
6+
import com.fasterxml.jackson.databind.node.ObjectNode;
37
import io.swagger.v3.oas.models.OpenAPI;
48
import io.swagger.v3.oas.models.media.Schema;
59
import io.swagger.v3.oas.models.security.SecurityRequirement;
@@ -8,6 +12,7 @@
812
import io.swagger.v3.parser.core.models.SwaggerParseResult;
913
import org.testng.annotations.Test;
1014

15+
import java.math.BigDecimal;
1116
import java.util.Arrays;
1217
import java.util.Collections;
1318
import java.util.List;
@@ -56,6 +61,46 @@ public void testSchemaKeysOAS31() {
5661
assertTrue(patternProperties.getTypes().contains("string"));
5762
}
5863

64+
@Test(description = "Test OAS31 Schema const deserialization")
65+
public void testSchemaConstOAS31() {
66+
SwaggerParseResult result = new OpenAPIV3Parser().readLocation( "3.1.0/issue-1975.yaml", null, null);
67+
assertNotNull(result.getOpenAPI());
68+
OpenAPI openAPI = result.getOpenAPI();
69+
70+
assertTrue(result.getMessages().size() == 0);
71+
assertEquals(openAPI.getComponents().getSchemas().get("ConstValidation").getConst(), 2);
72+
ObjectMapper mapper = new ObjectMapper();
73+
ObjectNode objNode = mapper.createObjectNode();
74+
objNode.put("foo", "bar");
75+
objNode.put("baz", "bax");
76+
assertEquals(openAPI.getComponents().getSchemas().get("ConstWithObject").getConst(), objNode);
77+
ArrayNode arrayNode = mapper.createArrayNode();
78+
ObjectNode arrayItem = mapper.createObjectNode();
79+
arrayItem.put("foo", "bar");
80+
arrayNode.add(arrayItem);
81+
assertEquals(openAPI.getComponents().getSchemas().get("ConstWithArray").getConst(), arrayNode);
82+
assertEquals(openAPI.getComponents().getSchemas().get("ConstWithNull").getConst(), NullNode.getInstance());
83+
assertEquals(openAPI.getComponents().getSchemas().get("ConstWithFalseDoesNotMatch0").getConst(), false);
84+
assertEquals(openAPI.getComponents().getSchemas().get("ConstWithTrueDoesNotMatch1").getConst(), true);
85+
arrayNode = mapper.createArrayNode();
86+
arrayNode.add(false);
87+
assertEquals(openAPI.getComponents().getSchemas().get("ConstWithArrayFalseDoesNotMatch0").getConst(), arrayNode);
88+
arrayNode = mapper.createArrayNode();
89+
arrayNode.add(true);
90+
assertEquals(openAPI.getComponents().getSchemas().get("ConstWithArrayTrueDoesNotMatch1").getConst(), arrayNode);
91+
objNode = mapper.createObjectNode();
92+
objNode.put("a", false);
93+
assertEquals(openAPI.getComponents().getSchemas().get("ConstWithAFalseDoesNotMatchA0").getConst(), objNode);
94+
objNode = mapper.createObjectNode();
95+
objNode.put("a", true);
96+
assertEquals(openAPI.getComponents().getSchemas().get("ConstWithATrueDoesNotMatchA1").getConst(), objNode);
97+
assertEquals(openAPI.getComponents().getSchemas().get("ConstWith0DoesNotMatchOtherZeroLikeTypes").getConst(), 0);
98+
assertEquals(openAPI.getComponents().getSchemas().get("ConstWith1DoesNotMatchTrue").getConst(), 1);
99+
assertEquals(openAPI.getComponents().getSchemas().get("ConstWith20MatchesIntegerAndFloatTypes").getConst(), new BigDecimal("-2.0"));
100+
assertEquals(openAPI.getComponents().getSchemas().get("ConstFloatAndIntegersAreEqualUpTo64BitRepresentationLimits").getConst(), new BigDecimal(9007199254740992L));
101+
assertEquals(openAPI.getComponents().getSchemas().get("ConstNulCharactersInStrings").getConst(), "hello\0there");
102+
}
103+
59104
@Test(description = "Test basic OAS31 deserialization/validation")
60105
public void testBasicOAS31() {
61106
SwaggerParseResult result = new OpenAPIV3Parser().readLocation( "3.1.0/test/basicOAS31.yaml", null, null);
@@ -1001,8 +1046,11 @@ public void test31SafeURLResolving() {
10011046
parseOptions.setRemoteRefBlockList(blockList);
10021047

10031048
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("3.1.0/resolve/safeResolving/safeUrlResolvingWithPetstore.yaml", null, parseOptions);
1004-
1005-
assertTrue(result.getMessages().isEmpty());
1049+
if (result.getMessages() != null) {
1050+
for (String message : result.getMessages()) {
1051+
assertTrue(message.contains("Server returned HTTP response code: 403"));
1052+
}
1053+
}
10061054
}
10071055

10081056
@Test(description = "Test safe resolving with blocked URL")
@@ -1015,11 +1063,15 @@ public void test31SafeURLResolvingWithBlockedURL() {
10151063
parseOptions.setRemoteRefAllowList(allowList);
10161064
parseOptions.setRemoteRefBlockList(blockList);
10171065

1018-
List<String> errorList = Arrays.asList("URL is part of the explicit denylist. URL [https://petstore3.swagger.io/api/v3/openapi.json]");
10191066
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("3.1.0/resolve/safeResolving/safeUrlResolvingWithPetstore.yaml", null, parseOptions);
10201067

1021-
assertEquals(result.getMessages(), errorList);
1022-
assertEquals(result.getMessages().size(), 1);
1068+
if (result.getMessages() != null) {
1069+
for (String message : result.getMessages()) {
1070+
assertTrue(
1071+
message.contains("Server returned HTTP response code: 403") ||
1072+
message.contains("URL is part of the explicit denylist. URL [https://petstore3.swagger.io/api/v3/openapi.json]"));
1073+
}
1074+
}
10231075
}
10241076

10251077
@Test(description = "Test safe resolving with turned off safelyResolveURL option")
@@ -1033,8 +1085,11 @@ public void test31SafeURLResolvingWithTurnedOffSafeResolving() {
10331085
parseOptions.setRemoteRefBlockList(blockList);
10341086

10351087
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("3.1.0/resolve/safeResolving/safeUrlResolvingWithPetstore.yaml", null, parseOptions);
1036-
1037-
assertTrue(result.getMessages().isEmpty());
1088+
if (result.getMessages() != null) {
1089+
for (String message : result.getMessages()) {
1090+
assertTrue(message.contains("Server returned HTTP response code: 403"));
1091+
}
1092+
}
10381093
}
10391094

10401095
@Test(description = "Test safe resolving with localhost and blocked url")
@@ -1044,9 +1099,13 @@ public void test31SafeURLResolvingWithLocalhostAndBlockedURL() {
10441099
parseOptions.setSafelyResolveURL(true);
10451100

10461101
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("3.1.0/resolve/safeResolving/safeUrlResolvingWithLocalhost.yaml", null, parseOptions);
1047-
1048-
assertTrue(result.getMessages().get(0).contains("IP is restricted"));
1049-
assertEquals(result.getMessages().size(), 1);
1102+
if (result.getMessages() != null) {
1103+
for (String message : result.getMessages()) {
1104+
assertTrue(
1105+
message.contains("Server returned HTTP response code: 403") ||
1106+
message.contains("IP is restricted"));
1107+
}
1108+
}
10501109
}
10511110

10521111
@Test(description = "Test safe resolving with localhost url")
@@ -1060,8 +1119,14 @@ public void test31SafeURLResolvingWithLocalhost() {
10601119
String error = "URL is part of the explicit denylist. URL [https://petstore.swagger.io/v2/swagger.json]";
10611120
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("3.1.0/resolve/safeResolving/safeUrlResolvingWithLocalhost.yaml", null, parseOptions);
10621121

1063-
assertTrue(result.getMessages().get(0).contains("IP is restricted"));
1064-
assertEquals(result.getMessages().get(1), error);
1065-
assertEquals(result.getMessages().size(), 2);
1122+
if (result.getMessages() != null) {
1123+
for (String message : result.getMessages()) {
1124+
assertTrue(
1125+
message.contains("Server returned HTTP response code: 403") ||
1126+
message.contains("IP is restricted") ||
1127+
message.contains(error)
1128+
);
1129+
}
1130+
}
10661131
}
10671132
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
openapi: 3.1.0
2+
servers:
3+
- url: https://someserver.com/v1
4+
info:
5+
title: openapi 3.1.0 sample spec
6+
version: 0.0.1
7+
description: sample spec for testing openapi functionality, built from json schema
8+
tests for draft2020-12
9+
tags: []
10+
paths: {}
11+
components:
12+
schemas:
13+
ConstValidation:
14+
$schema: https://json-schema.org/draft/2020-12/schema
15+
const: 2
16+
ConstWithObject:
17+
$schema: https://json-schema.org/draft/2020-12/schema
18+
const:
19+
foo: bar
20+
baz: bax
21+
ConstWithArray:
22+
$schema: https://json-schema.org/draft/2020-12/schema
23+
const:
24+
- foo: bar
25+
ConstWithNull:
26+
$schema: https://json-schema.org/draft/2020-12/schema
27+
const: null
28+
ConstWithFalseDoesNotMatch0:
29+
$schema: https://json-schema.org/draft/2020-12/schema
30+
const: false
31+
ConstWithTrueDoesNotMatch1:
32+
$schema: https://json-schema.org/draft/2020-12/schema
33+
const: true
34+
ConstWithArrayFalseDoesNotMatch0:
35+
$schema: https://json-schema.org/draft/2020-12/schema
36+
const:
37+
- false
38+
ConstWithArrayTrueDoesNotMatch1:
39+
$schema: https://json-schema.org/draft/2020-12/schema
40+
const:
41+
- true
42+
ConstWithAFalseDoesNotMatchA0:
43+
$schema: https://json-schema.org/draft/2020-12/schema
44+
const:
45+
a: false
46+
ConstWithATrueDoesNotMatchA1:
47+
$schema: https://json-schema.org/draft/2020-12/schema
48+
const:
49+
a: true
50+
ConstWith0DoesNotMatchOtherZeroLikeTypes:
51+
$schema: https://json-schema.org/draft/2020-12/schema
52+
const: 0
53+
ConstWith1DoesNotMatchTrue:
54+
$schema: https://json-schema.org/draft/2020-12/schema
55+
const: 1
56+
ConstWith20MatchesIntegerAndFloatTypes:
57+
$schema: https://json-schema.org/draft/2020-12/schema
58+
const: -2.0
59+
ConstFloatAndIntegersAreEqualUpTo64BitRepresentationLimits:
60+
$schema: https://json-schema.org/draft/2020-12/schema
61+
const: 9007199254740992
62+
ConstNulCharactersInStrings:
63+
$schema: https://json-schema.org/draft/2020-12/schema
64+
const: "hello\0there"

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@
137137
</plugin>
138138
<plugin>
139139
<artifactId>maven-compiler-plugin</artifactId>
140-
<version>3.10.1</version>
140+
<version>3.11.0</version>
141141
</plugin>
142142
<plugin>
143143
<groupId>org.apache.maven.plugins</groupId>
144144
<artifactId>maven-javadoc-plugin</artifactId>
145-
<version>3.5.0</version>
145+
<version>3.6.2</version>
146146
<configuration>
147147
<aggregate>true</aggregate>
148148
<source>1.8</source>
@@ -165,7 +165,7 @@
165165
<plugin>
166166
<groupId>org.apache.maven.plugins</groupId>
167167
<artifactId>maven-source-plugin</artifactId>
168-
<version>3.2.1</version>
168+
<version>3.3.0</version>
169169
<executions>
170170
<execution>
171171
<id>attach-sources</id>
@@ -421,8 +421,8 @@
421421
<junit-version>4.13.2</junit-version>
422422
<testng-version>7.8.0</testng-version>
423423
<jmockit-version>1.49</jmockit-version>
424-
<wiremock-version>2.35.0</wiremock-version>
425-
<surefire-version>3.0.0</surefire-version>
424+
<wiremock-version>2.35.1</wiremock-version>
425+
<surefire-version>3.2.2</surefire-version>
426426
<commons-lang-version>3.13.0</commons-lang-version>
427427
<jackson-version>2.15.3</jackson-version>
428428
<jackson-databind-version>2.15.3</jackson-databind-version>

0 commit comments

Comments
 (0)