swagger-core
swagger-core copied to clipboard
Custom resolver not intercepting 'resolveDescription'
My goal is to check every description attribute value, and if that value starts with "file://" attempt to load the file from the resources. I am doing this because some description blocks are very large and are written in markdown which benefit from an editor which renders the view. Presently, it seems the converter is not being applied. If there is a better way to achieve this goal I am open to any input.
Example annotation usage
@OpenAPIDefinition(
info = @Info(
title = "GoTo Devices API",
version = "1.0",
description = "file://api_description.md"
)
)
My custom converter
public class CustomConverter extends ModelResolver {
public CustomConverter() {
super(new ObjectMapper());
}
public CustomConverter(ObjectMapper mapper) {
super(mapper);
}
@Override
protected String resolveDescription(Annotated a, Annotation[] annotations, io.swagger.v3.oas.annotations.media.Schema schema) {
if (schema == null) {
return null;
}
var text = schema.description();
if (Strings.isNullOrEmpty(text)) {
return null;
}
if (text.startsWith("file://")) {
return loadFromFile(text.substring(7));
}
return text;
}
protected String loadFromFile(String filename) { return "magic load here" }
}
Registering the converter in pom.xml plugin configuration
<modelConverterClasses>com.sample.CustomConverter</modelConverterClasses>