I have a method annotated with @ApiParam as follows:
@RestController
@RequestMapping({LinksBuilder.BASE_URL})
@Api(tags = "Stuff Initiation", description="Stuff Initiation Service")
public class StuffResource {
@ApiOperation(value = "some description", tags = "Stuff Initiation")
@PostMapping(value = "/{stuffProduct}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Stuff InitiationResponse> postInitiateStuff (
@ApiParam(required=true,value="Stuff initiation payload")
@Valid @RequestBody Stuff Initiation stuffInitiation,
@ApiParam(name="stuffProduct", required= true, allowableValues="productStuff1,productStuff2,productStuff3")
@PathVariable String stuffProduct) throws StuffServiceException { ... }
...
}
The issue is that the swagger document generated by springfox (2.9.2) has a "allowEmptyValue":false which is disallowed on a path parameter by the swagger standard.
In an attempt to remedy this, I have implemented a solution similar to springfox hide allowEmptyValue when field annotated with @ApiModelProperty:
package com.example.config;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import com.google.common.base.Optional;
import io.swagger.annotations.ApiParam;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.ParameterBuilderPlugin;
import springfox.documentation.spi.service.contexts.ParameterContext;
import springfox.documentation.swagger.common.SwaggerPluginSupport;
@Component
@Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER + 100)
public class CustomizedParameterBuilderPlugin implements ParameterBuilderPlugin {
@Override
public boolean supports(final DocumentationType arg0) {
return true;
}
@Override
public void apply(ParameterContext context) {
//Optional<ApiModelProperty> annotation = empty();
Optional<ApiParam> apiParam = context.resolvedMethodParameter().findAnnotation(ApiParam.class);
if (apiParam.isPresent()) {
//apiParam.get().allowEmptyValue();
context.parameterBuilder().allowEmptyValue(null);
System.err.println(apiParam.get().name() + "\t" + apiParam.get().type());
}
}
}
I get the right elements, but apparently the setting of context.parameterBuilder().allowEmptyValue(null); doesn't work... the elements are still generated
I am aware that the root cause is a known bug, and is set as status fixed, but I have not got the possibility of using 3.0.0-SNAPSHOT