Aezio
Aezio

Reputation: 213

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

swagger model details here

Upvotes: 4

Views: 2839

Answers (1)

aciobanu
aciobanu

Reputation: 389

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.

Upvotes: 1

Related Questions