[英]XML examples in springdoc-openapi, swagger UI
I'm struggling with generation of correct XML examples in springdoc-openapi library.我正在努力在springdoc-openapi库中生成正确的 XML 示例。
Controller: Controller:
@RestController
@RequestMapping(produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public class MyController {
@GetMapping
public MonetaryValue getMonetaryValue() {
return new MonetaryValue(BigDecimal.ONE, "EUR");
}
}
Model Model
@Schema(name="price", description = "Monetary value")
@JacksonXmlRootElement(localName = "price")
public class MonetaryValue {
@Schema(example = "EUR")
@JsonProperty("cur")
@JacksonXmlProperty(localName = "cur", isAttribute = true)
private String currency;
@Schema(example = "1.00")
@JsonProperty("val")
@JacksonXmlText
private BigDecimal value;
// getters, setter ...
}
End point called with header Accept: application/xml
returns expected result:使用 header 调用的端点
Accept: application/xml
返回预期结果:
<price cur="EUR">1</price>
However it seems that Jackson annotations are ignored in springdoc.但是,springdoc 中似乎忽略了 Jackson 注释。 Example shown in swagger-ui shows:
swagger-ui 中显示的示例显示:
<value>
<cur>EUR</cur>
<val>1</val>
</value>
I have also tried to add JAXB annotations.我还尝试添加 JAXB 注释。
@Schema(name="price", description = "Monetary value")
@JacksonXmlRootElement(localName = "price")
public class MonetaryValue {
@Schema(example = "EUR")
@JsonProperty("cur")
@JacksonXmlProperty(localName = "cur", isAttribute = true)
@XmlAttribute(name = "cur")
private String currency;
@Schema(example = "1.00")
@JsonProperty("val")
@JacksonXmlText
@XmlValue
private BigDecimal value;
// getters, setter ...
}
It partly helped, attribute is shown correctly, but @XmlValue
annotation seems to be is ignored.它在一定程度上有所帮助,属性显示正确,但
@XmlValue
注释似乎被忽略了。 Value is shown in sub-element val
instead of element's text.值显示在子元素
val
中,而不是元素的文本中。
<value cur="EUR">
<val>1</val>
</value>
JSON examples work without any problem. JSON 示例可以正常工作。
Demo project on GitHub . GitHub 上的演示项目。
Thanks for help.感谢帮助。
This is an issue with the OpenAPI spec.这是 OpenAPI 规范的一个问题。
<value cur="EUR">1</value>
The XML structure you want to achieve is not supported by OpenAPI. OpenAPI不支持你想要实现的XML结构。
There is a GitHub issue tracking this: https://github.com/OAI/OpenAPI-Specification/issues/630有一个跟踪此问题的 GitHub 问题: https://github.com/OAI/OpenAPI-Specification/issues/630
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.