Skip to content

Commit

Permalink
Merge pull request #111 from cloudquery/fix/no-format-limits
Browse files Browse the repository at this point in the history
fix: Don't limit the explicit format
  • Loading branch information
samlown committed Feb 19, 2024
2 parents 15fa257 + 992e094 commit a446707
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
31 changes: 31 additions & 0 deletions fixtures/with_custom_format.json
@@ -0,0 +1,31 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/invopop/jsonschema/with-custom-format",
"$ref": "#/$defs/WithCustomFormat",
"$defs": {
"WithCustomFormat": {
"properties": {
"dates": {
"items": {
"type": "string",
"format": "date"
},
"type": "array"
},
"odds": {
"items": {
"type": "string",
"format": "odd"
},
"type": "array"
}
},
"additionalProperties": false,
"type": "object",
"required": [
"dates",
"odds"
]
}
}
}
5 changes: 1 addition & 4 deletions reflect.go
Expand Up @@ -768,10 +768,7 @@ func (t *Schema) stringKeywords(tags []string) {
case "pattern":
t.Pattern = val
case "format":
switch val {
case "date-time", "email", "hostname", "ipv4", "ipv6", "uri", "uuid":
t.Format = val
}
t.Format = val
case "readOnly":
i, _ := strconv.ParseBool(val)
t.ReadOnly = i
Expand Down
12 changes: 12 additions & 0 deletions reflect_test.go
Expand Up @@ -629,6 +629,18 @@ func TestUnsignedIntHandling(t *testing.T) {
fixtureContains(t, "fixtures/unsigned_int_handling.json", `"maxItems": 0`)
}

func TestJSONSchemaFormat(t *testing.T) {
type WithCustomFormat struct {
Dates []string `json:"dates" jsonschema:"format=date"`
Odds []string `json:"odds" jsonschema:"format=odd"`
}

r := &Reflector{}
compareSchemaOutput(t, "fixtures/with_custom_format.json", r, &WithCustomFormat{})
fixtureContains(t, "fixtures/with_custom_format.json", `"format": "date"`)
fixtureContains(t, "fixtures/with_custom_format.json", `"format": "odd"`)
}

type AliasObjectA struct {
PropA string `json:"prop_a"`
}
Expand Down

0 comments on commit a446707

Please sign in to comment.