Skip to content

fix(management-sdk): generate from a committed API spec - #849

Merged
roncohen merged 2 commits into
mainfrom
fix/management-sdk-pinned-spec
Dec 1, 2026
Merged

roncohen merged 2 commits into
mainfrom
fix/management-sdk-pinned-spec

Conversation

@roncohen

@roncohen roncohen commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The Management SDK's build wasn't reproducible. openapi-generator.config.yaml read the spec from https://app.reflag.com/openapi.json, and the committed openapi.json was an empty file. Every yarn build, including the release build, regenerated src/generated from whatever production served at that moment.

The live spec has changed since the client was last regenerated in #721, so the 2.0.0 release build produced uncommitted changes. That made the docs-sync step fail its clean-checkout check after publishing. Until this is fixed, every release will hit the same failure, and the next Management SDK release would ship code nobody reviewed.

Fix

  • Commit the current API spec as openapi.json, and point inputSpec at it. Builds now generate the same code every time.
  • Add yarn update-spec, which downloads the latest spec. To update the client, run yarn update-spec && yarn generate and commit both, so spec changes go through review.
  • Leave openapi.json out of oxfmt formatting, so the committed file matches what update-spec writes.
  • Regenerate the client from the committed spec with the pinned generator (7.19.0).
  • Add scripts/prepare-spec.mjs, which runs before generation. The generator flattens anyOf unions into one object with every field required, so a converter for effectiveRules filters would map filters on every filter and throw for anything but a group. The script rewrites unions tagged by a type constant as oneOf with a type discriminator, so the generator emits a real union that switches on type. It writes to an ignored .openapi.generated.json and leaves the committed spec untouched, so the fix survives update-spec. Today, only effectiveFlagFilter matches.

API changes in the regenerated client

  • Flags include flagType (boolean or multivariate), and createFlag accepts it. It's optional and defaults to boolean, so existing calls are unchanged.
  • FlagTargeting includes targetingMode and effectiveRules, the compiled rules that decide whether the flag is on. This adds 8 new models.
  • Endpoint descriptions are updated to match the API.

The changeset is a minor bump for @reflag/management-sdk. The README notes the flagType default.

Testing

  • Regenerating from the committed spec reproduces exactly the files the 2.0.0 release build modified.
  • tsc --project tsconfig.build.json passes, and the Management SDK tests (9) pass.
  • A new test parses FlagTargeting JSON containing every filter variant, including a group with a nested negation, and serializes it back to the same JSON.

@reflag-review reflag-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: high

2 actionable findings.

@reflag-review reflag-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: medium

no actionable findings

@roncohen
roncohen added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit 87fd6ea Dec 1, 2026
9 checks passed
@roncohen
roncohen deleted the fix/management-sdk-pinned-spec branch December 1, 2026 08:12
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.

1 participant