String httpMethod = operationEntry.getKey().name(); OperationMeta operationMeta = new OperationMeta(); operationMeta.init(this, method, strPath, httpMethod, operation);
@Override public String resolve(HttpMethod httpMethod, String pathname, Operation operation) { return httpMethod.name() + pathname.replaceAll("-", "_").replaceAll("/", "_").replaceAll("[{}]", ""); } }
private String computeServiceId(String pathname, Entry<HttpMethod, Operation> entry) { String operationId = entry.getValue().getOperationId(); return (operationId != null) ? operationId : entry.getKey().name() + pathname.replaceAll("-", "_").replaceAll("/", "_").replaceAll("[{}]", ""); }
private boolean isOperationNotExist(Map.Entry<HttpMethod, Operation> entry, String uri, Map<String, UriTemplate> uriTemplateMap, String securityName) { HttpMethod httpMethod = entry.getKey(); Operation operation = entry.getValue(); String operationId = APIUtils.generateOperationIdFromPath(uri, httpMethod.name()); if (uriTemplateMap.containsKey(operationId)) { assignScopesToOperation(operation, securityName, uriTemplateMap.get(operationId).getScopes()); uriTemplateMap.remove(operationId); return false; } else { return true; } }
private boolean isOperationNotExist(Map.Entry<HttpMethod, Operation> entry, String uri, Map<String, UriTemplate> uriTemplateMap, String securityName) { HttpMethod httpMethod = entry.getKey(); Operation operation = entry.getValue(); String operationId = APIUtils.generateOperationIdFromPath(uri, httpMethod.name()); if (uriTemplateMap.containsKey(operationId)) { assignScopesToOperation(operation, securityName, uriTemplateMap.get(operationId).getScopes()); uriTemplateMap.remove(operationId); return false; } else { return true; } }
private boolean isPathNotExist(Map<String, UriTemplate> uriTemplateMap, String securityName, Map.Entry<String, Path> entry) { Path path = entry.getValue(); String uri = entry.getKey(); path.getOperationMap().entrySet().forEach(httpMethodOperationEntry -> { if (isOperationNotExist(httpMethodOperationEntry, uri, uriTemplateMap, securityName)) { path.set(httpMethodOperationEntry.getKey().name().toLowerCase(), null); } }); return path.isEmpty(); }
private boolean isPathNotExist(Map<String, UriTemplate> uriTemplateMap, String securityName, Map.Entry<String, Path> entry) { Path path = entry.getValue(); String uri = entry.getKey(); path.getOperationMap().entrySet().forEach(httpMethodOperationEntry -> { if (isOperationNotExist(httpMethodOperationEntry, uri, uriTemplateMap, securityName)) { path.set(httpMethodOperationEntry.getKey().name().toLowerCase(), null); } }); return path.isEmpty(); }
public static OperationDescription operationDescriptionOf(final Swagger swagger, final Operation operation, final BiFunction<String, String, String> consumer) { final Entry<String, Path> pathEntry = swagger.getPaths().entrySet().stream() .filter(e -> e.getValue().getOperations().contains(operation)).findFirst().get(); final String path = pathEntry.getKey(); final Entry<HttpMethod, Operation> operationEntry = pathEntry.getValue().getOperationMap().entrySet().stream() .filter(e -> e.getValue().equals(operation)).findFirst().get(); final HttpMethod method = operationEntry.getKey(); final String specifiedSummary = trimToNull(operation.getSummary()); final String specifiedDescription = trimToNull(operation.getDescription()); final String name = ofNullable(toLiteralNull(specifiedSummary)).orElseGet(() -> method + " " + path); final String description = ofNullable(toLiteralNull(specifiedDescription)) .orElseGet(() -> consumer.apply(method.name(), path)); return new OperationDescription(name, description); }
continue; if (StringUtils.isBlank(httpMethod) && !requestMethod.equalsIgnoreCase(HttpMethod.POST.name())) continue;
@Override public String getHttpMethod(ReaderContext context, Method method) { final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); return apiOperation == null || StringUtils.isEmpty(apiOperation.httpMethod()) ? HttpMethod.POST.name() : apiOperation.httpMethod(); }
@Override public Producer createProducer() throws Exception { final CamelContext camelContext = getCamelContext(); final Swagger swagger = loadSpecificationFrom(camelContext, specificationUri); final Map<String, Path> paths = swagger.getPaths(); for (final Entry<String, Path> pathEntry : paths.entrySet()) { final Path path = pathEntry.getValue(); final Optional<Entry<HttpMethod, Operation>> maybeOperationEntry = path.getOperationMap().entrySet() .stream().filter(operationEntry -> operationId.equals(operationEntry.getValue().getOperationId())) .findAny(); if (maybeOperationEntry.isPresent()) { final Entry<HttpMethod, Operation> operationEntry = maybeOperationEntry.get(); final Operation operation = operationEntry.getValue(); final Map<String, Parameter> pathParameters = operation.getParameters().stream() .filter(p -> "path".equals(p.getIn())) .collect(Collectors.toMap(Parameter::getName, Function.identity())); final String uriTemplate = resolveUri(pathEntry.getKey(), pathParameters); final HttpMethod httpMethod = operationEntry.getKey(); final String method = httpMethod.name(); return createProducerFor(swagger, operation, method, uriTemplate); } } final String supportedOperations = paths.values().stream().flatMap(p -> p.getOperations().stream()) .map(Operation::getOperationId).collect(Collectors.joining(", ")); throw new IllegalArgumentException("The specified operation with ID: `" + operationId + "` cannot be found in the Swagger specification loaded from `" + specificationUri + "`. Operations defined in the specification are: " + supportedOperations); }
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(HttpOperationScenario.class) .addConstructorArgValue((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey()) .addConstructorArgValue(HttpMethod.valueOf(operation.getKey().name())) .addConstructorArgValue(operation.getValue()) .addConstructorArgValue(swagger.getDefinitions()); } else { log.info("Register auto generated scenario as singleton: " + operation.getValue().getOperationId()); beanFactory.registerSingleton(operation.getValue().getOperationId(), createScenario((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey(), HttpMethod.valueOf(operation.getKey().name()), operation.getValue(), swagger.getDefinitions()));
/** * Bind a handler to each operation. * * @param router the Vert.x router * @param config the plugin configuration * @param swagger the OpenAPI specification * @param path the mock path * @param pathConfig the path configuration */ private void handlePathOperations(Router router, OpenApiPluginConfig config, Swagger swagger, String path, Path pathConfig) { pathConfig.getOperationMap().forEach((httpMethod, operation) -> { final String fullPath = ofNullable(swagger.getBasePath()).orElse("") + convertPath(path); LOGGER.debug("Adding mock endpoint: {} -> {}", httpMethod, fullPath); // convert an {@link io.swagger.models.HttpMethod} to an {@link io.vertx.core.http.HttpMethod} final HttpMethod method = HttpMethod.valueOf(httpMethod.name()); router.route(method, fullPath).handler(buildHandler(config, swagger, operation)); }); }
public ExOperation mkOperation(HttpMethod method, String path) { notEmpty(path, "'path' CAN'T be null or empty!!!"); notEmpty(method, "'method' CAN'T be null or empty!!!"); synchronized (swagger) { String origPath = path; path = path.replaceAll("<[^>]+>", "").replaceAll("/:([^/]+)", "/{$1}"); // replace `/:id<[0-9]+>` with `/{id}` if (swagger.getPath(path) == null) { logger.info(">>> adding path - '" + path + "'"); swagger.path(path, new Path()); } Path pathObj = swagger.getPath(path); if (pathObj.getOperationMap().get(method) != null) { throw new IllegalArgumentException("DUPLICATED operation - " + method + " '" + path + "'"); } logger.info(">>> adding operation - " + method + " '" + path + "'"); pathObj.set(method.name().toLowerCase(), new ExOperation(this, method, path)); implemented.put(entry(method, path), true); // set implemented by default String prevPath = origPaths.put(entry(method, path), origPath); if (prevPath != null) throw new IllegalArgumentException( "`" + path + "` was repeatedly defined by `" + prevPath + "` and `" + origPath + "`!!!"); return (ExOperation) pathObj.getOperationMap().get(method); } }
String httpMethod = operationEntry.getKey().name(); OperationMeta operationMeta = new OperationMeta(); operationMeta.init(this, method, strPath, httpMethod, operation);
uriTemplateBuilder.httpVerb(operationEntry.getKey().name()); apiResourceBuilder.uriTemplate(uriTemplateBuilder.build()); apiResources.add(apiResourceBuilder.build());
uriTemplateBuilder.httpVerb(operationEntry.getKey().name()); apiResourceBuilder.uriTemplate(uriTemplateBuilder.build()); apiResources.add(apiResourceBuilder.build());
String httpMethod = operationEntry.getKey().name(); OperationMeta operationMeta = new OperationMeta(); operationMeta.init(this, method, strPath, httpMethod, operation);