Skip to content

naming_conventions

Francisco Dias edited this page Jun 30, 2026 · 3 revisions

Naming Conventions

The prefix system

GML has no namespaces. The --prefix flag (default: gm) generates four derived tokens that are prepended to every generated name to prevent collisions:

Token Example (gm) Used for
{prefix}_ gm_ Public functions (endpoint wrappers, cookie API, auth API)
_{prefix}_ _gm_ Private helpers (singleton getter, create_request, cookie_capture)
{Prefix} Gm Struct constructor names
{PREFIX}_ GM_ Macros and constants (reserved for future use)

With --prefix petstore:

  • Public: petstore_get_pet()
  • Private: _petstore_get_singleton()
  • Struct: PetstoreUser

Endpoint function names

Names are derived from the operation's operationId field (required — the tool throws if absent).

The tag name (first entry in operation.tags) is prepended as a group prefix. Both operationId and the tag are converted to snake_case.

operationId: "getUserById"   tag: "Users"
→ users_get_user_by_id

operationId: "createOrder"   tag: "Orders"
→ orders_create_order

operationId: "healthCheck"   (no tag)
→ health_check

The full public name is {prefix}_{group}_{snake_operationId}.

snake_case conversion rules

The ToSnake() helper:

  1. Protects known acronyms/exceptions from being split (OAuth2, OAuth, iOS, eBay, GitHub, iPhone) — these are lowercased as a single token.
  2. Inserts _ at camelCase boundaries (userIduser_id).
  3. Inserts _ at acronym boundaries (XMLParserxml_parser).
  4. Replaces non-alphanumeric characters with _.
  5. Collapses consecutive _, trims leading/trailing _, lowercases.

Duplicate name resolution

If two operations map to the same generated name, numeric suffixes are appended: get_item, get_item_2, get_item_3, …

GML keyword safety

If a generated name would clash with a GML reserved word (if, while, global, true, false, undefined, etc.) the conflict is resolved at the parameter level by prefixing with _. The full reserved list is in NameUtils.Reserved.

Parameter names

All parameters are prefixed with _ and converted to snake_case:

"userId"     → _user_id
"max-count"  → _max_count
"OAuth2Token" → _oauth2_token

Struct field names

Fields follow the same _snake_case conversion. Fields whose raw name is not a valid GML identifier (contains special characters) use bracket syntax in the constructor:

self[$ "x-rate-limit"] = _x_rate_limit;   // invalid ident → bracket
id = _id;                                  // valid → direct assignment

Struct names

schema name: "UserProfile"   prefix: gm
→ struct constructor: GmUserProfile
→ validate function:  GmUserProfile_validate

Generated private names

Internal variables inside endpoint functions use double-underscore-wrapped identifiers to minimise collision risk with user locals:

static __base_url__    // cached server URL
var    __url__         // final request URL
static __content_type__ // cached content-type constant
var    __security__    // auth scheme array for this request

Extension options

The generated helpers read two GameMaker Extension options from the extension named after the struct prefix:

extension_get_option_value("Gm", "server_rest_url")   // base URL
extension_get_option_value("Gm", "debug_logging")     // bool

Create an extension with the matching name and these option keys, or replace the helper functions with a custom implementation.

Clone this wiki locally