View Source ExOpenAI.Codegen.FunctionBodyGenerator (ex_openai.ex v2.0.0-beta2)

Generates function body AST for OpenAPI operations.

This module is primarily exercised via unit tests and mirrors the high‑level behaviour documented in docs/parsingv2.md:

  • Replaces path parameters in the URL using String.replace/3
  • Builds query strings from opts using URI.encode_www_form/1
  • Collects body parameters from the non‑opts function arguments
  • Delegates the HTTP call to ExOpenAI.Config.http_client().api_call/6

In the current v2 codegen the real, production function bodies are generated inline in PathModuleGenerator. generate_body/3 exists as a focused unit under test that captures the same ideas without being wired into the runtime generator.

Summary

Functions

Link to this function

categorize_parameters(operation)

View Source
Link to this function

determine_content_type(operation)

View Source
Link to this function

determine_http_method(operation)

View Source
Link to this function

generate_body(operation, path, arg_asts)

View Source
@spec generate_body(ExOpenAI.Codegen.DocsParser.Operation.t(), String.t(), [Macro.t()]) ::
  Macro.t()

Generates the function body AST for an operation.

The arg_asts parameter is the list of argument AST nodes that would appear in a function head, e.g. [quote(do: item_id), quote(do: opts)].

The generated body:

  • Captures arguments via binding/0 into all_args
  • Replaces any {path_param} segments using Keyword.get(all_args, name)
  • Builds a query string from query parameters present in all_args
  • Builds body_params from non‑path, non‑opts arguments
  • Calls api_call/6 with &Function.identity/1 as the converter