1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
package openapi3
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestIssue492(t *testing.T) {
spec := []byte(`
components:
schemas:
Server:
properties:
time:
$ref: "#/components/schemas/timestamp"
name:
type: string
type: object
timestamp:
type: string
format: date-time
openapi: "3.0.1"
paths: {}
info:
version: 1.1.1
title: title
`[1:])
loader := NewLoader()
doc, err := loader.LoadFromData(spec)
require.NoError(t, err)
err = doc.Validate(loader.Context)
require.NoError(t, err)
// verify that the expected format works
err = doc.Components.Schemas["Server"].Value.VisitJSON(map[string]interface{}{
"name": "kin-openapi",
"time": "2001-02-03T04:05:06.789Z",
})
require.NoError(t, err)
// verify that the issue is fixed
err = doc.Components.Schemas["Server"].Value.VisitJSON(map[string]interface{}{
"name": "kin-openapi",
"time": "2001-02-03T04:05:06:789Z",
})
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})?$")`)
}
|