Skip to content

fix: ts:"-" fields now appear in OpenAPI spec#21

Merged
tiko-ch merged 6 commits into
masterfrom
fix/field_exclusion
Jun 9, 2026
Merged

fix: ts:"-" fields now appear in OpenAPI spec#21
tiko-ch merged 6 commits into
masterfrom
fix/field_exclusion

Conversation

@tiko-ch

@tiko-ch tiko-ch commented Jun 4, 2026

Copy link
Copy Markdown

Summary

  • ts:"-" and json:"-" previously both mapped to Ignored state, causing ts:"-" fields to be silently dropped from the OpenAPI spec even though they are present on the wire
  • Added a distinct TsIgnored state so the shared parser retains these fields; the TypeScript printer filters them at render time, the Swagger printer sees them unchanged
  • json:"-" behavior is unchanged — those fields are still excluded everywhere

Test Plan

  • Unit tests for ParseStructTag asserting ts:"-"TsIgnored and json:"-"Ignored
  • Integration test asserting a ts:"-" field is absent from TypeScript output
  • Integration test asserting a ts:"-" field is present in Swagger/OpenAPI output
  • Full test suite passes (184 tests)

🤖 Generated with Claude Code

@tiko-ch tiko-ch force-pushed the fix/field_exclusion branch from 48873a7 to 5960a3c Compare June 4, 2026 21:22
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>
@tiko-ch tiko-ch force-pushed the fix/field_exclusion branch from 5960a3c to 5cb9ffb Compare June 4, 2026 21:30
tiko-ch and others added 5 commits June 4, 2026 23:41
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>
@tiko-ch tiko-ch merged commit 7b4d6bb into master Jun 9, 2026
1 check passed
@tiko-ch tiko-ch deleted the fix/field_exclusion branch June 9, 2026 09:55
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.

2 participants