【发布时间】:2021-01-31 12:14:44
【问题描述】:
我有以下架构。
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="sampleRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="Lookup" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="accountidtgroup">
<xs:complexType>
<xs:sequence>
<xs:element name="accountIDType" type="xs:string" />
<xs:element name="accountIDValue" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sysPlanID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sampleResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="Dummy" type="xs:string"/>
<xs:element name="OriginalReq">
<xs:complexType>
<xs:sequence>
<xs:element ref="sampleRequest"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我从中生成类并且一切正常,除了“查找”元素的大小写在 Swagger UI 中转换为小写(从技术上讲,它是对象名称),而它实际上应该是“查找”。如果我只是删除/注释掉 sampleRequest 中的“OriginalReq”元素,重新构建并重新启动我的应用程序,“Lookup”元素的情况在请求中显示得很好。这里要注意的重要一点是,“OriginalReq”元素实际上是对“sampleRequest”元素本身的引用,这是问题的根本原因。
这是我的 pom 依赖项
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
我做了一些调查,早期版本的 springfox 在 Jaxb 注释方面存在问题,但在以后的版本中已修复。证明是响应中的“虚拟”元素出现在正确的情况下,如果我在 @XmlElement 注释中手动将其更改为其他内容,我可以看到更新的值,这意味着注释已得到尊重,但对于 Lookup 元素它没有不工作。所以问题只在于嵌套元素具有公共元素的情况。
之前有没有人遇到过类似的问题,或者是否有解决方法?
【问题讨论】:
标签: spring-boot swagger springfox rest