Stancer.DynamicAPI (stancer v0.1.0)

Copy Markdown

Dynamically generated Stancer API functions from OpenAPI specification.

This module generates all available API functions at runtime from the Stancer OpenAPI spec. Each function is automatically documented and type-specified based on the schema.

Generated Functions

Functions are generated for each endpoint in the OpenAPI spec, including:

  • tokenize_card/1 - POST /tokens
  • create_payment/1 - POST /payments
  • get_payment/1 - GET /payments/{id}
  • capture_payment/2 - POST /payments/{id}/capture
  • refund_payment/2 - POST /payments/{id}/refund
  • get_card/1 - GET /cards/{id}
  • delete_card/1 - DELETE /cards/{id}
  • And many more endpoints based on the Stancer API

All functions return {:ok, response_data} on success or {:error, reason} on failure.

Summary

Functions

Call an API endpoint dynamically by name with parameters.

Get information about a specific endpoint.

Load the OpenAPI specification and return all available endpoints.

Get all available operations grouped by tag/resource.

List all available API operations with their documentation.

Print formatted documentation for all available operations.

Functions

call(operation_id, params \\ %{})

@spec call(String.t(), map() | list()) :: {:ok, map()} | {:error, term()}

Call an API endpoint dynamically by name with parameters.

Parameters:

  • operation_id: The operationId from OpenAPI
  • params: Map or list of parameters for the operation

Returns: {:ok, response} or {:error, reason}

Example:

{:ok, token} = Stancer.DynamicAPI.call("post_tokens", %{
  "card" => %{
    "number" => "4111111111111111",
    "exp_month" => 12,
    "exp_year" => 2026,
    "cvc" => "123"
  }
})

get_endpoint_info(operation_id)

@spec get_endpoint_info(String.t()) :: {:ok, map()} | {:error, atom()}

Get information about a specific endpoint.

Parameters:

  • operation_id: The operationId from OpenAPI (e.g., "post_tokens")

Returns: {:ok, endpoint_info} or {:error, :not_found}

get_endpoints()

@spec get_endpoints() :: {:ok, [map()]} | {:error, term()}

Load the OpenAPI specification and return all available endpoints.

Returns a list of endpoint maps with metadata from the OpenAPI spec.

get_operations_by_resource()

@spec get_operations_by_resource() :: {:ok, map()} | {:error, term()}

Get all available operations grouped by tag/resource.

Returns a map where keys are resource names and values are lists of operations.

list_operations()

@spec list_operations() :: {:ok, [map()]} | {:error, term()}

List all available API operations with their documentation.

Returns a list of operation maps with full metadata.