> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate template code

> Converts template-builder blocks into Pongo2 template code and mapped fields.



## OpenAPI

````yaml en/openapi/v3-current/reporter.yaml post /v1/templates/generate-code
openapi: 3.1.0
info:
  contact:
    name: Discord community
    url: https://discord.gg/DnhqKwkGv3
  description: >-
    This is OpenAPI documentation for Reporter. The unified reporter binary
    serves the REST API (RUN_MODE=api) and/or the RabbitMQ report-generation
    worker (RUN_MODE=worker); RUN_MODE=all runs both in one process for local
    development. All REST endpoints documented here serve only when RUN_MODE=api
    or all (port :4005); the worker (port :4006) exposes health/readyz only.
  license:
    name: Lerian Studio General License
  title: Midaz Reporter API
  version: 4.0.0
servers:
  - url: http://localhost:4005
  - url: https://localhost:4005
security:
  - BearerAuth: []
tags:
  - description: Generated report instances and their lifecycle.
    name: Reports
  - description: Reusable report definitions.
    name: Templates
  - description: Interactive construction of report templates.
    name: Template Builder
  - description: Scheduled report due-date tracking.
    name: Deadlines
  - description: Configured inputs that feed report data.
    name: Data Sources
  - description: Aggregated reporting metrics.
    name: Metrics
  - description: Published business event catalog and delivery policies.
    name: Streaming
paths:
  /v1/templates/generate-code:
    post:
      tags:
        - Template Builder
      summary: Generate template code
      description: >-
        Converts template-builder blocks into Pongo2 template code and mapped
        fields.
      operationId: generateTemplateCode
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateCodeInput'
        description: Template blocks and target output format.
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateCodeResponse'
          description: OK
        '400':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Bad Request
        '401':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Unauthorized
        '403':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Forbidden
        '500':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Internal Server Error
components:
  schemas:
    GenerateCodeInput:
      properties:
        blocks:
          description: Template builder blocks converted into Pongo2 code.
          examples:
            - - type: variable
                variable: account.id
          items:
            $ref: '#/components/schemas/TemplateBlock'
          type:
            - array
            - 'null'
        format:
          description: Output format targeted by the generated template.
          examples:
            - html
          type: string
      type: object
    GenerateCodeResponse:
      properties:
        code:
          description: Generated Pongo2 template source.
          examples:
            - '{{ account.id }}'
          type: string
        mappedFields:
          additionalProperties:
            additionalProperties:
              items:
                type: string
              type:
                - array
                - 'null'
            type: object
          description: >-
            Fields referenced by the generated template, grouped by data source
            and entity.
          examples:
            - primary:
                account:
                  - id
          type: object
      type: object
    Detail:
      properties:
        code:
          description: >-
            Stable, machine-readable domain error code scoped to the emitting
            service (format: <SERVICE>-NNNN).
          examples:
            - ERR-0001
          type: string
        detail:
          description: >-
            A human-readable explanation specific to this occurrence of the
            problem.
          examples:
            - Property foo is required but is missing.
          type: string
        errors:
          description: Optional list of individual error details
          examples:
            - - location: body.templateId
                message: expected string to match 'uuid' format
                value: not-a-uuid
          items:
            $ref: '#/components/schemas/ErrorDetail'
          type:
            - array
            - 'null'
        instance:
          description: >-
            A URI reference that identifies the specific occurrence of the
            problem.
          examples:
            - https://example.com/error-log/abc123
          format: uri
          type: string
        status:
          description: HTTP status code
          examples:
            - 400
          format: int64
          type: integer
        title:
          description: >-
            A short, human-readable summary of the problem type. This value
            should not change between occurrences of the error.
          examples:
            - Bad Request
          type: string
        type:
          default: about:blank
          description: A URI reference to human-readable documentation for the error.
          examples:
            - https://example.com/errors/example
          format: uri
          type: string
      type: object
    TemplateBlock:
      properties:
        assignment:
          description: Assignment expression emitted by a set block.
          examples:
            - total = account.balance
          type: string
        blockId:
          description: Client-defined identifier used to locate validation errors.
          examples:
            - customer-name
          type: string
        children:
          description: Nested blocks rendered inside this block.
          examples:
            - - content: Transaction
                type: text
          items:
            $ref: '#/components/schemas/TemplateBlock'
          type:
            - array
            - 'null'
        collection:
          description: Collection expression traversed by a loop block.
          examples:
            - account.transactions
          type: string
        condition:
          description: Boolean expression evaluated by a conditional block.
          examples:
            - account.active
          type: string
        content:
          description: Literal content rendered by text blocks.
          examples:
            - 'Account holder: '
          type: string
        elifBranches:
          description: Additional conditional branches evaluated in order.
          examples:
            - - children:
                  - content: Pending
                    type: text
                condition: account.pending
          items:
            $ref: '#/components/schemas/ElifBranch'
          type:
            - array
            - 'null'
        elseChildren:
          description: Blocks rendered when the primary condition is false.
          examples:
            - - content: Inactive
                type: text
          items:
            $ref: '#/components/schemas/TemplateBlock'
          type:
            - array
            - 'null'
        expression:
          description: Expression emitted by an expression block.
          examples:
            - account.balance > 0
          type: string
        field:
          description: Data field referenced by the block.
          examples:
            - transaction.amount
          type: string
        filters:
          description: Ordered filters applied to the variable.
          examples:
            - - name: upper
          items:
            $ref: '#/components/schemas/FilterChain'
          type:
            - array
            - 'null'
        format:
          description: Formatting option applied by the block.
          examples:
            - '2006-01-02'
          type: string
        function:
          description: Template function invoked by the block.
          examples:
            - format_currency
          type: string
        inline:
          description: Whether the block renders without adding a line break.
          examples:
            - true
          type: boolean
        iterator:
          description: Iterator variable name used by loop blocks.
          examples:
            - transaction
          type: string
        properties:
          additionalProperties: {}
          description: Block-specific configuration properties.
          examples:
            - class: summary
          type: object
        tagArgs:
          description: Arguments passed to the Pongo2 tag.
          examples:
            - '"summary.html"'
          type: string
        tagName:
          description: Pongo2 tag name emitted by a custom-tag block.
          examples:
            - include
          type: string
        trimWhitespace:
          description: Whether surrounding whitespace is removed during rendering.
          examples:
            - true
          type: boolean
        type:
          description: Template builder block type.
          examples:
            - variable
          type: string
        variable:
          description: Variable expression rendered by the block.
          examples:
            - account.holderName
          type: string
      type: object
    ErrorDetail:
      properties:
        location:
          description: >-
            Where the error occurred, e.g. 'body.items[3].tags' or
            'path.thing-id'
          examples:
            - body.templateId
          type: string
        message:
          description: Error message text
          examples:
            - expected string to match 'uuid' format
          type: string
        value:
          description: The value at the given location
          examples:
            - not-a-uuid
      type: object
    ElifBranch:
      properties:
        children:
          description: Blocks rendered when this branch matches.
          examples:
            - - content: Pending
                type: text
          items:
            $ref: '#/components/schemas/TemplateBlock'
          type:
            - array
            - 'null'
        condition:
          description: Boolean expression evaluated for this branch.
          examples:
            - account.pending
          type: string
      type: object
    FilterChain:
      properties:
        args:
          description: Arguments passed to the filter.
          examples:
            - '"2006-01-02"'
          type: string
        name:
          description: Pongo2 filter name.
          examples:
            - date
          type: string
      type: object
  securitySchemes:
    BearerAuth:
      bearerFormat: JWT
      description: JWT bearer token issued by the identity provider.
      scheme: bearer
      type: http

````