fix: preserve JSONSchemaExtend description; support {m,n} in tag patterns#191
Open
nghiack7 wants to merge 1 commit into
Open
fix: preserve JSONSchemaExtend description; support {m,n} in tag patterns#191nghiack7 wants to merge 1 commit into
nghiack7 wants to merge 1 commit into
Conversation
Two related bugs in tag parsing: 1. (invopop#169) structKeywordsFromTags always assigned jsonschema_description to t.Description, even when the tag was absent (empty string). This silently overwrote descriptions set earlier by JSONSchemaExtend. Fix: only assign when the tag is non-empty. 2. (invopop#181) splitOnUnescapedCommas split on commas inside regex quantifiers like {0,2}, truncating the pattern value. The existing backslash-escape convention (\,) worked, but required users to manually escape every comma in their regex, which is unintuitive. Fix: rewrite the function to track brace-nesting depth and skip commas inside {…}. The backslash-escape convention is still supported. Add tests: - TestSplitOnUnescapedCommas: three new cases covering {m,n} quantifiers - TestDescriptionPreservedFromJSONSchemaExtend: verifies description from JSONSchemaExtend is not overwritten by an absent jsonschema_description tag - TestPatternWithQuantifierComma: end-to-end test generating a schema with pattern=^[A-Z]{0,3}$ and verifying the full pattern reaches the output
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.
Two related tag-parsing bugs, both in
reflect.go:Bug 1: JSONSchemaExtend description overwritten (#169)
structKeywordsFromTagsunconditionally assignedjsonschema_descriptiontot.Description, even when the tag was absent:When a type implements
JSONSchemaExtendand sets a field's description, the property schema is first built byrefOrReflectTypeToSchema(which callsJSONSchemaExtend), thenstructKeywordsFromTagsruns and silently clears the description with an empty string.Fix: only assign when the tag is non-empty:
Bug 2: Regex quantifiers
{m,n}truncated in pattern tags (#181)splitOnUnescapedCommassplit on all unescaped commas, including those inside regex quantifiers like{0,2}:The old backslash-escape convention (
\,) still worked, but required users to manually escape every comma inside quantifiers, which was non-obvious and undocumented.Fix: rewrite
splitOnUnescapedCommasto track brace-nesting depth and skip commas inside{…}. The backslash-escape convention is still supported for backwards compatibility.Tests added
TestSplitOnUnescapedCommas: 3 new cases covering{m,n},{1,{2,3}}nestingTestDescriptionPreservedFromJSONSchemaExtend: verifies description fromJSONSchemaExtendsurvivesstructKeywordsFromTagsTestPatternWithQuantifierComma: end-to-end schema generation withpattern=^[A-Z]{0,3}$All existing tests pass.