Skip to content

fix(typescript,mcp): validate usageSDKInitImports and advancedFlags in gen.yaml - #154

Open
2ynn wants to merge 2 commits into
mainfrom
fix/typescript/wire-config-field-validation
Open

2ynn wants to merge 2 commits into
mainfrom
fix/typescript/wire-config-field-validation

Conversation

@2ynn

@2ynn 2ynn commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Why

Two config fields declare their gen.yaml checks as a ValidationFunc on the field definition in config.ts:

  • typescriptv2 usageSDKInitImports: must be an array of objects with a non-empty package and import, and an optional type of typeImport, packageImport, or aliasImport.
  • mcp-typescript advancedFlags: must be an array of alphanumeric strings.

Nothing reads ValidationFunc. GetLanguageConfigFields decodes the field definitions into sdk-gen-config's SDKGenConfigField, which has no such field, so the key is dropped and neither check has ever run. Malformed values are accepted silently: a usageSDKInitImports entry without import passes an undefined import name to addUsageImport, and an advancedFlags entry such as dry-run can never match a flag name, because gatherMCPFlags compares entries against sanitizeFieldName(flag.Name).

What changed

  • templates/templates/typescriptv2/config.ts, templates/templates/mcp-typescript/config.ts: each check moves into a target-level validateConfig(cfg). This is the hook Generator.validateConfig (pkg/generate/configuration.go) already runs on gen.yaml for the cli, go, javav2, php, pythonv2, and ruby targets; a non-empty message fails generation with gen.yaml validation error for <target>: <message>. The ValidationFunc keys are removed.
  • The usageSDKInitImports check resolves package || Package, import || Import, and type || Type before validating, matching templateUsageSDKInit, so entries using the capitalized keys keep generating.
  • Absent and null values are skipped. Templating already treats both as empty (templateUsageSDKInit checks Array.isArray, gatherMCPFlags checks truthiness), and an empty usageSDKInitImports: or advancedFlags: key in gen.yaml decodes to null, which the old function would have rejected.
  • pkg/generate/typescript_config_validation_test.go: error and success cases for both fields, including capitalized and mixed-case import keys, every import type, empty and non-string values, and empty flag names, through Generator.validateConfig, in the same style as cli_config_validation_test.go. That file's newCLITestConfig helper becomes newLanguageTestConfig(target, cfg) so both test files share it.
  • Changeset: core / typescriptv2, mcp-typescript patch.

Behaviour change: a gen.yaml with a malformed value for either field now fails validation instead of generating. Import types other than typeImport, packageImport, or aliasImport now fail validation. Previously, unrecognized values silently rendered as typeImport. Generated output for valid configurations does not change, so no review SDKs are regenerated; the existing review and test configurations (advancedFlags: [loneQueryParam], usageSDKInitImports: []) pass.

Testing

  • go test ./pkg/generate -run TestValidateConfigTypeScript -count=1: passes. With the template changes reverted, all 15 error cases fail.
  • go test ./pkg/generate -count=1: passes.
  • cmd/generate against a one-operation spec, with gen.yaml leaving templateVersion unset:
    • typescript with usageSDKInitImports: [{package: "@acme/sdk"}] fails with gen.yaml validation error for typescript: usageSDKInitImports[0].import must be a non-empty string; adding import: Acme generates.
    • mcp-typescript with advancedFlags: [dry-run] fails with gen.yaml validation error for mcp-typescript: advancedFlags[0] must contain only letters or numbers; dryRun generates.
  • make check-template-typescriptv2, make check-template-mcp-typescript, make lint: pass.

Public-safety check

  • This change contains no credentials, customer documents, private repository URLs, private filesystem paths, or unredacted private logs.
  • Title, body, comments, and commit messages name no customers or customer-derived identifiers, private paths or trackers, or workflow provenance, and are understandable without private context (.claude/skills/public-repo-communication/SKILL.md).
  • Generated fixtures and review SDK changes are public-safe.
  • I reviewed git diff --check.

…n gen.yaml

The typescriptv2 usageSDKInitImports and mcp-typescript advancedFlags
config fields declared their checks as a ValidationFunc on the field
definition. Nothing reads that key: the field definitions are decoded
into sdk-gen-config's SDKGenConfigField, which has no such field, so
the checks never ran and malformed values were accepted.

Move both checks into a target-level validateConfig, the hook the
generator already runs for gen.yaml on other targets, and skip absent
or null values, which templating already treats as empty.
@github-actions github-actions Bot added mcp-typescript Trigger (16) snapshot tests for mcp-typescript typescript Trigger (168) snapshot tests for typescript labels Oct 26, 2026

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 5 files

Shadow auto-approve: would not auto-approve because issues were found.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread templates/templates/typescriptv2/config.ts Outdated
@2ynn
2ynn marked this pull request as ready for review October 26, 2026 21:04
@2ynn
2ynn requested a review from a team as a code owner October 26, 2026 21:04
@2ynn
2ynn requested a review from mfbx9da4 October 26, 2026 21:04
…ateConfig

templateUsageSDKInit resolves package || Package, import || Import and
type || Type, so validate the same effective values. Add cases for
capitalized and mixed-case keys, every import type, empty and non-string
values, null entries, and empty advancedFlags names.

@cubic-dev-ai cubic-dev-ai 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.

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Moves dead per-field config validators into the target validateConfig hook so malformed usageSDKInitImports/advancedFlags now fail generation; tests and patch changeset included, valid output unchanged.

View guided diff | Turn on auto-fix | Re-trigger cubic

@speakeasy-generator-bot

speakeasy-generator-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Generator Snapshot Testing

Selector(s) Result Summary
snapshot-mcp-typescript, snapshot-typescript ❌ Snapshot run failed

Snapshot results: https://github.com/speakeasy-api/openapi-generation-snapshots/issues/140#issuecomment-6427958477

Snapshot results are summarized above. Additional run context is linked for maintainers with access.

@TristanSpeakEasy TristanSpeakEasy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, moving these checks into validateConfig makes sense. Keeping the capitalised import keys and null values working avoids unnecessary breakage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mcp-typescript Trigger (16) snapshot tests for mcp-typescript typescript Trigger (168) snapshot tests for typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants