smallrye / smallrye-open-api

SmallRye implementation of Eclipse MicroProfile OpenAPI
Apache License 2.0
115 stars 89 forks source link

Plain text should not be parsed as JSON #1963

Open cristalp opened 2 weeks ago

cristalp commented 2 weeks ago

This relates to the issue https://github.com/smallrye/smallrye-open-api/issues/1895

The plain text is shown correctly, but during the build I still get messages like

io.smallrye.openapi.runtime.io.JsonIO parseValue
INFO: SROAP02016: JSON value could not be parsed: 1200635948
1201860613
1201901219

This is a list of IDs and is defined like this:

  private static final String RESPONSE_EXAMPLE_IDS =
          "1200635948\n" +
          "1201860613\n" +
          "1201901219";

And in the annotations:

  @GET
  @Path("/expired")
  @Produces(MediaType.TEXT_PLAIN)
  @Operation(summary = "Bla bla")
  @APIResponses(value = {
      @APIResponse(responseCode = "200", description = "Yadda yadda", content = @Content(example = RESPONSE_EXAMPLE_IDS)) })
  public Response getExpired(
    return ...
  }

The method declares that it produces plain text, so the Maven plugin should not try to parse the example return value as JSON.

Note that putting the example within an @ExampleObject shows the same behavior.

Of course, this is only a minor issue.

MikeEdgar commented 2 weeks ago

+1 the scanner should know that reading a response example (or request body example) with a non-JSON media type should not attempt to parse the string.