Swagger-UI не работает со сложными объектами - PullRequest
0 голосов
/ 13 мая 2019

Когда у объекта есть другой объект cutom, я получаю сообщение об ошибке от swaggerUi: ​​

Вызвано: java.lang.NoSuchMethodError: io.swagger.models.properties.RefProperty. (Ljava / lang / String; Lio / swagger / models / refs / RefFormat;) V

enter image description here

Версия Swagger: 2.9.2 (https://mvnrepository.com/artifact/io.springfox/springfox-swagger2/2.9.2, https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui/2.9.2), Java 11.

Если я изменяю тип объекта поля sender на String, он работает нормально, но я хочу, чтобы он работал с пользовательским объектом.

@Getter // lombok here
@Setter
@AllArgsConstructor
@XmlRootElement(name = "r")
@NoArgsConstructor
public class RDto {
    private String id;
    private String number;
    private String status;
    private String error;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@XmlRootElement(name="TDto")
public class MDto {
    RDto sender; // If changed to String -> works fine
}
@Component
public class CamelConfig extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        restConfiguration().component("servlet") // configure we want to use servlet as the component for the rest DSL
                .bindingMode(RestBindingMode.json_xml) // enable json/xml binding mode
                .dataFormatProperty("prettyPrint", "true") // output using pretty print
                .contextPath("/con/api/")
                .apiContextPath("/api-doc")  // enable swagger api
                .apiProperty("api.version", "2.0.0")
                .apiProperty("api.title", "title")
                .apiProperty("api.description", "descr")
                .apiProperty("api.contact.name", "Aaa")
                .apiProperty("cors", "true"); // enable CORS

        // error handling to return custom HTTP status codes for the various exceptions
        onException(TestMessageException.class)
                .handled(true)
                // use HTTP status 400 when input data is invalid
                .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(400))
                .setBody(simple("Invalid input data"));

        rest()
                .description("rest service provider")
                .consumes("application/xml").produces("application/xml")
                .post("/send").type(MDto.class)
                .bindingMode(RestBindingMode.json_xml).description("test")
                .route().routeId("REST test").log("Message send: \n ${body}")
                .to("bean:MService?method=test")
                .endRest();
    }
}

1 Ответ

0 голосов
/ 13 мая 2019

Я изменил зависимости (добавив исключения):

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>${swagger.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>swagger-annotations</artifactId>
                <groupId>io.swagger</groupId>
            </exclusion>
            <exclusion>
                <artifactId>swagger-models</artifactId>
                <groupId>io.swagger</groupId>
            </exclusion>
        </exclusions>
    </dependency>

Потому что я использую верблюжьего чванства

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring-boot</artifactId>
        <version>3.0.0-M2</version>
        <!--<version>2.23.2</version>-->
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-swagger-java</artifactId>
        <version>3.0.0-M2</version>
        <!-- use the same version as your Camel core version -->
    </dependency>
...