0

我正在使用 Springfox 3.0 并有一个具有如下方法的 Controller 类:

@PostMapping
@ResponseBody
public Mono<MyResponseModel> contact(
        @ApiParam(
                value = "Contains authentication and account details.",
                required = true
        )
        @Authorization(
                mustBeConfirmed = true,
                mustNotBeModerated = true
        )
        final MyImportedPOJO myImportedPOJO,
        @ApiParam(
                value = "The main request model"
        )
        @Validated @RequestBody
        final MyRequestModel myRequestModel
     ) {...}

但是,在此 API 调用的 swagger-ui 页面中,它列出了 的所有成员,MyImportedPOJO就好像它们是单独的参数一样,就像这样,但它识别MyRequestModel为一个对象:

authorization.confirmed
boolean
(query)

authorization.moderated
boolean
(query)

myRequestModel *required
object
(body)

我不知道它是否相关,但MyImportedPOJO来自我正在导入的库,所以我不能向它添加任何注释。

这就是我设置 Springfox 的方式: 在 build.gradle 中:

compile 'io.springfox:springfox-swagger2:3.0.0'
compile 'io.springfox:springfox-swagger-ui:3.0.0'
compile 'io.springfox:springfox-boot-starter:3.0.0'

在我的MvcWebConfig

@Slf4j
@Configuration
@EnableSwagger2
@Import({SpringDataRestConfiguration.class, BeanValidatorPluginsConfiguration.class})
public class MvcWebConfig implements WebMvcConfigurer {

    @Autowired
    private TypeResolver resolver;

    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                .ignoredParameterTypes(LoggingContext.class)
                // Added this line to (successfully) make it appear in the Models section
                // of Swagger, but it still doesn't recognize it as an API Param
                .additionalModels(resolver.resolve(MyImportedPOJO.class))
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("My Webapp")
                .description("Does webapp things")
                .build();
    }
}
4

0 回答 0