Open FangmingD opened 10 years ago
I think that one uses com.wordnik.swagger.converter.ModelConverters to config the Swagger as following ModelConverters.addConverter(new CustomConverter(), true)
Here is the workaround I've found for this: 1) Implement "true" SwaggerFilter and add the ModelConverters.addConverter in constructor with true as second argument (this will add it as first converter):
// ommitted the imports
public class SwaggerFilter implements SwaggerSpecFilter {
private static final Logger LOGGER = LoggerFactory.getLogger(SwaggerFilter.class);
public SwaggerFilter() {
LOGGER.debug("Adding Model Converter.");
// adding model converter you have there
// the lines below will add this converter to the swagger as the first converter to use in the list
ModelConverters.addConverter(new CustomConverter(), true);
}
@Override
public boolean isOperationAllowed(Operation operation, ApiDescription apiDescription,
Map<String, List<String>> params, Map<String, String> cookies,
Map<String, List<String>> headers) {
// return true to allow any operations
return true;
}
@Override
public boolean isParamAllowed(Parameter parameter, Operation op, ApiDescription api,
Map<String, List<String>> params, Map<String, String> cookies,
Map<String, List<String>> headers) {
// return true to allow any parameters
return true;
}
}
2) Add the filter to the maven config:
<swaggerInternalFilter>your.company.SwaggerFilter</swaggerInternalFilter>
Also Note that latest (currently I'm using v2.3) is using different version of swagger core that you've mentioned (in the code you have you're implementing the class from the different swagger-core version). So, that latest CustomConverter read override will look like:
// .....
public class CustomConverter extends SwaggerSchemaConverter {
// .....
@Override
public Option<Model> read(Class<?> cls, Map<String, String> typeMap) {
// implement here
}
}
I have a class to override SwaggerSchemaConverter for generating the swagger models. It's working with my rest api and swagger ui.
like
but I'm not sure how this class can be called through this mavn-swagger plugin