Skip to content

getting_started

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

Getting Started

Build

Clone the repo and build the active solution.

git clone https://github.com/YoYoGames/GM-SwaggerCodeGen.git
cd GM-SwaggerCodeGen\GMExtensionCodeGen
dotnet build -c Release

The binary lands at GMSwaggerCodeGen\bin\Release\net9.0\GMSwaggerCodeGen.exe.

The repository also contains a refactored solution under OpenAPIGenerator/ (fdias-dev-refactor branch). Both solutions share the same CLI surface and produce identical output. The OpenAPIGenerator/ layout separates the language-agnostic code-writer library (codegencore) from the OpenAPI-specific generator (openapigen).

First run

Point the tool at your OpenAPI spec:

GMSwaggerCodeGen.exe -i path\to\openapi.json -o out --prefix gm

The out/ directory will contain:

out/
  generated_schemas.gml
  generated_http.gml
  generated_helpers.gml
  controller_create.gml
  controller_http.gml
  controller_cleanup.gml
  schemas_codegen.js    (only with --lang docs or default)
  function_codegen.js   (only with --lang docs or default)

Wiring the output into GameMaker

  1. Add the GML files to your project (drag into the Script or Extension asset).

  2. Create a persistent manager object — by convention, obj_gm_core (the prefix matches --prefix). Make it persistent so it survives room transitions.

  3. Paste the controller snippets into the object's events:

    File Event
    controller_create.gml Create
    controller_http.gml Async — HTTP
    controller_cleanup.gml Clean Up
  4. Place one instance of obj_gm_core in your first room (or create it in code). The singleton helper (_gm_get_singleton()) will locate it automatically.

  5. Call an endpoint:

    gm_my_endpoint(_param1, _param2, function(_status, _data, _request) {
        show_debug_message($"status={_status} data={json_stringify(_data)}");
    });

Setting auth tokens

Before calling secured endpoints, store the credential:

gm_request_auth_set_token("bearer_scheme_name", "your-jwt-here");

The generated code injects it automatically on every request that requires that scheme.

Regenerating

Re-run the tool whenever the spec changes. The output files are fully generated — do not hand-edit them. Keep any custom converters or hooks in separate scripts.

Clone this wiki locally