Skip to content

Commit

Permalink
Merge pull request #25 from jawn-smith/main
Browse files Browse the repository at this point in the history
Add format to array items subschema
  • Loading branch information
samlown committed Jul 21, 2022
2 parents d9664d9 + c594e8d commit d780b03
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions reflect.go
Expand Up @@ -834,6 +834,8 @@ func (t *Schema) arrayKeywords(tags []string) {
f, _ := strconv.ParseFloat(val, 64)
t.Items.Enum = append(t.Items.Enum, f)
}
case "format":
t.Items.Format = val
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions reflect_test.go
Expand Up @@ -477,3 +477,20 @@ func TestSplitOnUnescapedCommas(t *testing.T) {
require.Equal(t, test.expected, actual)
}
}

func TestArrayFormat(t *testing.T) {
type URIArray struct {
TestURIs []string `jsonschema:"type=array,format=uri"`
}

var jsonReflector Reflector
schema := jsonReflector.Reflect(&URIArray{})

URIInterface, found := schema.Definitions["URIArray"].Properties.Get("TestURIs")
require.Equal(t, found, true)

var URIArrayProperties *Schema = URIInterface.(*Schema)

URIArrayType := URIArrayProperties.Items.Format
require.Equal(t, URIArrayType, "uri")
}

0 comments on commit d780b03

Please sign in to comment.