Skip to content

Support field aliases from json case:ignore tag#200

Merged
thbkrkr merged 7 commits into
elastic:masterfrom
AndrewChubatiuk:support-field-aliases
Jun 11, 2026
Merged

Support field aliases from json case:ignore tag#200
thbkrkr merged 7 commits into
elastic:masterfrom
AndrewChubatiuk:support-field-aliases

Conversation

@AndrewChubatiuk

@AndrewChubatiuk AndrewChubatiuk commented Jun 1, 2026

Copy link
Copy Markdown

Summary

encoding/json/v2 supports the case:ignore JSON tag option, which lets a
field be matched against alternative naming conventions (e.g. snake_case /
camelCase). This PR surfaces those alternative names so they can be documented:

  • Fields tagged with json case:ignore now expose their alternative names via
    Field.Aliases, available in templates (markdown & asciidoctor).
  • A new processor.caseIgnoreAliases option controls which naming conventions
    are generated for aliases.

Details

Alias derivation reuses the JSON tag options already parsed for the field name
and runs after the field name is fully resolved, so aliases match the displayed
name. Snake-casing inserts a word boundary before an uppercase letter that
follows a digit (v1Betav1_beta).

Changes

  • Add Field.Aliases and populate it from the json case:ignore tag option
  • Add the processor.caseIgnoreAliases config option (documented in the README)
  • Render aliases in the markdown and asciidoctor type templates
  • Unit tests covering hasCaseIgnore, toSnakeCase, toCamelCase and
    deriveAliases, including acronym, digit-boundary and identical-derivation
    edge cases

AndrewChubatiuk and others added 7 commits June 1, 2026 20:46
Aliases are derived from the json "case:ignore" tag option, not from a
nonexistent "aliases" struct tag.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Move alias derivation below the empty-name fallback so aliases are based
on the final displayed field name (e.g. the type name for embedded
fields) rather than an intermediate value.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Avoid re-fetching and re-splitting the json struct tag: detect the
case:ignore option from the args already parsed for the field name.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A digit followed by an uppercase letter now starts a new word, so
"v1Beta" becomes "v1_beta" instead of "v1beta".

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Cover hasCaseIgnore, toSnakeCase, toCamelCase and deriveAliases,
including acronym, digit-boundary and identical-derivation edge cases.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@thbkrkr

thbkrkr commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Hi @AndrewChubatiuk, thanks for the contribution! 🙏 Nice addition, and the conversion logic is clean.

I pushed a few small follow-up commits on top of your branch:

  1. Unit tests for the new helpers (hasCaseIgnore, toSnakeCase, toCamelCase, deriveAliases), incl. acronym/digit edge cases
  2. Fix the Field.Aliases doc comment (it referenced an "aliases" tag; it's actually json case:ignore)
  3. Document the new processor.caseIgnoreAliases option in the README
  4. Derive aliases after the field name is fully resolved, so they match the displayed name
  5. Reuse the already-parsed json tag options instead of re-parsing
  6. Snake-case digit boundary so v1Betav1_beta

Kept as separate commits for easy review, I would appreciate you taking a look and letting me know if anything doesn't sit right with you. Thanks again!

@AndrewChubatiuk

AndrewChubatiuk commented Jun 11, 2026

Copy link
Copy Markdown
Author

hey @thbkrkr
i'm okay with your changes, thank you
could you please also take a look at
#194?

@thbkrkr thbkrkr changed the title support field aliases Support field aliases from json case:ignore tag Jun 11, 2026
@thbkrkr thbkrkr merged commit fdfed81 into elastic:master Jun 11, 2026
2 checks passed
@AndrewChubatiuk AndrewChubatiuk deleted the support-field-aliases branch June 11, 2026 15:38
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