diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000000..2d1daffbfd
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,18 @@
+version: 2
+updates:
+ - package-ecosystem: "maven"
+ target-branch: "master"
+ directory: "/"
+ schedule:
+ interval: "daily"
+ allow:
+ - dependency-name: "io.swagger.core.v3:*"
+ - dependency-name: "io.swagger:*"
+ - package-ecosystem: "maven"
+ target-branch: "v1"
+ directory: "/"
+ schedule:
+ interval: "daily"
+ allow:
+ - dependency-name: "io.swagger.core.v3:*"
+ - dependency-name: "io.swagger:*"
diff --git a/README.md b/README.md
index c0112f7f25..74e60a9288 100644
--- a/README.md
+++ b/README.md
@@ -114,7 +114,7 @@ You can include this library from Sonatype OSS for SNAPSHOTS, or Maven central f
io.swagger.parser.v3
swagger-parser
- 2.1.11
+ 2.1.12
```
diff --git a/modules/swagger-parser-cli/pom.xml b/modules/swagger-parser-cli/pom.xml
index 67188962cd..2f3557bdb1 100644
--- a/modules/swagger-parser-cli/pom.xml
+++ b/modules/swagger-parser-cli/pom.xml
@@ -5,7 +5,7 @@
swagger-parser-project
io.swagger.parser.v3
- 2.1.12-SNAPSHOT
+ 2.1.13-SNAPSHOT
../..
4.0.0
@@ -69,7 +69,7 @@
io.swagger.parser.v3
swagger-parser-v3
- 2.1.12-SNAPSHOT
+ 2.1.13-SNAPSHOT
compile
diff --git a/modules/swagger-parser-core/pom.xml b/modules/swagger-parser-core/pom.xml
index 04d72f946c..b567642091 100644
--- a/modules/swagger-parser-core/pom.xml
+++ b/modules/swagger-parser-core/pom.xml
@@ -3,7 +3,7 @@
io.swagger.parser.v3
swagger-parser-project
- 2.1.12-SNAPSHOT
+ 2.1.13-SNAPSHOT
../..
4.0.0
diff --git a/modules/swagger-parser-v2-converter/pom.xml b/modules/swagger-parser-v2-converter/pom.xml
index d7a1168d88..e364e2a6ab 100644
--- a/modules/swagger-parser-v2-converter/pom.xml
+++ b/modules/swagger-parser-v2-converter/pom.xml
@@ -3,7 +3,7 @@
io.swagger.parser.v3
swagger-parser-project
- 2.1.12-SNAPSHOT
+ 2.1.13-SNAPSHOT
../..
4.0.0
diff --git a/modules/swagger-parser-v3/pom.xml b/modules/swagger-parser-v3/pom.xml
index e9a152248e..51216143bc 100644
--- a/modules/swagger-parser-v3/pom.xml
+++ b/modules/swagger-parser-v3/pom.xml
@@ -3,7 +3,7 @@
io.swagger.parser.v3
swagger-parser-project
- 2.1.12-SNAPSHOT
+ 2.1.13-SNAPSHOT
../..
4.0.0
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java
index 6388d95b42..286f9ccac9 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java
@@ -149,8 +149,8 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
for(Schema item : composedSchema.getAllOf()){
if (item.get$ref() != null){
processRefSchema(item,file);
- } else if (item.getProperties() != null) {
- processProperties(item.getProperties(), file);
+ } else{
+ processSchema(item, file);
}
}
@@ -159,6 +159,8 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
if (item.get$ref() != null){
if (item.get$ref() != null){
processRefSchema(item,file);
+ }else{
+ processSchema(item, file);
}
}
}
@@ -167,10 +169,11 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
if (item.get$ref() != null){
if (item.get$ref() != null){
processRefSchema(item,file);
+ }else{
+ processSchema(item, file);
}
}
}
-
}
}
//Loop the properties and recursively call this method;
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/DereferencersFactory.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/DereferencersFactory.java
index 17eb5ea689..f8fdd40195 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/DereferencersFactory.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/DereferencersFactory.java
@@ -47,7 +47,7 @@ public List getDereferencers() {
if (ext == null) {
LOGGER.error("failed to load extension {}", ext);
} else {
- instance.addDereferencer(ext);
+ getInstance().addDereferencer(ext);
LOGGER.debug("adding OpenAPIDereferencer: {}", ext);
}
}
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/ReferenceUtils.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/ReferenceUtils.java
index d35c395c76..79f8542d50 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/ReferenceUtils.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/ReferenceUtils.java
@@ -1,24 +1,13 @@
package io.swagger.v3.parser.reference;
import com.fasterxml.jackson.databind.JsonNode;
-import io.swagger.v3.core.util.Json31;
-import io.swagger.v3.core.util.Yaml31;
-import io.swagger.v3.parser.core.models.AuthorizationValue;
-import io.swagger.v3.parser.util.ClasspathHelper;
-import io.swagger.v3.parser.util.RemoteUrl;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
-import java.io.FileInputStream;
-import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
-import java.util.List;
import java.util.regex.Pattern;
-import static java.nio.charset.StandardCharsets.UTF_8;
-
public class ReferenceUtils {
public static String toBaseURI(String uri) throws Exception
@@ -68,52 +57,6 @@ public static boolean isAnchor(String ref) {
return false;
}
- public static String readURI(String absoluteUri, List auths) throws Exception {
- URI resolved = new URI(absoluteUri);
- if (StringUtils.isNotBlank(resolved.getScheme())) {
- if (resolved.getScheme().startsWith("http")) {
- return readHttp(absoluteUri, auths);
- } else if (resolved.getScheme().startsWith("file")) {
- return readFile(absoluteUri);
- } else if (resolved.getScheme().startsWith("classpath")) {
- return readClasspath(absoluteUri);
- }
- }
- // If no matches exists, try file
- String content = null;
- try {
- content = readFile(absoluteUri);
- } catch (Exception e) {
- //
- }
- if (StringUtils.isBlank(content)) {
- content = readClasspath(absoluteUri);
- }
- return content;
- }
-
- public static JsonNode deserializeIntoTree(String content) throws Exception {
- boolean isJson = content.trim().startsWith("{");
- return isJson ? Json31.mapper().readTree(content) : Yaml31.mapper().readTree(content);
- }
-
- public static JsonNode parse(String absoluteUri, List auths) throws Exception {
- return deserializeIntoTree(readURI(absoluteUri, auths));
- }
-
- public static String readFile(String uri) throws Exception {
- try (InputStream inputStream = new FileInputStream(uri)) {
- return IOUtils.toString(inputStream, UTF_8);
- }
- }
-
- public static String readClasspath(String uri) throws Exception {
- return ClasspathHelper.loadFileFromClasspath(uri);
- }
- public static String readHttp(String uri, List auths) throws Exception {
- return RemoteUrl.urlToString(uri, auths);
- }
-
public static String unescapePointer(String jsonPathElement) {
// URL decode the fragment
try {
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/ReferenceVisitor.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/ReferenceVisitor.java
index 555babbddf..9b9a656141 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/ReferenceVisitor.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/ReferenceVisitor.java
@@ -2,6 +2,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
+import io.swagger.v3.core.util.Json31;
+import io.swagger.v3.core.util.Yaml31;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.examples.Example;
import io.swagger.v3.oas.models.headers.Header;
@@ -11,6 +13,7 @@
import io.swagger.v3.oas.models.parameters.RequestBody;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.security.SecurityScheme;
+import io.swagger.v3.parser.core.models.AuthorizationValue;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;
@@ -50,7 +53,7 @@ public Reference toReference(String uri) throws Exception{
if (referenceSet.containsKey(baseUri)) {
return referenceSet.get(baseUri);
}
- JsonNode node = ReferenceUtils.parse(baseUri, this.reference.getAuths());
+ JsonNode node = parse(baseUri, this.reference.getAuths());
Reference ref = new Reference()
.auths(this.reference.getAuths())
@@ -205,11 +208,11 @@ public Schema resolveSchemaRef(Schema visiting, String ref, List inherit
else {
JsonNode node = null;
try {
- node = ReferenceUtils.parse(baseURI, this.reference.getAuths());
+ node = parse(baseURI, this.reference.getAuths());
} catch (Exception e) {
// we can not parse, try ref
baseURI = toBaseURI(ref);
- node = ReferenceUtils.parse(baseURI, this.reference.getAuths());
+ node = parse(baseURI, this.reference.getAuths());
}
reference = toSchemaReference(baseURI, node);
}
@@ -266,4 +269,13 @@ public JsonNode findAnchor(JsonNode root, String anchor) {
return null;
}
+
+ public JsonNode deserializeIntoTree(String content) throws Exception {
+ boolean isJson = content.trim().startsWith("{");
+ return isJson ? Json31.mapper().readTree(content) : Yaml31.mapper().readTree(content);
+ }
+
+ public JsonNode parse(String absoluteUri, List auths) throws Exception {
+ return deserializeIntoTree(readURI(absoluteUri, auths));
+ }
}
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/Visitor.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/Visitor.java
index 651d18f765..d41b21cc22 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/Visitor.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/Visitor.java
@@ -16,9 +16,19 @@
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.responses.ApiResponses;
import io.swagger.v3.oas.models.security.SecurityScheme;
-
+import io.swagger.v3.parser.core.models.AuthorizationValue;
+import io.swagger.v3.parser.util.ClasspathHelper;
+import io.swagger.v3.parser.util.RemoteUrl;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.URI;
import java.util.List;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
public interface Visitor {
OpenAPI visitOpenApi(OpenAPI openAPI);
@@ -52,4 +62,41 @@ public interface Visitor {
Example visitExample(Example example);
+ default String readFile(String uri) throws Exception {
+ try (InputStream inputStream = new FileInputStream(uri)) {
+ return IOUtils.toString(inputStream, UTF_8);
+ }
+ }
+
+ default String readClasspath(String uri) throws Exception {
+ return ClasspathHelper.loadFileFromClasspath(uri);
+ }
+ default String readHttp(String uri, List auths) throws Exception {
+ return RemoteUrl.urlToString(uri, auths);
+ }
+
+ default String readURI(String absoluteUri, List auths) throws Exception {
+ URI resolved = new URI(absoluteUri);
+ if (StringUtils.isNotBlank(resolved.getScheme())) {
+ if (resolved.getScheme().startsWith("http")) {
+ return readHttp(absoluteUri, auths);
+ } else if (resolved.getScheme().startsWith("file")) {
+ return readFile(absoluteUri);
+ } else if (resolved.getScheme().startsWith("classpath")) {
+ return readClasspath(absoluteUri);
+ }
+ }
+ // If no matches exists, try file
+ String content = null;
+ try {
+ content = readFile(absoluteUri);
+ } catch (Exception e) {
+ //
+ }
+ if (StringUtils.isBlank(content)) {
+ content = readClasspath(absoluteUri);
+ }
+ return content;
+ }
+
}
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RefUtils.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RefUtils.java
index 7fcf56a4c6..561a3b5679 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RefUtils.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RefUtils.java
@@ -14,6 +14,7 @@
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.Arrays;
import java.util.List;
import java.util.Optional;
@@ -47,10 +48,13 @@ public static String computeDefinitionName(String ref) {
plausibleName = filePathElements[filePathElements.length - 1];
final String[] split = plausibleName.split("\\.");
- // Fix for issue-1621
- plausibleName = split[0];
- for (int i = 1; i < split.length - 1; i++) {
- plausibleName += "." + split[i];
+ // Fix for issue-1621 and issue-1865
+ //validate number of dots
+ if(split.length > 2) {
+ //Remove dot so ref can be interpreted as internal and relative in Swagger-Core schema class 'set$ref'
+ plausibleName = String.join("", Arrays.copyOf(split, split.length - 1));
+ }else{
+ plausibleName = split[0];
}
}
@@ -225,4 +229,4 @@ private static String readAll(Path path) throws IOException {
return IOUtils.toString(inputStream, UTF_8);
}
}
-}
\ No newline at end of file
+}
diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/CustomOpenAPIDereferencer.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/CustomOpenAPIDereferencer.java
new file mode 100644
index 0000000000..1482cf25ff
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/CustomOpenAPIDereferencer.java
@@ -0,0 +1,51 @@
+package io.swagger.v3.parser.test;
+
+import io.swagger.v3.parser.core.models.AuthorizationValue;
+import io.swagger.v3.parser.reference.DereferencerContext;
+import io.swagger.v3.parser.reference.OpenAPI31Traverser;
+import io.swagger.v3.parser.reference.OpenAPIDereferencer31;
+import io.swagger.v3.parser.reference.Reference;
+import io.swagger.v3.parser.reference.ReferenceVisitor;
+import io.swagger.v3.parser.reference.Traverser;
+import io.swagger.v3.parser.reference.Visitor;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+
+public class CustomOpenAPIDereferencer extends OpenAPIDereferencer31 {
+ @Override
+ public Visitor buildReferenceVisitor(DereferencerContext context, Reference reference, Traverser traverser) {
+ return new CustomVisitor(reference, (OpenAPI31Traverser)traverser, new HashSet<>(), new HashMap<>());
+ }
+
+ static public class CustomVisitor extends ReferenceVisitor {
+
+ public CustomVisitor(Reference reference, OpenAPI31Traverser openAPITraverser, HashSet