springfox.documentation.spi.service.contexts.RequestMappingContext Java Examples

The following examples show how to use springfox.documentation.spi.service.contexts.RequestMappingContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PageableParameterBuilderPluginTest.java    From jhipster with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    Method method = this.getClass().getMethod("test", new Class<?>[]{Pageable.class, Integer.class});
    resolver = new TypeResolver();
    RequestHandler handler = new WebMvcRequestHandler(new HandlerMethodResolver(resolver), null, new
        HandlerMethod(this, method));
    DocumentationContext docContext = mock(DocumentationContext.class);
    RequestMappingContext reqContext = new RequestMappingContext(docContext, handler);
    builder = spy(new OperationBuilder(null));
    context = new OperationContext(builder, RequestMethod.GET, reqContext, 0);
    List<TypeNameProviderPlugin> plugins = new LinkedList<>();
    extractor = new TypeNameExtractor(resolver, SimplePluginRegistry.create(plugins), new
        JacksonEnumTypeDeterminer());
    plugin = new PageableParameterBuilderPlugin(extractor, resolver);
}
 
Example #2
Source File: ApiMethodModelsProvider.java    From swagger-more with Apache License 2.0 5 votes vote down vote up
private void collectApiMethodParams(RequestMappingContext context) {
    List<ResolvedMethodParameter> parameterTypes = context.getParameters();
    Optional<ApiMethod> optional = context.findAnnotation(ApiMethod.class);
    OperationModelContextsBuilder builder = context.operationModelsBuilder();
    if (optional.isPresent()) {
        parameterTypes.forEach(parameter -> collectAllTypes(context, parameter).forEach(builder::addInputParam));
    }
}
 
Example #3
Source File: ApiMethodModelsProvider.java    From swagger-more with Apache License 2.0 5 votes vote down vote up
private List<ResolvedType> collectAllTypes(RequestMappingContext context, ResolvedMethodParameter parameter) {
    List<ResolvedType> allTypes = newArrayList();
    for (ResolvedType type : collectBindingTypes(context.alternateFor(parameter.getParameterType()), newArrayList())) {
        ApiModel apiModel = AnnotationUtils.getAnnotation(type.getErasedType(), ApiModel.class);
        allTypes.add(type);
        if (apiModel != null) {
            allTypes.addAll(Arrays.stream(apiModel.subTypes())
                    .filter(subType -> subType.getAnnotation(ApiModel.class) != type.getErasedType().getAnnotation(ApiModel.class))
                    .map(typeResolver::resolve).collect(Collectors.toList()));
        }
    }
    return allTypes;
}
 
Example #4
Source File: SuccessPlugin.java    From BlogManagePlatform with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(RequestMappingContext context) {
	if (context.findAnnotation(ApiResponses.class).isPresent()) {
		return;
	}
	Optional<Success> annotation = context.findAnnotation(Success.class);
	if (!annotation.isPresent()) {
		context.operationModelsBuilder().addReturn(okResult);
		return;
	}
	ResolvedType resolvedType = SwaggerUtil.resolvedType(typeResolver, annotation.get());
	context.operationModelsBuilder().addReturn(resolvedType);
}
 
Example #5
Source File: ApiMethodModelsProvider.java    From swagger-more with Apache License 2.0 4 votes vote down vote up
@Override
public void apply(RequestMappingContext context) {
    collectFromReturnType(context);
    collectApiMethodParams(context);
}
 
Example #6
Source File: ApiMethodModelsProvider.java    From swagger-more with Apache License 2.0 4 votes vote down vote up
private void collectFromReturnType(RequestMappingContext context) {
    ResolvedType modelType = context.alternateFor(context.getReturnType());
    context.operationModelsBuilder().addReturn(modelType);
}
 
Example #7
Source File: ApiListingJsonScanner.java    From Resource with GNU General Public License v3.0 4 votes vote down vote up
public Multimap<String, ApiListing> scan(ApiListingScanningContext context)
{
    final Multimap<String, ApiListing> apiListingMap = LinkedListMultimap.create();
    int position = 0;
    Map<ResourceGroup, List<RequestMappingContext>> requestMappingsByResourceGroup
        = context.getRequestMappingsByResourceGroup();
    Collection<ApiDescription> additionalListings = pluginsManager.additionalListings(context);
    Set<ResourceGroup> allResourceGroups = from(collectResourceGroups(additionalListings))
        .append(requestMappingsByResourceGroup.keySet())
        .toSet();

    List<SecurityReference> securityReferences = newArrayList();
    for (final ResourceGroup resourceGroup : sortedByName(allResourceGroups))
    {

        DocumentationContext documentationContext = context.getDocumentationContext();
        Set<String> produces = new LinkedHashSet<String>(documentationContext.getProduces());
        Set<String> consumes = new LinkedHashSet<String>(documentationContext.getConsumes());
        String host = documentationContext.getHost();
        Set<String> protocols = new LinkedHashSet<String>(documentationContext.getProtocols());
        Set<ApiDescription> apiDescriptions = newHashSet();

        Map<String, Model> models = new LinkedHashMap<String, Model>();
        List<RequestMappingContext> requestMappings = nullToEmptyList(
            requestMappingsByResourceGroup.get(resourceGroup));

        for (RequestMappingContext each : sortedByMethods(requestMappings))
        {//url
            Map<String, Model> knownModels = new HashMap<>();
            models.putAll(apiModelReader.read(each.withKnownModels(models)));

            apiDescriptions.addAll(apiDescriptionReader.read(each));
        }
        //
        models.putAll(ModelCache.getInstance().getKnownModels());

        List<ApiDescription> additional = from(additionalListings)
            .filter(and(
                belongsTo(resourceGroup.getGroupName()),
                onlySelectedApis(documentationContext)))
            .toList();
        apiDescriptions.addAll(additional);

        List<ApiDescription> sortedApis = from(apiDescriptions)
            .toSortedList(documentationContext.getApiDescriptionOrdering());
        Optional<String> o = longestCommonPath(sortedApis);
        String resourcePath = new ResourcePathProvider(resourceGroup)
            .resourcePath()
            .or(o)
            .orNull();

        PathProvider pathProvider = documentationContext.getPathProvider();
        String basePath = pathProvider.getApplicationBasePath();
        PathAdjuster adjuster = new PathMappingAdjuster(documentationContext);
        ApiListingBuilder apiListingBuilder = new ApiListingBuilder(context.apiDescriptionOrdering())
            .apiVersion(documentationContext.getApiInfo().getVersion())
            .basePath(adjuster.adjustedPath(basePath))
            .resourcePath(resourcePath)
            .produces(produces)
            .consumes(consumes)
            .host(host)
            .protocols(protocols)
            .securityReferences(securityReferences)
            .apis(sortedApis)
            .models(models)
            .position(position++)
            .availableTags(documentationContext.getTags());

        ApiListingContext apiListingContext = new ApiListingContext(
            context.getDocumentationType(),
            resourceGroup,
            apiListingBuilder);
        apiListingMap.put(resourceGroup.getGroupName(), pluginsManager.apiListing(apiListingContext));
    }
    return apiListingMap;
}
 
Example #8
Source File: ApiListingJsonScanner.java    From Resource with GNU General Public License v3.0 4 votes vote down vote up
private Iterable<RequestMappingContext> sortedByMethods(List<RequestMappingContext> contexts)
{
    return contexts.stream().sorted(methodComparator()).collect(toList());
}