-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2035 from maddingo/bugfix/issue-2034
fixed issue 2034, added test case for issue
- Loading branch information
Showing
2 changed files
with
58 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...es/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV31ParserUriTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.swagger.v3.parser.test; | ||
|
||
|
||
import io.swagger.v3.parser.OpenAPIV3Parser; | ||
import io.swagger.v3.parser.core.models.ParseOptions; | ||
import io.swagger.v3.parser.core.models.SwaggerParseResult; | ||
import org.apache.commons.io.IOUtils; | ||
import org.testng.annotations.Test; | ||
|
||
import java.net.URI; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertNull; | ||
|
||
/** | ||
* Test parsing classpath and file URIs. | ||
* Before the fix, an exception is logged as an error and a message containing "(No such file or directory)" | ||
* is added to the parse result. | ||
* This test checks for the absence of the message. | ||
*/ | ||
public class OpenAPIV31ParserUriTest { | ||
@Test | ||
public void resolveFileInput() throws Exception { | ||
URI uri = getClass().getResource("/3.1.0/basic.yaml").toURI(); | ||
assertEquals(uri.getScheme(), "file"); | ||
String uriString = uri.toString(); | ||
ParseOptions options = new ParseOptions(); | ||
options.setResolve(true); | ||
SwaggerParseResult result = new OpenAPIV3Parser().readLocation(uriString, null, options); | ||
validateParseResult(result, "(No such file or directory)"); | ||
} | ||
|
||
@Test | ||
public void resolveClasspathInput() throws Exception { | ||
URL url = getClass().getResource("/3.1.0/basic.yaml"); | ||
String content = IOUtils.toString(url, StandardCharsets.UTF_8); | ||
ParseOptions options = new ParseOptions(); | ||
options.setResolve(true); | ||
SwaggerParseResult result = new OpenAPIV3Parser().readContents(content, null, options, "classpath:/3.1.0/basic.yaml"); | ||
validateParseResult(result, "Could not find classpath:/3.1.0/basic.yaml"); | ||
} | ||
|
||
private static void validateParseResult(SwaggerParseResult result, String checkForMessage) { | ||
String noSuchFileMessage = result.getMessages().stream() | ||
.filter(message -> message.contains(checkForMessage)) | ||
.findFirst() | ||
.orElse(null); | ||
assertNull(noSuchFileMessage); | ||
} | ||
} |