如何让Quarkus Swagger识别JsonSerialize(as=),JsonDeserialize(as=)

如何让Quarkus Swagger识别JsonSerialize(as=),JsonDeserialize(as=),swagger,quarkus,Swagger,Quarkus,我正在使用Quarkus 1.10.3.Final(包括Quarkus resteasy jackson和Quarkus smallrye openapi)和Immutables库(org.immmutables:value:2.8.8)定义各种应用程序模型。我的问题是,Swagger UI似乎无法识别标准的jackson@JsonSerialize(as=)和@jsonderialize(as=)注释 在下面定义的模型示例中,我希望在Swagger UI页面的components部分中看到四(

我正在使用Quarkus 1.10.3.Final(包括Quarkus resteasy jackson和Quarkus smallrye openapi)和Immutables库(org.immmutables:value:2.8.8)定义各种应用程序模型。我的问题是,Swagger UI似乎无法识别标准的jackson@JsonSerialize(as=)和@jsonderialize(as=)注释

在下面定义的模型示例中,我希望在Swagger UI页面的components部分中看到四(4)个字段

范例 但是,当查看Swagger UI页面时,生成的组件显示为空对象:

Swigger UI中的这个问题在Swigger UI版本中得到了解决,随后在Swigger UI 2.0中被删除,然后在中再次修复

在所有这些引导之后,我的问题很简单:

  • 除了放弃不可变之外,还有人知道变通方法吗

在深入研究smallrye openapi的源代码之后,您可以向每个不可变字段添加@Schema注释,即

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = ImmutableFieldMetaData.class)
@JsonSerialize(as = ImmutableFieldMetaData.class)
@Value.Immutable
@Schema(implementation = ImmutableFieldMetaData.class)
public interface FieldMetaData {
  String field();
  String type();
  Boolean deprecated();
  String description();
}

如果需要,您也可以将字段注释为@Schema。

请阅读:如何生成OpenAPI定义?您使用的是
quarkus smallrye openapi
maven依赖项吗?您使用的是
quarkus resteasy jackson
还是
quarkus resteasy jsonb
?虽然quarkus通过jackson提供json-b(反)序列化,但接口不同,不可变库仅声明与jackson兼容。我使用的是quarks smallrye openapi和quarkus resteasy jackson。
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = ImmutableFieldMetaData.class)
@JsonSerialize(as = ImmutableFieldMetaData.class)
@Value.Immutable
@Schema(implementation = ImmutableFieldMetaData.class)
public interface FieldMetaData {
  String field();
  String type();
  Boolean deprecated();
  String description();
}