private Map<String, Model> readParametersApiModel( HandlerMethodResolver handlerMethodResolver, SwaggerGlobalSettings settings, HandlerMethod handlerMethod) { Method method = handlerMethod.getMethod(); Map<String, Model> modelMap = newHashMap(); log.debug( "Reading parameters models for handlerMethod |{}|", handlerMethod.getMethod().getName()); List<ResolvedMethodParameter> parameterTypes = handlerMethodResolver.methodParameters(handlerMethod); Annotation[][] annotations = method.getParameterAnnotations(); for (int i = 0; i < annotations.length; i++) { Annotation[] pAnnotations = annotations[i]; for (Annotation annotation : pAnnotations) { if (annotation instanceof RequestBody) { ResolvedMethodParameter pType = parameterTypes.get(i); if (!settings .getIgnorableParameterTypes() .contains(pType.getResolvedParameterType().getErasedType())) { ModelContext modelContext = ModelContext.inputParam(pType.getResolvedParameterType()); markIgnorablesAsHasSeen(settings.getIgnorableParameterTypes(), modelContext); Optional<Model> pModel = modelProvider.modelFor(modelContext); if (pModel.isPresent()) { log.debug( "Swagger generated parameter model id: {}, name: {}, schema: {} models", pModel.get().id(), pModel.get().name()); modelMap.put(pModel.get().id(), pModel.get()); } else { log.debug( "Swagger core did not find any parameter models for {}", pType.getResolvedParameterType()); } populateDependencies(modelContext, modelMap); } } } } log.debug( "Finished reading parameters models for handlerMethod |{}|", handlerMethod.getMethod().getName()); return modelMap; }
@PostConstruct public void initialize() { List<ApiListingReference> apiListingReferences = new ArrayList<ApiListingReference>(); if (null != apiListingReferenceScanner) { apiListingReferenceScanner.scan(); apiListingReferences = apiListingReferenceScanner.getApiListingReferences(); Map<ResourceGroup, List<RequestMappingContext>> resourceGroupRequestMappings = apiListingReferenceScanner.getResourceGroupRequestMappings(); TypeResolver typeResolver = swaggerGlobalSettings.getTypeResolver(); DefaultModelPropertiesProvider propertiesProvider = new DefaultModelPropertiesProvider( new ObjectMapper(), // DK TODO: Autowire this new AccessorsProvider(typeResolver), new FieldsProvider(typeResolver)); ModelDependencyProvider dependencyProvider = new ModelDependencyProvider(typeResolver, propertiesProvider); DefaultModelProvider modelProvider = new DefaultModelProvider(typeResolver, propertiesProvider, dependencyProvider); ApiListingScanner apiListingScanner = new ApiListingScanner( resourceGroupRequestMappings, swaggerPathProvider, modelProvider, authorizationContext); apiListingScanner.setSwaggerGlobalSettings(swaggerGlobalSettings); Map<String, ApiListing> apiListings = apiListingScanner.scan(); swaggerCache.addApiListings(apiListings); } else { log.error("ApiListingReferenceScanner not configured"); } ResourceListing resourceListing = new ResourceListing( "1", SwaggerSpec.version(), toScalaList(apiListingReferences), toScalaList(authorizationTypes), toOption(apiInfo)); swaggerCache.addSwaggerResourceListing(swaggerGroup, resourceListing); }
@Override public void execute(RequestMappingContext context) { HandlerMethod handlerMethod = context.getHandlerMethod(); log.debug("Reading models for handlerMethod |{}|", handlerMethod.getMethod().getName()); Map<String, Model> modelMap = newHashMap(); SwaggerGlobalSettings swaggerGlobalSettings = (SwaggerGlobalSettings) context.get("swaggerGlobalSettings"); HandlerMethodResolver handlerMethodResolver = new HandlerMethodResolver(swaggerGlobalSettings.getTypeResolver()); ResolvedType modelType = ModelUtils.handlerReturnType(swaggerGlobalSettings.getTypeResolver(), handlerMethod); ApiOperation apiOperationAnnotation = handlerMethod.getMethodAnnotation(ApiOperation.class); if (null != apiOperationAnnotation && Void.class != apiOperationAnnotation.response()) { modelType = asResolved(swaggerGlobalSettings.getTypeResolver(), apiOperationAnnotation.response()); } if (!swaggerGlobalSettings.getIgnorableParameterTypes().contains(modelType.getErasedType())) { ModelContext modelContext = ModelContext.returnValue(modelType); markIgnorablesAsHasSeen(swaggerGlobalSettings.getIgnorableParameterTypes(), modelContext); Optional<Model> model = modelProvider.modelFor(modelContext); if (model.isPresent() && !"void".equals(model.get().name())) { log.debug( "Swagger generated parameter model id: {}, name: {}, schema: {} models", model.get().id(), model.get().name()); modelMap.put(model.get().id(), model.get()); } else { log.debug("Swagger core did not find any models"); } populateDependencies(modelContext, modelMap); } modelMap.putAll( readParametersApiModel(handlerMethodResolver, swaggerGlobalSettings, handlerMethod)); log.debug( "Finished reading models for handlerMethod |{}|", handlerMethod.getMethod().getName()); context.put("models", modelMap); }