smallrye-open-api icon indicating copy to clipboard operation
smallrye-open-api copied to clipboard

Plain text should not be parsed as JSON

Open cristalp opened this issue 1 year ago • 1 comments

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.

cristalp avatar Aug 26 '24 08:08 cristalp

+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.

MikeEdgar avatar Aug 28 '24 11:08 MikeEdgar

@MikeEdgar same problem for QueryParams:

@Parameter(example = "2019-05-02T09:51:25.265") @QueryParam("createDateTimeMax") public LocalDateTime createDateTimeMax;

2024-11-12 15:42:44,876 INFO [io.sma.ope.run.io] (build-51) SROAP02016: JSON value could not be parsed: 2019-02-02T09:51:25.265

Postremus avatar Nov 12 '24 15:11 Postremus