Skip to content

Commit

Permalink
TestIssue430: fix racey behavior (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenollp committed May 31, 2022
1 parent 39add0a commit 12540af
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
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

0 comments on commit 12540af

Please sign in to comment.