Infusion.Naming (infusion v0.1.0)

Copy Markdown View Source

Turns OpenAPI names into Elixir module and function names.

Each operation gets a module path (["Repos"], ["ZeroTrust", "Devices"]) and a function name, from the first strategy that applies:

  1. Vendor SDK hints: x-fern-sdk-group-name (dot-separated groups) and x-fern-sdk-method-name. Cloudflare sets them on nearly every operation, so its SDK matches the official ones.
  2. group/action operation IDs, as GitHub uses (repos/get).
  3. The path, when the operation has no tag (all of Stripe, part of OpenAI): GET /v1/customers is Customers.list, POST /v1/customers/{id} is Customers.update, POST /v1/payment_intents/{id}/cancel is PaymentIntents.cancel, and /v1/customers/{id}/sources is a nested Customers.Sources.
  4. The tag and the operation ID, with version prefixes taken off the tag (Twilio's Api20100401Recording) and the module's words taken off the function (list_recording in Recording is list).

Summary

Functions

A function or field name: "createChatCompletion", "repos/get-pages" -> snake_case.

A module name part: "vector stores", "vector_stores", "vector-stores" -> "VectorStores".

Names an operation. op is the operation object, path and method its location.

The package name for a base module, as the vendor writes it: OpenAI is openai, GitHub is github (not open_ai, git_hub). Used for the app, the directory and the API key's environment variable.

Splits camelCase, PascalCase, kebab, snake, dotted and spaced names into lowercase words.

Types

operation_name()

@type operation_name() :: %{
  module: [String.t()],
  function: String.t(),
  strategy: atom()
}

Functions

function_name(name)

@spec function_name(String.t()) :: String.t()

A function or field name: "createChatCompletion", "repos/get-pages" -> snake_case.

module_part(name)

@spec module_part(String.t()) :: String.t()

A module name part: "vector stores", "vector_stores", "vector-stores" -> "VectorStores".

operation(op, path, method)

@spec operation(map(), String.t(), String.t()) :: operation_name()

Names an operation. op is the operation object, path and method its location.

package(base)

@spec package(String.t()) :: String.t()

The package name for a base module, as the vendor writes it: OpenAI is openai, GitHub is github (not open_ai, git_hub). Used for the app, the directory and the API key's environment variable.

words(name)

@spec words(String.t()) :: [String.t()]

Splits camelCase, PascalCase, kebab, snake, dotted and spaced names into lowercase words.