Repository navigation
reflect: accept ipv4 and ipv6 in net.IP schema - #201
Closed
AdamMagued wants to merge 1 commit into
Closed
AdamMagued wants to merge 1 commit into
AdamMagued wants to merge 1 commit into
Conversation
Author
|
Closing in favor of earlier community PR #199 to keep the review queue clean. |
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.
Fixes #198
Root Cause Analysis
Go's standard library
net.IP.UnmarshalTextunmarshals text representations of IP addresses by callingnet.ParseIP, which accepts both IPv4 (dotted-decimal) and IPv6 addresses. However,invopop/jsonschemareflectednet.IPexclusively into an IPv4 string schema:This caused valid IPv6 addresses accepted by
net.IPin Go to fail validation against schemas generated byjsonschema.Solution
Updated
reflect.goto generate ananyOfschema fornet.IPcontaining bothipv4andipv6string format schemas:{ "anyOf": [ {"type": "string", "format": "ipv4"}, {"type": "string", "format": "ipv6"} ] }This accurately models the formats accepted by
net.IP.UnmarshalText. Updated existing test fixtures and added regression unit tests inreflect_test.goverifying schema generation for struct fields of typenet.IPand direct reflection ofnet.IP.Verification
go test -v -race ./...: 100% tests passed.go vet ./...: 0 warnings.git diff --check: 0 whitespace issues.