Validator try to parse text/plain request as JSON
Issue #94
resolved
Hello,
I'm facing a strange behavior when I try to validate server against my API using mockmvc.
The text/plain input is in csv format, I don't expect any validation on that, it's a string that's all.
I end up with the error: java.lang.AssertionError: Validation failed. [ERROR] Unable to parse JSON - Unrecognized token 'Test': was expecting ('true', 'false' or 'null')
Here is the unit test:
@Test
public void testComplianceWithAPI()
{
try
{
byte[] inputContent = Files.readAllBytes(
Paths.get(ResourceUtils.getURL(INPUT_CSV_FILE_PATH).toURI()));
mockMvc.perform(post(URL_TEMPLATE)
.contentType(MediaType.TEXT_PLAIN)
.accept(MediaType.APPLICATION_JSON)
.content(inputContent))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(swagger().isValid(SCANALGO_API_PATH));
}
catch (Exception ex)
{
ex.printStackTrace();
Assert.fail(ex.getMessage());
}
}
And here is the signature of the webservice I try to validate:
@PostMapping(consumes = MediaType.TEXT_PLAIN_VALUE, produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
public TranslationInput convert(@RequestBody String pPld) throws IOException
Can you reproduce that bug?
Is there a work around to exclude some request validation?
Comments (3)
-
-
Any news on this bug?
-
- changed status to resolved
Available in v1.4.2
- Log in to comment
Thanks for raising this. I'll try to reproduce the bug this week.