Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cli/cli/Services/Web/CodeGen/TsProperty.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using cli.Services.Web.Helpers;

namespace cli.Services.Web.CodeGen;

/// <summary>
Expand Down Expand Up @@ -148,7 +150,7 @@ public override void Write(TsCodeWriter writer)
if (Modifiers.HasFlag(TsModifier.Abstract))
writer.Write($"{TsModifierExtensions.Abstract} ");

writer.Write(Name);
writer.Write(StringHelper.QuoteIfNeeded(Name));

if (IsOptional)
writer.Write("?");
Expand Down
4 changes: 3 additions & 1 deletion cli/cli/Services/Web/CodeGen/TsType.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using cli.Services.Web.Helpers;

namespace cli.Services.Web.CodeGen;

/// <summary>
Expand Down Expand Up @@ -322,7 +324,7 @@ public override void Write(TsCodeWriter w)

for (int i = 0; i < _props.Length; i++)
{
w.Write(_props[i].name);
w.Write(StringHelper.QuoteIfNeeded(_props[i].name));

if (_props[i].propType == PropType.Optional)
w.Write("?");
Expand Down
1 change: 1 addition & 0 deletions cli/cli/Services/Web/Helpers/OpenApiMethodNameGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ private static string HttpVerbPrefix(string verb)
"POST" => "Post",
"PUT" => "Put",
"DELETE" => "Delete",
"PATCH" => "Patch",
_ => "Get"
};
}
13 changes: 13 additions & 0 deletions cli/cli/Services/Web/Helpers/StringHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ public static string ToSafeIdentifier(string input)
return sanitized;
}

/// <summary>
/// Returns true if the input is NOT a valid unquoted TypeScript identifier.
/// </summary>
public static bool NeedsQuoting(string input)
=> string.IsNullOrEmpty(input) || !Regex.IsMatch(input, @"^[A-Za-z_$][A-Za-z0-9_$]*$");

/// <summary>
/// Returns the property name quoted if it contains characters invalid for
/// an unquoted TypeScript identifier, otherwise returns it as-is.
/// </summary>
public static string QuoteIfNeeded(string name)
=> NeedsQuoting(name) ? $"\"{name}\"" : name;

/// <summary>
/// Converts a string to a PascalCase identifier.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions cli/cli/Services/Web/Helpers/WebApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ private static void GenerateApiMethod(OpenApiDocument document, Dictionary<strin
.Where(p => p.In == ParameterLocation.Header)
// Exclude 'X-BEAM-SCOPE' header; it is set by default via the Beam Web SDK.
.Where(p => p.Name != "X-BEAM-SCOPE")
// Only include headers that makeApiRequest supports (currently just X-BEAM-GAMERTAG).
.Where(p => p.Name == "X-BEAM-GAMERTAG")
.ToList();

foreach (var (httpMethod, operation) in pathItem.Operations)
Expand Down
17 changes: 17 additions & 0 deletions web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- `codegen` script in `package.json` to regenerate TypeScript API types from OpenAPI specs via the CLI.
- New generated APIs: `BillingApi`, `CustomerApi`, `PlayerSessionApi`, `PlayerStatsApi`.

### Fixed

- Web code generator now quotes TypeScript property names that contain invalid identifier characters (e.g., `x5t#S256`).
- Web code generator now produces distinct method names for PATCH endpoints instead of colliding with GET.
- `tsdown.config.ts` updated to use `import.meta.url` instead of `__dirname` for ES module compatibility.

### Changed

- Updated auto-generated APIs and schemas to latest OpenAPI specs.

## [1.0.0] - 2025-11-19

### Added
Expand Down
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"test": "vitest",
"lint": "eslint --ext .ts src tests",
"format": "prettier --write .",
"codegen": "WEB_DIR=$PWD && cd \"$WEB_DIR/..\" && [ -f build-number.txt ] || echo 0 > build-number.txt && dotnet run -f net10.0 --project ./cli/cli -- --host https://dev.api.beamable.com oapi generate --engine web --conflict-strategy RenameUncommonConflicts --output \"$WEB_DIR/src/__generated__\"",
"doc": "node ./generateDocs.mjs",
"release": "node ./update-version.mjs && pnpm build",
"prepublishOnly": "pnpm build"
Expand Down
5 changes: 3 additions & 2 deletions web/samples/WordWiz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"vite-plugin-mkcert": "^1.17.8",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^3.2.4"
}
}
},
"packageManager": "pnpm@10.33.0"
}
98 changes: 14 additions & 84 deletions web/src/__generated__/apis/AccountsApi.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading