smallrye / smallrye-open-api

SmallRye implementation of Eclipse MicroProfile OpenAPI
Apache License 2.0
113 stars 87 forks source link

Null values in JSON examples are suppressed in OpenAPI YAML #1773

Closed cristalp closed 3 months ago

cristalp commented 3 months ago

When I specify an example in the OpenAPI annotations, like

  static final String RESPONSE_ALL =
    """
      {
        "foo": "bar",
        "baz": null
      }
    """;

then in the OpenAPI YAML, the null value is suppressed and thus doesn't appear in the SwaggerUI.

Michael Edgar helped me with this on Stackoverflow: https://stackoverflow.com/questions/78140810/quarkus-and-openapi-swaggerui-why-are-null-values-in-json-examples-suppresse According to him this is the part of the code that suppresses null values: https://github.com/smallrye/smallrye-open-api/blob/4389f3ab7af8b15b22789af598fa1c1baecf9378/core/src/main/java/io/smallrye/openapi/runtime/io/ObjectWriter.java#L76-L78

Since a null value is ok according to JSON specs, the null value should also appear in OpenAPI.

MikeEdgar commented 3 months ago

@cristalp , I went to try and reproduce this problem and it turns out it was fixed by #1759, which was just merged to main today, and will be in the 3.11 release :rocket: Once I finish #1774, the release will happen, probably next week some time if everything goes well.

I'll close this issue now since it's been fixed in main, so watch for 3.11 and you can try it out when it's released.

cristalp commented 3 months ago

Great, thanks a lot!