View Source Avrogen.Avro.Schema (avrogen v0.8.5)
The entry point for code generation. It starts by taking a raw schema: JSON matching the specification.
An Avro schema is a recursive data structure.
Summary
Functions
Get the filename of the generated elixir source file from a schema.
Get all the filenames of the generated elixir source file from a schema.
This function will generate elixir modules for the provided schema. If the schema references external types (i.e. types that are not embedded within the schema), then the schemas for the external dependencies should be passed as the second argument.
Types
@type file_name() :: String.t()
@type generated_code() :: iodata()
@type non_union() :: Avrogen.Avro.Types.Record.t() | Avrogen.Avro.Types.Record.Field.t() | Avrogen.Avro.Types.Reference.t() | Avrogen.Avro.Types.Primitive.t() | Avrogen.Avro.Types.Logical.t() | Avrogen.Avro.Types.Enum.t() | Avrogen.Avro.Types.Map.t() | Avrogen.Avro.Types.Array.t()
@type t() :: Avrogen.Avro.Types.Union.t() | non_union()
Functions
@spec filename_from_schema( Path.t(), Avrogen.Avro.Types.Record.t() | Avrogen.Avro.Types.Enum.t() ) :: Path.t()
Get the filename of the generated elixir source file from a schema.
@spec filenames_from_schema(Path.t(), raw_schema(), Keyword.t()) :: [Path.t()]
Get all the filenames of the generated elixir source file from a schema.
@spec generate_code(raw_schema(), raw_schema(), String.t() | nil, Keyword.t()) :: [ {file_name(), generated_code()} ]
This function will generate elixir modules for the provided schema. If the schema references external types (i.e. types that are not embedded within the schema), then the schemas for the external dependencies should be passed as the second argument.
Overview of code:
- This function works by first parsing the schemas into
Schema.t()
which is a recursive data structure representing the avro schema file. - It then does a second parse over the schema where it normalizes the schema by extracting all the embedded types and replacing the embedded type with a reference to the schema.
- The final stage is generation of the specific modules (for
enum
s and 'records). The code generation relies on the 'CodeGenerator
protocol defined below where each part of the schema implements this protocol and is responsible for generating snippets of the generated code. These snippets are combined theCodeGenerator
implementation in the patent type.
@spec normalized_schemas(raw_schema(), String.t() | nil, boolean()) :: [t()]
@spec parse(raw_schema()) :: t()