fix: ts:"-" fields now appear in OpenAPI spec#21
Merged
Conversation
48873a7 to
5960a3c
Compare
Previously ts:"-" and json:"-" both mapped to Ignored state, causing fields to be dropped from the shared parser data model used by both the TypeScript and Swagger printers. Add a TsIgnored state so ts:"-" fields pass through the parser into record.Fields. The TypeScript printer filters them at render time; the Swagger printer sees them unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
5960a3c to
5cb9ffb
Compare
The header fallback in ParseStructTag was unconditionally overriding State to Optional, clobbering TsIgnored for fields tagged both header:"X-..." and ts:"-". Those fields then leaked into TypeScript output as hyphenated property names, producing invalid syntax. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ts_client.go was only skipping Ignored/NoInfo fields when building the JSON field list for route metadata. TsIgnored fields (ts:"-") now also need to be skipped so the TypeScript client is unaffected by the OpenAPI fix. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
json:"...,omitempty" was unconditionally setting State=Optional, clobbering TsIgnored for fields tagged both omitempty and ts:"-". Those fields then passed the TsIgnored filter and leaked into TypeScript route metadata and type output. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Previously, visiting a TsIgnored field's type for Swagger $ref resolution caused the type and all its subtypes to be registered as TypeScript-visible, resulting in spurious enum/type emissions in the generated TypeScript client. Track TypeScript visibility separately from Swagger visibility in the parser. When traversing a TsIgnored field's type tree, mark those types as Swagger-only by setting inTsIgnored=true. The TypeScript printer filters the visitOrder to only emit types marked as tsVisible. Also add tests covering the new subtype-exclusion behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
go/doc excludes unexported fields (e.g. protobuf's state protoimpl.MessageState) from v2.Fields.List, so index-based AST field lookup was off-by-N for structs that start with unexported fields, causing field comments to be assigned to the wrong fields in TypeScript output. Switch to name-based lookup using a map[string]*ast.Field built from the AST fields, so reflect index mismatches are impossible regardless of unexported field layout. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
starzu-cyberhaven
approved these changes
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ts:"-"andjson:"-"previously both mapped toIgnoredstate, causingts:"-"fields to be silently dropped from the OpenAPI spec even though they are present on the wireTsIgnoredstate so the shared parser retains these fields; the TypeScript printer filters them at render time, the Swagger printer sees them unchangedjson:"-"behavior is unchanged — those fields are still excluded everywhereTest Plan
ParseStructTagassertingts:"-"→TsIgnoredandjson:"-"→Ignoredts:"-"field is absent from TypeScript outputts:"-"field is present in Swagger/OpenAPI output🤖 Generated with Claude Code