use of com.github.fge.jackson.jsonpointer.JsonPointer in project stackgres by ongres.
the class ExtensionsMutator method onExtensionToInstall.
@Override
protected void onExtensionToInstall(Builder<JsonPatchOperation> operations, StackGresClusterExtension extension, int index, StackGresClusterInstalledExtension installedExtension) {
final JsonPointer extensionVersionPointer = CLUSTER_CONFIG_POINTER.append("postgres").append("extensions").append(index).append("version");
final TextNode extensionVersion = new TextNode(installedExtension.getVersion());
if (extension.getVersion() == null) {
operations.add(new AddOperation(extensionVersionPointer, extensionVersion));
} else if (!installedExtension.getVersion().equals(extension.getVersion())) {
operations.add(new ReplaceOperation(extensionVersionPointer, extensionVersion));
}
}
use of com.github.fge.jackson.jsonpointer.JsonPointer in project stackgres by ongres.
the class ClusterConfigurationMutator method ensureConfigurationNode.
static List<JsonPatchOperation> ensureConfigurationNode(StackGresClusterReview review) {
final StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
StackGresClusterConfiguration configuration = spec.getConfiguration();
if (configuration == null) {
try {
configuration = new StackGresClusterConfiguration();
spec.setConfiguration(configuration);
final JsonPointer confPointer = getTargetPointer();
final AddOperation configurationAdd = new AddOperation(confPointer, JsonPatchMutator.FACTORY.objectNode());
return ImmutableList.of(configurationAdd);
} catch (NoSuchFieldException e) {
return ImmutableList.of();
}
}
return ImmutableList.of();
}
use of com.github.fge.jackson.jsonpointer.JsonPointer in project stackgres by ongres.
the class AbstractExtensionsMutator method onExtensionToInstall.
protected void onExtensionToInstall(ImmutableList.Builder<JsonPatchOperation> operations, final StackGresClusterExtension extension, final int index, final StackGresClusterInstalledExtension installedExtension) {
final JsonPointer extensionVersionPointer = TO_INSTALL_EXTENSIONS_POINTER.append(index).append("version");
final TextNode extensionVersion = new TextNode(installedExtension.getVersion());
if (extension.getVersion() == null) {
operations.add(new AddOperation(extensionVersionPointer, extensionVersion));
} else if (!installedExtension.getVersion().equals(extension.getVersion())) {
operations.add(new ReplaceOperation(extensionVersionPointer, extensionVersion));
}
}
use of com.github.fge.jackson.jsonpointer.JsonPointer in project swagger-parser by swagger-api.
the class ApiObjectMigrator method migrate.
@Nonnull
@Override
public JsonNode migrate(@Nonnull final JsonNode input) throws SwaggerMigrationException {
ObjectNode on = (ObjectNode) input;
if (on.get("type") == null) {
JsonNode responseMessages = on.get("responseMessages");
JsonNode type = null;
if (responseMessages != null && responseMessages instanceof ArrayNode) {
// look for a 200 response
ArrayNode arrayNode = (ArrayNode) responseMessages;
Iterator<JsonNode> itr = arrayNode.elements();
while (itr.hasNext()) {
JsonNode rm = itr.next();
JsonNode code = rm.get("code");
if (code != null) {
if ("200".equals(code.toString())) {
type = rm;
}
}
}
}
if (type != null) {
if (type.get("type") == null) {
on.put("type", "void");
} else {
on.put("type", type.get("type"));
}
} else {
on.put("type", "void");
}
}
// if there are no parameters, we can insert an empty array
if (on.get("parameters") == null) {
on.put("parameters", Json.mapper().createArrayNode());
}
// see if there's a response
final MutableJsonTree tree = new MutableJsonTree(input);
tree.applyMigrator(renameMember("httpMethod", "method"));
tree.applyMigrator(renameMember("errorResponses", "responseMessages"));
/*
* Migrate response messages, if any
*/
JsonPointer ptr = JsonPointer.of("responseMessages");
if (!ptr.path(tree.getBaseNode()).isMissingNode()) {
tree.setPointer(ptr);
tree.applyMigratorToElements(renameMember("reason", "message"));
}
/*
* Migrate parameters
*/
ptr = JsonPointer.of("parameters");
tree.setPointer(ptr);
tree.applyMigratorToElements(parametersMigrator);
return tree.getBaseNode();
}
use of com.github.fge.jackson.jsonpointer.JsonPointer in project swagger-parser by swagger-api.
the class MutableJsonTree method applyMigrator.
/**
* Apply a migrator to the node at the current pointer
*
* <p>It is assumed here that the current node is a JSON Object.</p>
*
* @param migrator the migrator to apply
* @throws SwaggerMigrationException current node is not an object, or the
* migrator failed to apply
*/
public void applyMigrator(final SwaggerMigrator migrator) throws SwaggerMigrationException {
final JsonPointer parent = currentPointer.parent();
if (!parent.get(baseNode).isObject()) {
throw new SwaggerMigrationException();
}
final ObjectNode parentNode = (ObjectNode) parent.get(baseNode);
final JsonNode patched = migrator.migrate(currentNode);
if (currentPointer.isEmpty()) {
baseNode = currentNode = patched;
return;
}
final String memberName = Iterables.getLast(currentPointer).getToken().getRaw();
parentNode.put(memberName, patched);
}
Aggregations