Reputation: 965
iam trying to validate some strings that may contain swagger specifications. Iam trying to use the swagger parser.
The following code doesn't work. I only get the message: "[attribute is not of type object
]"
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());
}
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.
Thanks for your help.
Update: Problem solved
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.
Upvotes: 2
Views: 1057
Reputation: 965
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();
And then print the list elements.
Upvotes: 1