Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(custom): add javadocs to custom classes #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -34,6 +34,18 @@
import static com.github.fge.avro.translators.AvroTranslatorUtil.*;


/**
* Customized class to allow extension and modifications to be separate from original class. Original class is marked as final
* which makes it impossible to extend externally and makes it less flexible in general. The naming change is also applied to other
* customized classes for the same reasons, especially for some of the translator subtypes which needed to be changed to not extend
* subtypes. Separation is also important since all of the code in this repo is under LGPL licensing.
* Changes from original:
*
* Translator selection logic has been modified to be able to modify the translation process. Modification to specific translators and
* logic outlined in each translator and the selector util.
*
* Sanitizes class names to shortname in translation, this results in cleaner output types which work with code generation.
*/
public class CustomAvro2JsonSchemaProcessor extends RawProcessor<JsonTree, SchemaTree> {
public CustomAvro2JsonSchemaProcessor()
{
Original file line number Diff line number Diff line change
@@ -23,6 +23,10 @@
import org.apache.avro.Schema;


/**
* Overrides the types returned by AvroTranslators to customized types. Not all types needed to be customized so in cases
* where a customized type is not present, falls back to default behavior.
*/
public class AvroTranslatorUtil {

private AvroTranslatorUtil() {
Original file line number Diff line number Diff line change
@@ -31,6 +31,9 @@
import static com.github.fge.avro.translators.AvroTranslatorUtil.*;


/**
* Adds missing description for top level array and modifies selector logic for array sub items to customized util method
*/
public class CustomArrayAvroTranslator extends AvroTranslator {
private static final AvroTranslator INSTANCE = new CustomArrayAvroTranslator();

Original file line number Diff line number Diff line change
@@ -27,6 +27,9 @@
import org.apache.avro.Schema;


/**
* Adds missing description of field
*/
public class CustomByteTranslator extends AvroTranslator {
private static final String BYTES_PATTERN = "^[\u0000-\u00ff]*$";

Original file line number Diff line number Diff line change
@@ -30,6 +30,10 @@
import org.apache.avro.Schema;


/**
* Customized to point to fixed type definition reference. We use Fixed types to represent certain types that have specific definitions
* in the schema and the default implementation ignores these, just setting the fixed type to a String of fixed size. EX: UUID
*/
public class CustomFixedTranslator extends AvroTranslator {
private static final String BYTES_PATTERN = "^[\u0000-\u00ff]*$";

Original file line number Diff line number Diff line change
@@ -27,6 +27,9 @@
import org.apache.avro.Schema;


/**
* Adds missing description
*/
public class CustomIntTranslator extends AvroTranslator {
private static final AvroTranslator INSTANCE = new CustomIntTranslator();

Original file line number Diff line number Diff line change
@@ -27,6 +27,9 @@
import org.apache.avro.Schema;


/**
* Adds missing description and format
*/
final class CustomLongAvroTranslator extends AvroTranslator {
private static final AvroTranslator INSTANCE = new CustomLongAvroTranslator();

Original file line number Diff line number Diff line change
@@ -31,6 +31,9 @@
import static com.github.fge.avro.translators.AvroTranslatorUtil.*;


/**
* Adds missing description
*/
final class CustomMapAvroTranslator extends AvroTranslator {
private static final AvroTranslator INSTANCE = new CustomMapAvroTranslator();

Original file line number Diff line number Diff line change
@@ -40,6 +40,12 @@
import static com.github.fge.avro.translators.AvroTranslatorUtil.*;


/**
* Customizes extended class to allow for modifications at the translate function level, specifically naming of types.
* Adds missing descriptions to root record and fixes references for subfields.
* Applies partial fix for the FIX ME comment present in the base repository to not mark fields as required when
* default is provided. Also fixes a silly error message to just pass through the original error.
*/
public class CustomRecordAvroTranslator extends AvroTranslator {
private static final ObjectMapper OLD_MAPPER = new ObjectMapper();

Original file line number Diff line number Diff line change
@@ -27,6 +27,9 @@
import org.apache.avro.Schema;


/**
* Adds missing description.
*/
public class CustomSimpleTranslator extends AvroTranslator {
private final NodeType type;

Original file line number Diff line number Diff line change
@@ -32,6 +32,11 @@
import static com.github.fge.avro.translators.AvroTranslatorUtil.*;


/**
* Filters out NULL values that get added into the Avro Union, if this leaves the Union with a single type then we just treat it as that type
* instead of as a union. For types where the Union includes enums and String, then just uses String as any value is supported
* if String is allowed.
*/
public class CustomUnionAvroTranslator extends AvroTranslator {
private static final AvroTranslator INSTANCE = new CustomUnionAvroTranslator();