Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestIssue430: fix racey behavior #553

Merged
merged 3 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
env:
GOARCH: '386'
- run: go test ./...
- run: go test -count=2 ./...
- run: go test -v -run TestRaceyPatternSchema -race ./...
env:
CGO_ENABLED: '1'
Expand Down
11 changes: 6 additions & 5 deletions openapi3/schema_formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ const (
FormatOfStringForUUIDOfRFC4122 = `^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$`
)

//FormatCallback custom check on exotic formats
type FormatCallback func(Val string) error
// FormatCallback performs custom checks on exotic formats
type FormatCallback func(value string) error

// Format represents a format validator registered by either DefineStringFormat or DefineStringFormatCallback
type Format struct {
regexp *regexp.Regexp
callback FormatCallback
}

//SchemaStringFormats allows for validating strings format
var SchemaStringFormats = make(map[string]Format, 8)
// SchemaStringFormats allows for validating string formats
var SchemaStringFormats = make(map[string]Format, 4)

//DefineStringFormat Defines a new regexp pattern for a given format
// DefineStringFormat defines a new regexp pattern for a given format
func DefineStringFormat(name string, pattern string) {
re, err := regexp.Compile(pattern)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions openapi3/schema_formats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ func TestIssue430(t *testing.T) {
NewStringSchema().WithFormat("ipv6"),
)

delete(SchemaStringFormats, "ipv4")
delete(SchemaStringFormats, "ipv6")

err := schema.Validate(context.Background())
require.NoError(t, err)

Expand Down