Skip to content

Commit eaa7245

Browse files
committed
feat #582: use OpenAPI minor version during validation when available
1 parent 808300a commit eaa7245

8 files changed

+948
-439
lines changed

openapi3/issue735_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ func TestIssue735(t *testing.T) {
2020
DefineStringFormat("email", FormatOfStringForEmail)
2121
DefineIPv4Format()
2222
DefineIPv6Format()
23+
// restore modified string formats used during this tests
24+
defer RestoreDefaultStringFormats()
2325

2426
testCases := []testCase{
2527
{

openapi3/schema.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,20 +579,48 @@ func NewStringSchema() *Schema {
579579
}
580580
}
581581

582+
func NewDateSchema() *Schema {
583+
return &Schema{
584+
Type: TypeString,
585+
Format: "date",
586+
}
587+
}
588+
582589
func NewDateTimeSchema() *Schema {
583590
return &Schema{
584591
Type: TypeString,
585592
Format: "date-time",
586593
}
587594
}
588595

596+
func NewHostnameSchema() *Schema {
597+
return &Schema{
598+
Type: TypeString,
599+
Format: "hostname",
600+
}
601+
}
602+
589603
func NewUUIDSchema() *Schema {
590604
return &Schema{
591605
Type: TypeString,
592606
Format: "uuid",
593607
}
594608
}
595609

610+
func NewIPv4Schema() *Schema {
611+
return &Schema{
612+
Type: TypeString,
613+
Format: "ipv4",
614+
}
615+
}
616+
617+
func NewIPv6Schema() *Schema {
618+
return &Schema{
619+
Type: TypeString,
620+
Format: "ipv6",
621+
}
622+
}
623+
596624
func NewBytesSchema() *Schema {
597625
return &Schema{
598626
Type: TypeString,
@@ -1624,7 +1652,7 @@ func (schema *Schema) visitJSONString(settings *schemaValidationSettings, value
16241652
var formatStrErr string
16251653
var formatErr error
16261654
if format := schema.Format; format != "" {
1627-
if f, ok := SchemaStringFormats[format]; ok {
1655+
if f := getSchemaStringFormats(format, settings.openapiMinorVersion); f != nil {
16281656
switch {
16291657
case f.regexp != nil && f.callback == nil:
16301658
if cp := f.regexp; !cp.MatchString(value) {

openapi3/schema_issue492_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ info:
4646
"name": "kin-openapi",
4747
"time": "2001-02-03T04:05:06:789Z",
4848
})
49-
require.ErrorContains(t, err, `Error at "/time": string doesn't match the format "date-time" (regular expression "^[0-9]{4}-(0[0-9]|10|11|12)-([0-2][0-9]|30|31)T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+)?(Z|(\+|-)[0-9]{2}:[0-9]{2})?$")`)
49+
require.ErrorContains(t, err, `Error at "/time": string doesn't match the format "date-time" (regular expression `)
5050
}

0 commit comments

Comments
 (0)