Skip to main content

How do I document macros?

To document macros, use a properties file and nest the configurations under a macros: key

Example

macros/properties.yml
macros:
- name: cents_to_dollars
description: A macro to convert cents to dollars
arguments:
- name: column_name
type: column
description: The name of the column you want to convert
- name: precision
type: integer
description: Number of decimal places. Defaults to 2.
Report incorrect code
tip

From dbt v1.10, you can opt into validating the arguments you define in macro documentation using the validate_macro_args behavior change flag. When enabled, dbt will:

  • Infer arguments from the macro and includes them in the manifest.json file if no arguments are documented.
  • Raise a warning if documented argument names don't match the macro definition.
  • Raise a warning if type fields don't follow supported formats.

Learn more about macro argument validation.

Document a custom materialization

When you create a custom materialization, dbt creates an associated macro with the following format:

materialization_{materialization_name}_{adapter}
Report incorrect code

To document a custom materialization, use the previously mentioned format to determine the associated macro name(s) to document.

macros/properties.yml
macros:
- name: materialization_my_materialization_name_default
description: A custom materialization to insert records into an append-only table and track when they were added.
- name: materialization_my_materialization_name_xyz
description: A custom materialization to insert records into an append-only table and track when they were added.
Report incorrect code

Was this page helpful?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

0
Loading