Skip to content

Migrate C# codegen to blueprint-based model builder#304

Draft
razor-x wants to merge 4 commits into
mainfrom
claude/codegen-cleanup-blueprint-6s6k6x
Draft

Migrate C# codegen to blueprint-based model builder#304
razor-x wants to merge 4 commits into
mainfrom
claude/codegen-cleanup-blueprint-6s6k6x

Conversation

@razor-x

@razor-x razor-x commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary

Refactored the C# SDK code generator to depend exclusively on the @seamapi/blueprint specification instead of the raw OpenAPI schema. This simplifies the build pipeline by eliminating OpenAPI-specific parsing logic while maintaining output compatibility.

Key Changes

  • Rewrote codegen/lib/build-model.ts: Replaced OpenAPI schema traversal with blueprint-based model building. The new implementation derives types, resources, and properties directly from the normalized blueprint, which already resolves type distinctions (int vs. float, enum members, inline objects, discriminated unions).

  • Simplified codegen/lib/csharp.ts: Removed OpenAPI type imports and parsing helpers. The codegen now works exclusively with blueprint types (Blueprint, Endpoint).

  • Removed OpenAPI utility modules: Deleted temporary workaround files that ported OpenAPI-specific logic:

    • codegen/lib/openapi/flatten-obj-schema.ts
    • codegen/lib/openapi/deep-flatten-one-of-and-all-of-schema.ts
    • codegen/lib/openapi/get-parameter-and-response-schema.ts
    • codegen/lib/openapi/get-filtered-routes.ts
    • codegen/lib/types.ts
    • codegen/lib/schema-modifications.ts
  • Updated codegen/smith.ts: Changed to use blueprint-based partials from @seamapi/smith instead of Handlebars-specific utilities.

  • Generated output updates: Regenerated C# model and API classes with nullable reference type annotations (?) applied consistently across properties. This includes:

    • Making previously required fields nullable where appropriate (e.g., PhoneSession, Device, AccessCode, AcsUser, etc.)
    • Updating DataMember attributes to reflect IsRequired = false for nullable properties
    • Removing deprecated API classes (ClimateSettingSchedulesThermostats, EnrollmentAutomationsUserIdentities, Networks, CredentialProvisioningAutomationsAcs, UnmanagedUsersAcs, UnmanagedAccessGroupsAcs, ClientSessionsV1InstantKeySeam, CredentialPoolsAcs)
    • Removing deprecated model classes (ClimateSettingSchedule, Location, PartnerResource, ServiceHealth, Network, PhoneRegistration, Pagination)
    • Adding new API endpoints (e.g., GetRequest in UnmanagedAccessGrants, UnmanagedUserIdentities)
    • Adding new enum values (e.g., off mode in thermostat HVAC settings)

Implementation Details

The blueprint-based approach eliminates the need to distinguish between OpenAPI's int/float, Object/object, and inline enum handling, as the blueprint already normalizes these distinctions. This reduces code complexity and makes the generator more maintainable by depending on a single, well-defined specification format.

https://claude.ai/code/session_01ThCbfBhJb4Hydvo8Es4qJA

claude and others added 4 commits July 23, 2026 21:24
Replace the OpenAPI-spec parsing port with a generator that depends solely
on @seamapi/blueprint, removing every TEMPORARY/TODO output-parity workaround.

- smith.ts wires the @seamapi/smith `blueprint` plugin and the csharp plugin
  reads the resolved blueprint from Metalsmith metadata.
- build-model.ts normalizes blueprint resources, endpoints, parameters, and
  properties into the durable class-model, resolving int vs. float, enum
  members, inline objects, and discriminated unions directly from the
  blueprint (no schema traversal).
- csharp.ts iterates blueprint.resources / routes and emits action_attempt and
  event as discriminated unions.
- Delete the OpenAPI parsing helpers (lib/openapi/*), the ported types.ts, and
  schema-modifications.ts.
- Regenerate the C# output. Model properties are now uniformly optional and
  nullable (the blueprint does not carry per-property required/nullable
  metadata); Api class names derive from the route path. Prune generated files
  for routes/resources no longer present in the blueprint.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ThCbfBhJb4Hydvo8Es4qJA
The blueprint now exposes `isOptional` and `isNullable` on properties. Map
them to the two orthogonal C# concepts instead of emitting every model
property as optional+nullable:

- DataMember IsRequired = !isOptional (payload presence)
- C# nullable annotation = isNullable (value may be null)

Endpoint parameters are unchanged (they carry isRequired). Bump
@seamapi/blueprint to ^0.60.0. The generated output is regenerated and
formatted by the Generate CI workflow.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ThCbfBhJb4Hydvo8Es4qJA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants