简体   繁体   中英

Nested object is not shown in Swagger documentation

I'm working with swagger-springfox on version 2.9.2, I encountered a problem with incomplete display of multiple nested objects. I have a class named AddEntityCaseReq and the structure below. When I visited the swagger-ui.html , there is nothing in the Properties . I have marked @ApiModel and @ApiModelProperties on each class. Is there anything missing?

This is the class structure

AddEntityCaseReq
├── id
└── List<UploadDocuments> uploadDocuments;
    └── Properties
          ├── id
          └── name

This is the controller code

    @ResponseBody
    @RequestMapping(value = "/addEntityCase", method = RequestMethod.POST)
    @ApiOperation(value = "add entity case", notes = "add entity case")
    @ApiImplicitParam(name = "addEntityCaseReq", value = "reuqest",
            required = true, dataType = "AddEntityCaseReq")
    public CommonResp<Boolean> addEntityCase(@RequestBody AddEntityCaseReq addEntityCaseReq) {
        return addEntityCase.execute(addEntityCaseReq);
    }

swagger model details here

招摇模型细节在这里

If you have class hierarchies in openapi you might see only the base class in the swagger ui. What you could do is to force the mapping for a base class for a richer subclass, in the configuration:

    return new Docket(DocumentationType.SWAGGER_2)
            .securitySchemes(schemeList)
            .alternateTypeRules( AlternateTypeRules.newRule(
                    typeResolver.resolve(LocalDate.class),
                    typeResolver.resolve(Date.class), Ordered.HIGHEST_PRECEDENCE),
                    AlternateTypeRules.newRule(
                            typeResolver.resolve(List.class, LocalDate.class),
                            typeResolver.resolve(List.class, String.class), Ordered.HIGHEST_PRECEDENCE),
                    AlternateTypeRules.newRule(
                            typeResolver.resolve(List.class, YourBaseClass.class),
                            typeResolver.resolve(List.class, YourRicherSubclass.class), Ordered.HIGHEST_PRECEDENCE)

            )
            .select()

This is an example for mapping lists, but it would work the same for standard objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM