Skip to content

Commit a446707

Browse files
authored
Merge pull request #111 from cloudquery/fix/no-format-limits
fix: Don't limit the explicit format
2 parents 15fa257 + 992e094 commit a446707

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

fixtures/with_custom_format.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://github.com/invopop/jsonschema/with-custom-format",
4+
"$ref": "#/$defs/WithCustomFormat",
5+
"$defs": {
6+
"WithCustomFormat": {
7+
"properties": {
8+
"dates": {
9+
"items": {
10+
"type": "string",
11+
"format": "date"
12+
},
13+
"type": "array"
14+
},
15+
"odds": {
16+
"items": {
17+
"type": "string",
18+
"format": "odd"
19+
},
20+
"type": "array"
21+
}
22+
},
23+
"additionalProperties": false,
24+
"type": "object",
25+
"required": [
26+
"dates",
27+
"odds"
28+
]
29+
}
30+
}
31+
}

reflect.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,10 +768,7 @@ func (t *Schema) stringKeywords(tags []string) {
768768
case "pattern":
769769
t.Pattern = val
770770
case "format":
771-
switch val {
772-
case "date-time", "email", "hostname", "ipv4", "ipv6", "uri", "uuid":
773-
t.Format = val
774-
}
771+
t.Format = val
775772
case "readOnly":
776773
i, _ := strconv.ParseBool(val)
777774
t.ReadOnly = i

reflect_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,18 @@ func TestUnsignedIntHandling(t *testing.T) {
629629
fixtureContains(t, "fixtures/unsigned_int_handling.json", `"maxItems": 0`)
630630
}
631631

632+
func TestJSONSchemaFormat(t *testing.T) {
633+
type WithCustomFormat struct {
634+
Dates []string `json:"dates" jsonschema:"format=date"`
635+
Odds []string `json:"odds" jsonschema:"format=odd"`
636+
}
637+
638+
r := &Reflector{}
639+
compareSchemaOutput(t, "fixtures/with_custom_format.json", r, &WithCustomFormat{})
640+
fixtureContains(t, "fixtures/with_custom_format.json", `"format": "date"`)
641+
fixtureContains(t, "fixtures/with_custom_format.json", `"format": "odd"`)
642+
}
643+
632644
type AliasObjectA struct {
633645
PropA string `json:"prop_a"`
634646
}

0 commit comments

Comments
 (0)