I've got a Java project using Swagger. It does a great job of generating the swagger.json, but it's listing all the output fields as optional and I need some of them to be required. That's not a problem for my code because I can add the @ApiModelProperty annotation and specify whether it's required.
The problem is with objects from 3rd party jars. I can't go annotate that code. How do I create the equivalent functionality of @ApiModelProperty on 3rd party code?
Let's assume we're talking about newer version of swagger / openAPI. You can kludge this with a
ReaderListener
, something like so:And then register this in your code using:
jersey.register(FixSwagger.class);
The
beforeScan()
andafterScan()
methods allow you to mutate theopenAPI
object, so you can programatically change whatever you need to.