Skip to content

Commit 0bc719a

Browse files
committed
oas 3.1 - fix rebase issues
1 parent 64cc238 commit 0bc719a

File tree

11 files changed

+92
-107
lines changed

11 files changed

+92
-107
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/ResolverCache.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public ResolverCache(OpenAPI openApi, List<AuthorizationValue> auths, String par
8686
}
8787

8888
public ResolverCache(OpenAPI openApi, List<AuthorizationValue> auths, String parentFileLocation, Set<String> resolveValidationMessages, ParseOptions parseOptions) {
89-
this.openapi31 = parseOptions.isOpenapi31();
89+
this.openapi31 = openApi != null && openApi.getOpenapi() != null && openApi.getOpenapi().startsWith("3.1");
9090
this.openApi = openApi;
9191
this.auths = auths;
9292
this.rootPath = parentFileLocation;
@@ -159,7 +159,7 @@ else if (rootPath != null) {
159159
externalFileCache.put(file, contents);
160160
}
161161
SwaggerParseResult deserializationUtilResult = new SwaggerParseResult();
162-
JsonNode tree = DeserializationUtils.deserializeIntoTree(contents, file, parseOptions, deserializationUtilResult, openapi31);
162+
JsonNode tree = DeserializationUtils.deserializeIntoTree(contents, file, parseOptions, deserializationUtilResult);
163163

164164
if (definitionPath == null) {
165165
T result = null;
@@ -192,7 +192,7 @@ else if (rootPath != null) {
192192
} else {
193193
if (expectedType.equals(Schema.class)) {
194194
OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
195-
result = (T) deserializer.getSchema((ObjectNode) tree, definitionPath.replace("/", "."), null, , new OpenAPIDeserializer.ParseResult().openapi31(openapi31));
195+
result = (T) deserializer.getSchema((ObjectNode) tree, definitionPath.replace("/", "."), new OpenAPIDeserializer.ParseResult().openapi31(openapi31));
196196
} else {
197197
result = DeserializationUtils.deserialize(tree, file, expectedType, openapi31);
198198
}

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,15 @@ protected void addImplicitResolvers() {
132132
public static JsonNode deserializeIntoTree(String contents, String fileOrHost) {
133133
return deserializeIntoTree(contents, fileOrHost, null, new SwaggerParseResult());
134134
}
135-
public static JsonNode deserializeIntoTree(String contents, String fileOrHost, ParseOptions parseOptions, SwaggerParseResult deserializationUtilsResult) {
136-
return deserializeIntoTree(contents, fileOrHost, parseOptions, deserializationUtilsResult, false);
137-
}
138135

139-
public static JsonNode deserializeIntoTree(String contents, String fileOrHost, ParseOptions parseOptions, SwaggerParseResult deserializationUtilsResult, boolean openapi31) {
136+
public static JsonNode deserializeIntoTree(String contents, String fileOrHost, ParseOptions parseOptions, SwaggerParseResult deserializationUtilsResult) {
140137
JsonNode result;
141138

142139
try {
143140
if (isJson(contents)) {
144-
result = openapi31 ? ObjectMapperFactory.createJson31().readTree(contents) : ObjectMapperFactory.createJson().readTree(contents);
141+
result = ObjectMapperFactory.createJson().readTree(contents);
145142
} else {
146-
result = readYamlTree(contents, parseOptions, deserializationUtilsResult, openapi31);
143+
result = readYamlTree(contents, parseOptions, deserializationUtilsResult);
147144
}
148145
} catch (IOException e) {
149146
throw new RuntimeException("An exception was thrown while trying to deserialize the contents of " + fileOrHost + " into a JsonNode tree", e);
@@ -161,7 +158,7 @@ public static <T> T deserialize(Object contents, String fileOrHost, Class<T> exp
161158

162159
boolean isJson = false;
163160

164-
if(contents instanceof String && isJson((String)contents)) {
161+
if (contents instanceof String && isJson((String)contents)) {
165162
isJson = true;
166163
}
167164

@@ -196,16 +193,13 @@ private static boolean isJson(String contents) {
196193
}
197194

198195
public static JsonNode readYamlTree(String contents) {
199-
return readYamlTree(contents, null, new SwaggerParseResult(), false);
196+
return readYamlTree(contents, null, new SwaggerParseResult());
200197
}
201-
public static JsonNode readYamlTree(String contents, ParseOptions parseOptions, SwaggerParseResult deserializationUtilsResult, boolean openapi31) {
202-
203-
ObjectMapper jsonMapper = openapi31 ? Json31.mapper() : Json.mapper();
204-
ObjectMapper yamlMapper = openapi31 ? Yaml31.mapper() : Yaml.mapper();
198+
public static JsonNode readYamlTree(String contents, ParseOptions parseOptions, SwaggerParseResult deserializationUtilsResult) {
205199

206200
if (parseOptions != null && parseOptions.isLegacyYamlDeserialization()) {
207201
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(new SafeConstructor());
208-
return jsonMapper.convertValue(yaml.load(contents), JsonNode.class);
202+
return Json.mapper().convertValue(yaml.load(contents), JsonNode.class);
209203
}
210204
try {
211205
org.yaml.snakeyaml.Yaml yaml = null;
@@ -219,7 +213,7 @@ public static JsonNode readYamlTree(String contents, ParseOptions parseOptions,
219213
boolean res = exceedsLimits(o, null, new Integer(0), new IdentityHashMap<Object, Long>(), deserializationUtilsResult);
220214
if (res) {
221215
LOGGER.warn("Error converting snake-parsed yaml to JsonNode");
222-
return yamlMapper.readTree(contents);
216+
return Yaml.mapper().readTree(contents);
223217
}
224218
}
225219
try {
@@ -228,14 +222,14 @@ public static JsonNode readYamlTree(String contents, ParseOptions parseOptions,
228222
} catch (Exception e) {
229223
//
230224
}
231-
return jsonMapper.convertValue(o, JsonNode.class);
225+
return Json.mapper().convertValue(o, JsonNode.class);
232226
} catch (Throwable e) {
233227
LOGGER.warn("Error snake-parsing yaml content", e);
234228
if (deserializationUtilsResult != null) {
235229
deserializationUtilsResult.message(e.getMessage());
236230
}
237231
try {
238-
return yamlMapper.readTree(contents);
232+
return Yaml.mapper().readTree(contents);
239233
} catch (Exception ee) {
240234
LOGGER.error("Error parsing content", ee);
241235
throw new RuntimeException(e);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public class OpenAPIDeserializer {
136136

137137
// 3.1
138138
// TODO use a map instead for 3.0 and 3.1. Care about compatibility
139+
// TODO OAS3.1 - ensure all OAS 3.1 new keywords are added to the various sets
139140
protected static Set<String> ROOT_KEYS_31 = new LinkedHashSet<>(Arrays.asList("openapi", "info", "servers", "paths",
140141
"components", "security", "tags", "externalDocs", "webhooks", "jsonSchemaDialect"));
141142
protected static Set<String> RESERVED_KEYWORDS_31 = new LinkedHashSet<>(Arrays.asList("x-oai-","x-oas-"));
@@ -166,14 +167,15 @@ public class OpenAPIDeserializer {
166167
protected static Set<String> EXTERNAL_DOCS_KEYS_31 = new LinkedHashSet<>(Arrays.asList("description", "url"));
167168
protected static Set<String> COMPONENTS_KEYS_31 = new LinkedHashSet<>(Arrays.asList("schemas", "responses", "pathItems",
168169
"parameters", "examples", "requestBodies", "headers", "securitySchemes", "links", "callbacks"));
170+
// TODO OAS3.1 - ensure all schema 2020/12 + OAS 3.1 vocabulary keys are added
169171
protected static Set<String> SCHEMA_KEYS_31 = new LinkedHashSet<>(Arrays.asList("$ref", "title", "multipleOf",
170172
"maximum", "format", "exclusiveMaximum", "minimum", "exclusiveMinimum", "maxLength", "minLength",
171173
"pattern",
172174
"maxItems", "minItems", "uniqueItems", "maxProperties", "minProperties", "required", "enum", "type",
173175
"allOf",
174176
"oneOf", "anyOf", "not", "items", "properties", "additionalProperties", "patternProperties", "description",
175177
"format", "default", "discriminator", "readOnly", "writeOnly", "xml", "externalDocs", "example", "deprecated",
176-
"const", "examples", "$id", "$comment"));
178+
"const", "examples", "$id", "$comment", "if", "then", "else", "unevaluatedProperties", "prefixItems"));
177179
protected static Set<String> EXAMPLE_KEYS_31 = new LinkedHashSet<>(Arrays.asList("$ref", "summary", "description",
178180
"value", "externalValue"));
179181
protected static Set<String> HEADER_KEYS_31 = new LinkedHashSet<>(Arrays.asList("$ref", "name", "in", "description",
@@ -1855,10 +1857,10 @@ public List<Parameter> getParameterList(ArrayNode obj, String location, ParseRes
18551857
if (!filter.add(param.getName() + "#" + param.getIn())) {
18561858
if (ref != null) {
18571859
if (ref.startsWith(REFERENCE_SEPARATOR)) {// validate if it's inline param also
1858-
result.warning(location, "There are duplicate parameter values");
1860+
result.warning(location, " There are duplicate parameter values");
18591861
}
18601862
} else {
1861-
result.warning(location, "There are duplicate parameter values");
1863+
result.warning(location, " There are duplicate parameter values");
18621864
}
18631865
}
18641866
});
@@ -4360,7 +4362,7 @@ public List<String> getMessages() {
43604362
}
43614363
for (Location l : warnings) {
43624364
String location = l.location.equals("") ? "" : l.location + ".";
4363-
String message = location + l.key;
4365+
String message = location + l.key;
43644366
messages.add(message);
43654367
}
43664368
for (Location l : unsupported.keySet()) {

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/processors/ExternalRefProcessorTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ public class ExternalRefProcessorTest {
3434
@Injectable
3535
OpenAPI openAPI;
3636

37-
@Injectable
38-
boolean openapi31;
39-
4037
@Test
4138
public void testProcessRefToExternalDefinition_NoNameConflict(
4239
@Injectable final Schema mockedModel) throws Exception {

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/processors/OperationProcessorTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import mockit.FullVerifications;
1414
import mockit.Injectable;
1515
import mockit.Mocked;
16-
import org.junit.Ignore;
1716
import org.testng.annotations.Test;
1817

1918
import java.util.List;
@@ -39,7 +38,7 @@ public class OperationProcessorTest {
3938
ResponseProcessor responseProcessor;
4039

4140
@Test (enabled = false)
42-
// TODO reenable failing on operation.getParameters()
41+
// TODO OAS3.1 - reenable failing on operation.getParameters()
4342
public void testProcessOperation(@Injectable final List<Parameter> inputParameterList,
4443
@Injectable final List<Parameter> outputParameterList,
4544
@Injectable final Parameter inputParameter,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void testValidateExternalRefsTrueRemote() throws Exception{
107107
assertTrue(result.getMessages().contains("attribute components.headers.X-Rate-Limit-Limit.descriptasdd is unexpected (./ref.yaml)"));
108108
assertTrue(result.getMessages().contains("attribute components.links.unsubscribe.parametersx is unexpected (./ref.yaml)"));
109109
assertTrue(result.getMessages().contains("attribute components.examples.response-example.summaryx is unexpected (./ref.yaml)"));
110-
assertTrue(result.getMessages().contains("attribute components.examples.response-example. value and externalValue are both present (./ref.yaml)"));
110+
assertTrue(result.getMessages().contains("components.examples.response-example. value and externalValue are both present (./ref.yaml)"));
111111
assertTrue(result.getMessages().contains("attribute components.callbacks.failed.wrongField is not of type `object` (./ref.yaml)"));
112112
assertTrue(result.getMessages().contains("attribute paths.~1refPet(get).responses is missing (./ref.yaml)"));
113113

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

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

3-
import io.swagger.v3.core.util.Yaml;
4-
import io.swagger.v3.core.util.Yaml31;
53
import io.swagger.v3.oas.models.OpenAPI;
64
import io.swagger.v3.oas.models.media.Schema;
75
import io.swagger.v3.oas.models.security.SecurityRequirement;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3263,7 +3263,7 @@ public void testValidateExternalRefsTrue() {
32633263
assertTrue(result.getMessages().contains("attribute components.headers.X-Rate-Limit-Limit.descriptasdd is unexpected (./ref.yaml)"));
32643264
assertTrue(result.getMessages().contains("attribute components.links.unsubscribe.parametersx is unexpected (./ref.yaml)"));
32653265
assertTrue(result.getMessages().contains("attribute components.examples.response-example.summaryx is unexpected (./ref.yaml)"));
3266-
assertTrue(result.getMessages().contains("attribute components.examples.response-example. value and externalValue are both present (./ref.yaml)"));
3266+
assertTrue(result.getMessages().contains("components.examples.response-example. value and externalValue are both present (./ref.yaml)"));
32673267
assertTrue(result.getMessages().contains("attribute components.callbacks.failed.wrongField is not of type `object` (./ref.yaml)"));
32683268
assertTrue(result.getMessages().contains("attribute paths.~1refPet(get).responses is missing (./ref.yaml)"));
32693269

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.swagger.v3.parser.test;
22

33

4-
import io.swagger.v3.core.util.Yaml;
54
import io.swagger.v3.oas.models.OpenAPI;
65
import io.swagger.v3.oas.models.parameters.RequestBody;
76
import io.swagger.v3.parser.OpenAPIV3Parser;
@@ -15,8 +14,6 @@
1514
import org.testng.Assert;
1615
import org.testng.annotations.Test;
1716

18-
import java.io.File;
19-
import java.net.MalformedURLException;
2017
import java.util.ArrayList;
2118
import java.util.Arrays;
2219
import java.util.HashSet;
@@ -164,7 +161,6 @@ public void testResolveRelativeSiblingPaths() {
164161
SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("/relativeParent/root/root.yaml", null, options);
165162

166163
Assert.assertNotNull(parseResult.getOpenAPI());
167-
Yaml.prettyPrint(parseResult);
168164

169165
HashSet<String> validationMessages = new HashSet<>(null != parseResult.getMessages() ? parseResult.getMessages() : new ArrayList<>());
170166
Assert.assertTrue(validationMessages.isEmpty(), validationMessages.toString());

0 commit comments

Comments
 (0)