Skip to content

getting_started

Francisco Dias edited this page Jul 1, 2026 · 5 revisions

Getting Started

Build

Clone the repo and build the solution.

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

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

First run — config file (recommended)

Bootstrap a config in a working folder, then point it at your spec:

openapigen.exe --init ./myapi

This creates ./myapi/config.json and ./myapi/openapigen.schema.json. Open config.json, set "Input" to the path of your OpenAPI spec, and run:

openapigen.exe --config ./myapi/config.json

Generated files land in the folder specified by "Gml.OutputFolder" (default: ./myapi/build).

config.json format

{
  "$schema": "./openapigen.schema.json",
  "Input": "./openapi.json",
  "Prefix": "gm",
  "Gml": {
    "Enabled": true,
    "OutputFolder": "./build"
  },
  "Docs": {
    "Enabled": false,
    "OutputFolder": "./build"
  }
}

First run — direct mode

For one-off runs without a config file:

openapigen.exe --input openapi.json --output out --prefix gm

Add --docs to also emit documentation stubs.

Output files

out/
  generated_schemas.gml
  generated_http.gml
  generated_helpers.gml
  controller_create.gml
  controller_http.gml
  controller_cleanup.gml
  schemas_codegen.js    (only with Docs.Enabled: true or --docs)
  function_codegen.js   (only with Docs.Enabled: true or --docs)

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 scheme name must match the key in components.securitySchemes of the spec. The generated code injects the token 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