Try this in your snap class:
import com.snaplogic.api.SchemaPropagator;
add “implements SchemaPropagator.Passthrough
” to your class
This interface functions as a “mixin” by relying on a feature that was new in Java 8: There are default implementations for the two methods defined by this interface that should do what you need if you’re looking to simply pass through the schema in both directions without modification. This is exactly what our Copy snap does.
Sorry, this is a relatively new feature of our SDK and it’s not documented in our developer docs yet. We appreciate that you’re building such a full-featured snap that does everything a good snap should. To make up for the lack of examples or javadocs for this class, I’ve included its source code below. You may notice an alternative to the “Passthrough” interface called “Original”, that gives you some clues about how you might alter the schema in either direction if you need to.
Hope that helps.
/*
* SnapLogic - Data Integration
*
* Copyright (C) 2019, SnapLogic, Inc. All rights reserved.
*
* This program is licensed under the terms of
* the SnapLogic Commercial Subscription agreement.
*
* "SnapLogic" is a trademark of SnapLogic, Inc.
*/
package com.snaplogic.api;
import com.snaplogic.common.SnapType;
import com.snaplogic.snap.schema.api.ObjectSchema;
import com.snaplogic.snap.schema.api.Schema;
import com.snaplogic.snap.schema.api.SchemaProvider;
/**
* Snaps should implement this interface if they wish to propagate schema from upstream snaps to
* downstream snaps and vice-versa.
*/
public interface SchemaPropagator {
/**
* Mixin for snaps that directly pass documents without modification.
*/
interface Passthrough extends SchemaPropagator {
@Override
default void pullDownstreamInputSchema(SchemaProvider schemaProvider, final String name,
ObjectSchema downstreamSchema, String view, ObjectSchema inputSchema) {
inputSchema.merge(downstreamSchema);
}
@Override
default void propagateUpstreamOutputSchema(SchemaProvider schemaProvider, final String name,
ObjectSchema upstreamSchema, String view, ObjectSchema outputSchema) {
outputSchema.merge(upstreamSchema);
}
}
/**
* Mixin for snaps that pass their input documents to their outputs in the "original" property.
*/
interface Original extends SchemaPropagator {
@Override
default void pullDownstreamInputSchema(SchemaProvider schemaProvider, final String name,
ObjectSchema downstreamSchema, String view, ObjectSchema inputSchema) {
Schema original = downstreamSchema.getChild("original");
if (original != null) {
inputSchema.merge(original);
}
}
@Override
default void propagateUpstreamOutputSchema(SchemaProvider schemaProvider, final String name,
ObjectSchema upstreamSchema, String view, ObjectSchema outputSchema) {
ObjectSchema originalSchema = schemaProvider.createSchema(SnapType.COMPOSITE,
"original");
originalSchema.merge(upstreamSchema);
outputSchema.addChild(originalSchema);
}
}
/**
* Snaps should implement this method to propagate schema from downstream snaps to this
* snap's input views.
*
* @param schemaProvider
* @param name The name of the output view that is connected to a downstream snap.
* @param downstreamSchema The schema of the downstream input view.
* @param view The name of this snap's input view that is being modified.
* @param inputSchema The current schema for this input view.
*/
void pullDownstreamInputSchema(SchemaProvider schemaProvider, final String name, ObjectSchema
downstreamSchema, String view, ObjectSchema inputSchema);
/**
* Snaps should implement this method to propagate schema from upstream snaps to this
* snap's output views.
*
* @param schemaProvider
* @param name The name of the input view that is connected to an upstream snap.
* @param upstreamSchema The schema of the upstream output view.
* @param view The name of this snap's output view that is being modified.
* @param outputSchema The current schema for this output view.
*/
void propagateUpstreamOutputSchema(SchemaProvider schemaProvider, final String name,
ObjectSchema upstreamSchema, String view, ObjectSchema outputSchema);
}