ExParamsSchema.Definition.Typespec (ex_params_schema v0.1.1)

Copy Markdown View Source

Builds the typespec AST for generated structs from normalized fields.

This internal module is used by ExParamsSchema.Compiler at compile time.

Summary

Functions

Returns the struct typespec AST from field definitions.

Functions

struct_type(fields)

@spec struct_type([ExParamsSchema.Definition.Field.t()]) :: Macro.t()

Returns the struct typespec AST from field definitions.

iex> fields = [
...>   %ExParamsSchema.Definition.Field{name: :count, type: :integer},
...>   %ExParamsSchema.Definition.Field{name: :label, type: :string, options: [optional: true]}
...> ]
iex> ast = ExParamsSchema.Definition.Typespec.struct_type(fields)
iex> Macro.to_string(ast)
"%__MODULE__{count: integer(), label: String.t() | nil}"