Search in sources :

Example 1 with HttpMethod

use of io.swagger.models.HttpMethod in project camel by apache.

the class RestSwaggerEndpoint method createProducer.

@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 String uriTemplate = pathEntry.getKey();
            final HttpMethod httpMethod = operationEntry.getKey();
            final String method = httpMethod.name();
            final Operation operation = operationEntry.getValue();
            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);
}
Also used : CamelContext(org.apache.camel.CamelContext) UriPath(org.apache.camel.spi.UriPath) Path(io.swagger.models.Path) Scheme(io.swagger.models.Scheme) SwaggerParser(io.swagger.parser.SwaggerParser) Metadata(org.apache.camel.spi.Metadata) UriPath(org.apache.camel.spi.UriPath) URISyntaxException(java.net.URISyntaxException) Swagger(io.swagger.models.Swagger) Json(io.swagger.util.Json) StringHelper.before(org.apache.camel.util.StringHelper.before) HashMap(java.util.HashMap) Endpoint(org.apache.camel.Endpoint) Consumer(org.apache.camel.Consumer) ObjectHelper.notNull(org.apache.camel.util.ObjectHelper.notNull) StringHelper.notEmpty(org.apache.camel.util.StringHelper.notEmpty) UriEndpoint(org.apache.camel.spi.UriEndpoint) Processor(org.apache.camel.Processor) UriParam(org.apache.camel.spi.UriParam) ObjectHelper.isNotEmpty(org.apache.camel.util.ObjectHelper.isNotEmpty) Path(io.swagger.models.Path) RestSwaggerHelper.isHostParam(org.apache.camel.component.rest.swagger.RestSwaggerHelper.isHostParam) Map(java.util.Map) ResourceHelper(org.apache.camel.util.ResourceHelper) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) Operation(io.swagger.models.Operation) RestSwaggerHelper.isMediaRange(org.apache.camel.component.rest.swagger.RestSwaggerHelper.isMediaRange) ExchangePattern(org.apache.camel.ExchangePattern) CamelContext(org.apache.camel.CamelContext) StringHelper.after(org.apache.camel.util.StringHelper.after) DefaultEndpoint(org.apache.camel.impl.DefaultEndpoint) Optional.ofNullable(java.util.Optional.ofNullable) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Producer(org.apache.camel.Producer) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) HttpMethod(io.swagger.models.HttpMethod) InputStream(java.io.InputStream) RestConfiguration(org.apache.camel.spi.RestConfiguration) Operation(io.swagger.models.Operation) Entry(java.util.Map.Entry) Swagger(io.swagger.models.Swagger) HttpMethod(io.swagger.models.HttpMethod)

Example 2 with HttpMethod

use of io.swagger.models.HttpMethod in project KaiZen-OpenAPI-Editor by RepreZen.

the class PathParamHyperlinkDetector method findParameterPath.

private Iterable<JsonPointer> findParameterPath(JsonDocument doc, JsonPointer basePath, String parameter) {
    AbstractNode parent = doc.getModel().find(basePath);
    if (parent == null || !parent.isObject()) {
        return Lists.newArrayList();
    }
    List<JsonPointer> paths = new ArrayList<>();
    for (HttpMethod method : HttpMethod.values()) {
        String mName = method.name().toLowerCase();
        if (parent.get(mName) == null) {
            continue;
        }
        AbstractNode parameters = parent.get(mName).get("parameters");
        if (parameters != null && parameters.isArray()) {
            for (int i = 0; i < parameters.size(); i++) {
                AbstractNode current = parameters.get(i);
                if (JsonReference.isReference(current)) {
                    JsonPointer ptr = JsonReference.getPointer(current.asObject());
                    AbstractNode resolved = doc.getModel().find(ptr);
                    if (resolved != null && resolved.isObject() && resolved.get("name") != null) {
                        if (parameter.equals(resolved.get("name").asValue().getValue())) {
                            paths.add(ptr);
                        }
                    }
                } else if (current.isObject() && current.get("name") != null) {
                    if (parameter.equals(current.get("name").asValue().getValue())) {
                        paths.add(JsonPointer.compile(basePath + "/" + mName + "/parameters/" + i));
                    }
                }
            }
        }
    }
    return paths;
}
Also used : AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) ArrayList(java.util.ArrayList) JsonPointer(com.fasterxml.jackson.core.JsonPointer) HttpMethod(io.swagger.models.HttpMethod)

Example 3 with HttpMethod

use of io.swagger.models.HttpMethod in project java-chassis by ServiceComb.

the class SchemaMeta method initOperations.

private void initOperations() {
    for (Entry<String, Path> entry : swagger.getPaths().entrySet()) {
        String strPath = entry.getKey();
        Path path = entry.getValue();
        for (Entry<HttpMethod, Operation> operationEntry : path.getOperationMap().entrySet()) {
            Operation operation = operationEntry.getValue();
            if (operation.getOperationId() == null) {
                throw ExceptionUtils.operationIdInvalid(getSchemaId(), strPath);
            }
            Method method = ReflectUtils.findMethod(swaggerIntf, operation.getOperationId());
            if (method == null) {
                throw ExceptionUtils.operationNotExist(getSchemaId(), operation.getOperationId());
            }
            String httpMethod = operationEntry.getKey().name();
            OperationMeta operationMeta = new OperationMeta();
            operationMeta.init(this, method, strPath, httpMethod, operation);
            operationMgr.register(method.getName(), operationMeta);
        }
    }
}
Also used : Path(io.swagger.models.Path) Operation(io.swagger.models.Operation) HttpMethod(io.swagger.models.HttpMethod) Method(java.lang.reflect.Method) HttpMethod(io.swagger.models.HttpMethod)

Aggregations

HttpMethod (io.swagger.models.HttpMethod)3 Operation (io.swagger.models.Operation)2 Path (io.swagger.models.Path)2 JsonPointer (com.fasterxml.jackson.core.JsonPointer)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AbstractNode (com.reprezen.swagedit.core.model.AbstractNode)1 Scheme (io.swagger.models.Scheme)1 Swagger (io.swagger.models.Swagger)1 SwaggerParser (io.swagger.parser.SwaggerParser)1 Json (io.swagger.util.Json)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1