Java 中的 Swagger 规范验证 [英] Swagger Spec Validation in Java
问题描述
我试图验证一些可能包含 swagger 规范的字符串.我正在尝试使用 swagger 解析器.
iam trying to validate some strings that may contain swagger specifications. Iam trying to use the swagger parser.
以下代码不起作用.我只收到消息:[属性不是 object
] 类型"
The following code doesn't work. I only get the message: "[attribute is not of type object
]"
从 xml 文件中读取 swagger 规范.
The swagger spec is read out of an xml file.
swaggerXml = nodeList.item(0).getTextContent();
SwaggerDeserializationResult res = new SwaggerParser().readWithInfo(swaggerXml);
for (int i = 0; i < res.getMessages().size(); i++){
log.info(res.getMessages().toString());
}
这个方法有错吗?或者.错误消息的含义是什么?我只想知道该字符串是否包含 JSON 格式的有效 Swagger 规范.
Is this method wrong? Or. what is the meaning of the error message? I just want to know if the string contains a valid Swagger specification in JSON format.
感谢您的帮助.
更新:问题已解决
据我所知,如果字符串不是 json 有效的,则会抛出错误.首先我检查 json 是否有效,然后才执行 swagger 解析器.
As far as I could see the error is thrown if the string is not json valid. First I check if the json is valid and only then execute the swagger parser.
推荐答案
只是想提供我不久前想出的解决方案.
just want to provide my solution i figured out a while ago.
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(swaggerXml);
List<String> messageList = result.getMessages();
然后打印列表元素.
这篇关于Java 中的 Swagger 规范验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!