Support field aliases from json case:ignore tag#200
Merged
Conversation
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>
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:
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! |
Author
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
encoding/json/v2supports thecase:ignoreJSON tag option, which lets afield be matched against alternative naming conventions (e.g. snake_case /
camelCase). This PR surfaces those alternative names so they can be documented:
case:ignorenow expose their alternative names viaField.Aliases, available in templates (markdown & asciidoctor).processor.caseIgnoreAliasesoption controls which naming conventionsare 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 (
v1Beta→v1_beta).Changes
Field.Aliasesand populate it from the jsoncase:ignoretag optionprocessor.caseIgnoreAliasesconfig option (documented in the README)hasCaseIgnore,toSnakeCase,toCamelCaseandderiveAliases, including acronym, digit-boundary and identical-derivationedge cases