Skip to content

Instantly share code, notes, and snippets.

@shederman
Created June 4, 2020 10:15
Show Gist options
  • Save shederman/b6f7d18fdaca8f42cac4ba04c4c2d549 to your computer and use it in GitHub Desktop.
Save shederman/b6f7d18fdaca8f42cac4ba04c4c2d549 to your computer and use it in GitHub Desktop.
SpringFox Order Bug
package com.payzilch.customer.framework.util;
import static com.google.common.base.Strings.isNullOrEmpty;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import com.fasterxml.classmate.TypeResolver;
import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import springfox.documentation.builders.OperationBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.ResponseMessageBuilder;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.schema.ModelReference;
import springfox.documentation.service.ApiDescription;
import springfox.documentation.service.Header;
import springfox.documentation.service.ObjectVendorExtension;
import springfox.documentation.service.Operation;
import springfox.documentation.service.Parameter;
import springfox.documentation.service.StringVendorExtension;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.ApiListingScannerPlugin;
import springfox.documentation.spi.service.contexts.DocumentationContext;
import springfox.documentation.spring.web.readers.operation.CachingOperationNameGenerator;
import springfox.documentation.swagger.common.SwaggerPluginSupport;
@Component
@Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER + 1000030)
public class CustomLisingScannerPlugin implements ApiListingScannerPlugin {
private static final Logger logger = LoggerFactory.getLogger(CustomAwsCorsPlugin.class);
@Override
public List<ApiDescription> apply(DocumentationContext context) {
List<ApiDescription> descps = new ArrayList<>();
logger.debug("{} API Operations to apply", CustomAwsExtensionsReader.getOperationPaths().size());
return descps;
}
@Override
public boolean supports(DocumentationType documentationType) {
return true;
}
}
package com.payzilch.customer.framework.util;
import static com.google.common.base.Strings.isNullOrEmpty;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.google.common.base.Optional;
import com.payzilch.framework.util.Helper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import springfox.documentation.service.ObjectVendorExtension;
import springfox.documentation.service.ResolvedMethodParameter;
import springfox.documentation.service.StringVendorExtension;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.OperationBuilderPlugin;
import springfox.documentation.spi.service.contexts.OperationContext;
import springfox.documentation.swagger.common.SwaggerPluginSupport;
@Component
@Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER + 10031)
public class CustomOperationBuilderPlugin implements OperationBuilderPlugin {
private static final Logger logger = LoggerFactory.getLogger(CustomAwsExtensionsReader.class);
private static List<String> operations = new ArrayList<String>();
@SuppressWarnings("rawtypes")
@Override
public void apply(OperationContext context) {
Optional<ApiOperation> apiOperationOperational = context.findAnnotation(ApiOperation.class);
Optional<PostMapping> postMapping = context.findAnnotation(PostMapping.class);
Optional<GetMapping> getMapping = context.findAnnotation(GetMapping.class);
if (apiOperationOperational.isPresent()) {
ApiOperation apiOperation = apiOperationOperational.get();
logger.debug("API Operation {}, {} {} {}", context.getName(), context.requestMappingPattern(), apiOperation.httpMethod(), apiOperation.nickname());
operations.add(context.requestMappingPattern());
}
}
@Override
public boolean supports(DocumentationType delimiter) {
return SwaggerPluginSupport.pluginDoesApply(delimiter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment