use of io.github.microcks.domain.Operation in project microcks by microcks.
the class ServiceService method copyOverridenOperations.
/**
* Recopy overriden operation mutable properties into newService.
*/
private void copyOverridenOperations(Service existingService, Service newService) {
for (Operation existingOperation : existingService.getOperations()) {
if (existingOperation.hasOverride()) {
for (Operation op : newService.getOperations()) {
if (existingOperation.getName().equals(op.getName())) {
op.setDefaultDelay(existingOperation.getDefaultDelay());
op.setDispatcher(existingOperation.getDispatcher());
op.setDispatcherRules(existingOperation.getDispatcherRules());
op.setParameterConstraints(existingOperation.getParameterConstraints());
op.setOverride(true);
}
}
}
}
}
use of io.github.microcks.domain.Operation in project microcks by microcks.
the class AsyncAPIImporter method getResourceDefinitions.
@Override
public List<Resource> getResourceDefinitions(Service service) {
List<Resource> results = new ArrayList<>();
// Build a suitable name.
String name = service.getName() + "-" + service.getVersion();
if (isYaml) {
name += ".yaml";
} else {
name += ".json";
}
// Build a brand new resource just with spec content.
Resource resource = new Resource();
resource.setName(name);
resource.setType(ResourceType.ASYNC_API_SPEC);
resource.setContent(specContent);
results.add(resource);
// references for external schemas only if we have a resolver available.
if (referenceResolver != null) {
for (Operation operation : service.getOperations()) {
String[] operationElements = operation.getName().split(" ");
String messageNamePtr = "/channels/" + operationElements[1].replaceAll("/", "~1");
messageNamePtr += "/" + operationElements[0].toLowerCase() + "/message";
JsonNode messageNode = spec.at(messageNamePtr);
if (messageNode != null) {
// If it's a $ref, then navigate to it.
messageNode = followRefIfAny(messageNode);
// Extract payload schema here.
if (messageNode.has("payload")) {
JsonNode payloadNode = messageNode.path("payload");
// Check we have a reference that is not a local one.
if (payloadNode.has("$ref") && !payloadNode.path("$ref").asText().startsWith("#")) {
String ref = payloadNode.path("$ref").asText();
// to indicate exact Resource)
if (ref.contains("#")) {
ref = ref.substring(0, ref.indexOf("#"));
}
try {
// Extract content using resolver.
String content = referenceResolver.getHttpReferenceContent(ref, "UTF-8");
// Build a new resource from content. Use the escaped operation path.
Resource schemaResource = new Resource();
schemaResource.setName(IdBuilder.buildResourceFullName(service, operation));
schemaResource.setPath(ref);
schemaResource.setContent(content);
// We have to look at schema format to know the type.
// Default value is set at first.
String schemaFormat = "application/vnd.aai.asyncapi";
if (messageNode.has("schemaFormat")) {
schemaFormat = messageNode.path("schemaFormat").asText();
}
if (schemaFormat.startsWith("application/vnd.aai.asyncapi")) {
schemaResource.setType(ResourceType.ASYNC_API_SCHEMA);
} else if (schemaFormat.startsWith("application/vnd.oai.openapi")) {
schemaResource.setType(ResourceType.OPEN_API_SCHEMA);
} else if (schemaFormat.startsWith("application/schema+json") || schemaFormat.startsWith("application/schema+yaml")) {
schemaResource.setType(ResourceType.JSON_SCHEMA);
} else if (schemaFormat.startsWith("application/vnd.apache.avro")) {
schemaResource.setType(ResourceType.AVRO_SCHEMA);
}
results.add(schemaResource);
} catch (IOException ioe) {
log.error("IOException while trying to resolve reference " + ref, ioe);
log.info("Ignoring the reference {} cause it could not be resolved", ref);
}
}
}
}
}
// Finally try to clean up resolved references and associated resources (files)
referenceResolver.cleanResolvedReferences();
}
return results;
}
use of io.github.microcks.domain.Operation in project microcks by microcks.
the class ProtobufImporter method extractOperations.
/**
* Extract the operations from GRPC service methods.
*/
private List<Operation> extractOperations(DescriptorProtos.ServiceDescriptorProto service) {
List<Operation> results = new ArrayList<>();
for (DescriptorProtos.MethodDescriptorProto method : service.getMethodList()) {
Operation operation = new Operation();
operation.setName(method.getName());
operation.setInputName(method.getInputType());
operation.setOutputName(method.getOutputType());
results.add(operation);
}
return results;
}
use of io.github.microcks.domain.Operation in project microcks by microcks.
the class MetadataImporter method extractOperations.
/**
* Extract the list of operations from Specification.
*/
private List<Operation> extractOperations() throws MockRepositoryImportException {
List<Operation> results = new ArrayList<>();
// Iterate on specification "operations" nodes.
Iterator<Map.Entry<String, JsonNode>> operations = spec.path("operations").fields();
while (operations.hasNext()) {
Map.Entry<String, JsonNode> operation = operations.next();
// Build a new operation.
Operation op = new Operation();
op.setName(operation.getKey());
JsonNode operationValue = operation.getValue();
MetadataExtractor.completeOperationProperties(op, operationValue);
results.add(op);
}
return results;
}
use of io.github.microcks.domain.Operation in project microcks by microcks.
the class PostmanCollectionImporter method extractOperationsV2.
private List<Operation> extractOperationsV2() {
// Items corresponding to same operations may be defined multiple times in Postman
// with different names and resource path. We have to track them to complete them in second step.
Map<String, Operation> collectedOperations = new HashMap<String, Operation>();
Iterator<JsonNode> items = collection.path("item").elements();
while (items.hasNext()) {
JsonNode item = items.next();
extractOperationV2("", item, collectedOperations);
}
return new ArrayList<>(collectedOperations.values());
}
Aggregations