NullPointerException when trying to parse OAS3 from a String
还没有人认领这个 Issue。
评估
调研方向
首先复现 StringParseTest.testSelfContainedOasSpec,然后检查 ReferenceManager.java 中的 getDocReference,以及堆栈跟踪中显示的 OpenApiParser.java 的 parse 重载。当一个自包含的 OAS3 字符串在 resolutionBase 为 null 的情况下能够完成解析,并且 title 和 path 断言在没有 NullPointerException 的情况下通过时,修复就完成了。
由索引模型根据 Issue 内容生成。
描述
The KaiZen-OpenApi-Parser documentation sounds as if the "resolutionBase" can be left empty if the OAS3 is fully self-contained and no relative references are used:
https://github.com/RepreZen/KaiZen-OpenApi-Parser/blob/master/API-Overview.md
OpenApi3 parse(String model, URL resolutionBase) - parse a JSON or YAML string, with the given URL used for resolving any relative references encountered in the model. If resolutionBase is null, relative references will all fail resolution.
But calling the parse method without a resolutionBase leads to a NullPointerException:
java.lang.NullPointerException: Cannot invoke "java.net.URL.toString()" because "this.docUrl" is null
at com.networknt.jsonoverlay.ReferenceManager.getDocReference(ReferenceManager.java:62)
at com.networknt.oas.OpenApiParser.parse(OpenApiParser.java:95)
at com.networknt.oas.OpenApiParser.parse(OpenApiParser.java:85)
at com.networknt.oas.OpenApiParser.parse(OpenApiParser.java:35)
at com.networknt.oas.OpenApi3Parser.parse(OpenApi3Parser.java:29)
at com.networknt.oas.OpenApi3Parser.parse(OpenApi3Parser.java:1)
at com.networknt.oas.OpenApiParser.parse(OpenApiParser.java:28)
at com.networknt.oas.OpenApi3Parser.parse(OpenApi3Parser.java:24)
at com.networknt.oas.StringParseTest.testSelfContainedOasSpec(StringParseTest.java:57)
Here is a short test that I wrote:
public class StringParseTest {
private final static String testTitle = "Test Title";
private final static String testPath = "/test";
private final String oas3String = //
"openapi: 3.0.0\n" //
+ "info:\n" //
+ " title: " + testTitle + "\n" //
+ " description: This is a description\n" //
+ " version: 1.0.0\n" //
+ "servers:\n" //
+ " - url: https://localhost:8080\n" //
+ "paths:\n" //
+ " " + testPath + ":\n" //
+ " get:\n" //
+ " description: Some endpoint\n" //
+ " operationId: testOps\n" //
+ " responses:\n" //
+ " '200':\n" //
+ " description: Successful operation\n";
@Test
public void testSelfContainedOasSpec() throws Exception {
// no need to pass a resolutionBase since the spec is self contained
OpenApi3 oas3 = new OpenApi3Parser().parse(this.oas3String, null);
assertEquals(testTitle, oas3.getInfo().getTitle());
Map<String, Path> paths = oas3.getPaths();
assertEquals(1, paths.size());
assertEquals("/test", paths.entrySet().iterator().next().getKey());
}
}
Please also note that this is only one issue. It looks like there are more issues if I try to load more complicated OAS3 specs, like for instance here:
@Test
public void testYamlFileAsString() throws Exception {
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
String oas3String;
try (InputStream is = classLoader.getResourceAsStream("models/circular.yaml")) {
assertNotNull(is);
try (InputStreamReader isr = new InputStreamReader(is); BufferedReader reader = new BufferedReader(isr)) {
oas3String = reader.lines().collect(Collectors.joining(System.lineSeparator()));
}
}
assertNotNull(oas3String);
OpenApi3 oas3 = new OpenApi3Parser().parse(oas3String, null);
// check oas3 object ...
}
- 主要语言
- Java
- 星标
- 13
- 派生
- 9
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
networknt/openapi-parser 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 50/100
networknt/openapi-parser#66 ·
查看 networknt/openapi-parser 的全部 Issue
相似的 Issue
-
area/plugin
难度 2/5 1-3 小时 新手友好度 75/100
kestra-io/plugin-kestra#190 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
integra-team-red/meet-map#249 ·
-
[Studio][Bug] Cancelled create-user dialog keeps the password and admin switch for the next attempt 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
apache/rocketmq-dashboard#5064 ·