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

Functions

Link to this function

external_dependencies(schema)

View Source
Link to this function

filename_from_schema(dest, schema)

View Source
@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.

Link to this function

filenames_from_schema(dest, schema, opts \\ [])

View Source
@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.

Link to this function

generate_code(schema, dependencies, module_prefix, opts \\ [])

View Source
@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 enums 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 the CodeGenerator implementation in the patent type.
Link to this function

module_path(module_prefix, dep_name, global)

View Source
Link to this function

normalized_schemas(schema, module_prefix, scope_embedded_types)

View Source
@spec normalized_schemas(raw_schema(), String.t() | nil, boolean()) :: [t()]
@spec parse(raw_schema()) :: t()