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);
}
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;
}
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);
}
}
}
Aggregations