Skip to content
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
15 changes: 15 additions & 0 deletions openapi3/issue697_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package openapi3

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestIssue697(t *testing.T) {
loader := NewLoader()
doc, err := loader.LoadFromFile("testdata/issue697.yml")
require.NoError(t, err)
err = doc.Validate(loader.Context)
require.NoError(t, err)
}
10 changes: 9 additions & 1 deletion openapi3/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"regexp"
"sort"
"strconv"
"strings"
"unicode/utf16"

"github.com/go-openapi/jsonpointer"
Expand Down Expand Up @@ -180,7 +181,14 @@ func (schema *Schema) MarshalJSON() ([]byte, error) {

// UnmarshalJSON sets Schema to a copy of data.
func (schema *Schema) UnmarshalJSON(data []byte) error {
return jsoninfo.UnmarshalStrictStruct(data, schema)
err := jsoninfo.UnmarshalStrictStruct(data, schema)
if schema.Format == "date" {
// This is a fix for: https://github.com/getkin/kin-openapi/issues/697
if eg, ok := schema.Example.(string); ok {
schema.Example = strings.TrimSuffix(eg, "T00:00:00Z")
}
}
return err
}

// JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable
Expand Down
14 changes: 14 additions & 0 deletions openapi3/testdata/issue697.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
openapi: 3.0.1
components:
schemas:
API:
properties:
dateExample:
type: string
format: date
example: 2019-09-12
info:
title: sample
version: version not set
paths: {}