79685891

Date: 2025-07-01 10:23:13
Score: 1
Natty:
Report link

What I needed to do was:

SwaggerConfiguration oasConfig = new SwaggerConfiguration()
    .openApi(baseModel)
    .readerClass(MyCustomReader.class.getName()) // <- HERE
    .prettyPrint(true)
    .resourcePackages(Set.of("my.api.package"));
public class MyCustomReader extends Reader {

  @Override
  public OpenAPI read(Class<?> cls,
                      String parentPath, 
                      String parentMethod, 
                      boolean isSubresource,
                      RequestBody parentRequestBody, 
                      ApiResponses apiResponses,
                      Set<String> parentTags,
                      List<Parameter> parentParameters,
                      Set<Class<?>> scannedResources)
 {
    OpenAPI openAPI = super.read(cls, parentPath, parentMethod, isSubresource,                parentRequestBody, apiResponses,
      parentTags, parentParameters, scannedResources);
    return populateMissingDescriptions(openAPI);
  }

  public static OpenAPI populateMissingDescriptions(OpenAPI openAPI) {
    if (openAPI.getPaths() != null) {
      for (Entry<String, PathItem> entry : openAPI.getPaths().entrySet()) {
        String path = entry.getKey();
        PathItem pathItem = entry.getValue();
        for (Operation operation : pathItem.readOperations()) {
          if (operation.getResponses() != null) {
            for (Entry<String, ApiResponse> e : operation.getResponses().entrySet()) {
              String status = e.getKey();
              ApiResponse response = e.getValue();
              if (response.getDescription() == null) {
                response.setDescription("");
              }
            }
          }
        }
      }
    }
    return openAPI;
  }
}
Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Starts with a question (0.5): What I
  • Low reputation (1):
Posted by: dmn28