Skip to content

Commit bd3f76a

Browse files
committed
Don't require hints when converting to schema
1 parent 247ce1f commit bd3f76a

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ See [examples] directory for runnable examples and how to infer JTD.
1717
```go
1818
schema := NewInferrer(WithoutHints()).
1919
Infer("my-string").
20-
IntoSchema(WithoutHints())
20+
IntoSchema()
2121
// {
2222
// "type": "string"
2323
// }
@@ -31,7 +31,7 @@ rows := []string{
3131
`{"name":"Joe", "age": 52, "something_optional": true, "something_nullable": 1.1}`,
3232
`{"name":"Jane", "age": 48, "something_nullable": null}`,
3333
}
34-
schema := InferStrings(rows, WithoutHints()).IntoSchema(WithoutHints())
34+
schema := InferStrings(rows, WithoutHints()).IntoSchema()
3535
// {
3636
// "properties": {
3737
// "age": {

examples/infer_multiple_string_rows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func main() {
1313
}
1414
schema := jtdinfer.
1515
InferStrings(rows, jtdinfer.WithoutHints()).
16-
IntoSchema(jtdinfer.WithoutHints())
16+
IntoSchema()
1717

1818
j, _ := json.MarshalIndent(schema, "", " ")
1919
print(string(j))

examples/infer_simple_value.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func main() {
1010
schema := jtdinfer.
1111
NewInferrer(jtdinfer.WithoutHints()).
1212
Infer("my-string").
13-
IntoSchema(jtdinfer.WithoutHints())
13+
IntoSchema()
1414

1515
j, _ := json.MarshalIndent(schema, "", " ")
1616
print(string(j))

examples/infer_with_hints.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func main() {
3030
Discriminator: jtdinfer.NewHintSet().Add([]string{"discriminator", "-", "type"}),
3131
}
3232

33-
schema := jtdinfer.InferStrings(rows, hints).IntoSchema(hints)
33+
schema := jtdinfer.InferStrings(rows, hints).IntoSchema()
3434
j, _ := json.MarshalIndent(schema, "", " ")
3535
print(string(j))
3636
}

inferrer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func (i *Inferrer) Infer(value any) *Inferrer {
2828
}
2929

3030
// IntoSchema will convert the `InferredSchema` into a final `Schema`.
31-
func (i *Inferrer) IntoSchema(hints Hints) Schema {
32-
return i.Inference.IntoSchema(hints)
31+
func (i *Inferrer) IntoSchema() Schema {
32+
return i.Inference.IntoSchema(i.Hints)
3333
}
3434

3535
// InferStrings accepts a slice of strings and will convert them to either a

inferrer_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestJTDInfer(t *testing.T) {
2020
"hobbies": {Elements: &Schema{Type: jtd.TypeString}},
2121
},
2222
}
23-
gotSchema := InferStrings(rows, Hints{}).IntoSchema(Hints{})
23+
gotSchema := InferStrings(rows, WithoutHints()).IntoSchema()
2424

2525
assert.EqualValues(t, expectedSchema, gotSchema)
2626
}
@@ -48,10 +48,19 @@ func TestJTDInferrerWithEnumHints(t *testing.T) {
4848
},
4949
},
5050
}
51-
gotSchema := InferStrings(rows, hints).IntoSchema(hints)
51+
gotSchema := InferStrings(rows, hints).IntoSchema()
5252

5353
// We check that we got the same elements in our enum first and then we
5454
// delete it since the order is unreliable due to being a map.
55+
require.ElementsMatch(
56+
t,
57+
expectedSchema.Properties["name"].Enum,
58+
gotSchema.Properties["name"].Enum,
59+
)
60+
61+
delete(expectedSchema.Properties, "name")
62+
delete(gotSchema.Properties, "name")
63+
5564
require.ElementsMatch(
5665
t,
5766
expectedSchema.Properties["address"].Properties["city"].Enum,
@@ -81,7 +90,7 @@ func TestJTDInferWithValuesHints(t *testing.T) {
8190
},
8291
},
8392
}
84-
gotSchema := InferStrings(rows, hints).IntoSchema(hints)
93+
gotSchema := InferStrings(rows, hints).IntoSchema()
8594

8695
assert.EqualValues(t, expectedSchema, gotSchema)
8796
}
@@ -112,7 +121,7 @@ func TestJTDInferWithDiscriminatorHints(t *testing.T) {
112121
},
113122
},
114123
}
115-
gotSchema := InferStrings(rows, hints).IntoSchema(hints)
124+
gotSchema := InferStrings(rows, hints).IntoSchema()
116125

117126
assert.EqualValues(t, expectedSchema, gotSchema)
118127
}

0 commit comments

Comments
 (0)