@@ -72,11 +72,11 @@ public void testJsonTypeInference() {
7272 public void testFormatInferrers () {
7373 // Fake format inferrer that always uses the string length as the format
7474 final FormatInferrer testStrLenFormatInferrer = input -> {
75- final String textValue = input .getSample ().textValue ();
7675 assertNotNull (input .getSpecVersion ());
77- if (textValue == null ) {
76+ if (! input . getSample (). isString () ) {
7877 return null ;
7978 }
79+ final String textValue = input .getSample ().stringValue ();
8080 return String .valueOf (textValue .length ());
8181 };
8282 assertSame (FormatInferrers .noOp (), FormatInferrers .chained ());
@@ -89,70 +89,72 @@ public void testFormatInferrers() {
8989 .addFormatInferrers (FormatInferrers .dateTime ())
9090 .setSpecVersion (SpecVersion .DRAFT_07 )
9191 .build ()
92- .inferForSample (jnf .textNode ("aaaaaaaaa" ))
92+ .inferForSample (jnf .stringNode ("aaaaaaaaa" ))
9393 .path ("format" ).textValue ());
9494 assertEquals ("date-time" , JsonSchemaInferrer .newBuilder ()
9595 .addFormatInferrers (FormatInferrers .dateTime ())
9696 .build ()
97- .inferForSample (jnf .textNode (Instant .now ().toString ()))
97+ .inferForSample (jnf .stringNode (Instant .now ().toString ()))
9898 .path ("format" ).textValue ());
9999 assertNull (JsonSchemaInferrer .newBuilder ()
100100 .addFormatInferrers (FormatInferrers .dateTime ())
101101 .setSpecVersion (SpecVersion .DRAFT_06 )
102102 .build ()
103- .inferForSample (jnf .textNode ("1900-01-01" ))
103+ .inferForSample (jnf .stringNode ("1900-01-01" ))
104104 .path ("format" ).textValue ());
105105 assertEquals ("date" , JsonSchemaInferrer .newBuilder ()
106106 .addFormatInferrers (FormatInferrers .dateTime ())
107107 .setSpecVersion (SpecVersion .DRAFT_07 )
108108 .build ()
109- .inferForSample (jnf .textNode ("1900-01-01" ))
109+ .inferForSample (jnf .stringNode ("1900-01-01" ))
110110 .path ("format" ).textValue ());
111111 assertNull (JsonSchemaInferrer .newBuilder ()
112112 .addFormatInferrers (FormatInferrers .dateTime ())
113113 .setSpecVersion (SpecVersion .DRAFT_06 )
114114 .build ()
115- .inferForSample (jnf .textNode ("20:20:39" ))
115+ .inferForSample (jnf .stringNode ("20:20:39" ))
116116 .path ("format" ).textValue ());
117117 assertEquals ("time" , JsonSchemaInferrer .newBuilder ()
118118 .addFormatInferrers (FormatInferrers .dateTime ())
119119 .setSpecVersion (SpecVersion .DRAFT_07 ).build ()
120- .inferForSample (jnf .textNode ("20:20:39+01:23" ))
120+ .inferForSample (jnf .stringNode ("20:20:39+01:23" ))
121121 .path ("format" ).textValue ());
122122 assertEquals ("time" , JsonSchemaInferrer .newBuilder ()
123123 .addFormatInferrers (FormatInferrers .dateTime ())
124124 .setSpecVersion (SpecVersion .DRAFT_07 ).build ()
125- .inferForSample (jnf .textNode ("20:20:39+00:00" ))
125+ .inferForSample (jnf .stringNode ("20:20:39+00:00" ))
126126 .path ("format" ).textValue ());
127127 {
128128 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
129129 .addFormatInferrers (FormatInferrers .chained (
130130 FormatInferrers .dateTime (), testStrLenFormatInferrer ))
131131 .build ();
132- assertEquals ("date-time" , inferrer .inferForSample (jnf .textNode (Instant .now ().toString ()))
132+ assertEquals ("date-time" , inferrer .inferForSample (jnf .stringNode (Instant .now ().toString ()))
133133 .path ("format" ).textValue ());
134- assertEquals ("0" , inferrer .inferForSample (jnf .textNode ("" )).path ("format" ).textValue ());
134+ assertEquals ("0" , inferrer .inferForSample (jnf .stringNode ("" )).path ("format" ).textValue ());
135135 }
136136 {
137137 final JsonSchemaInferrer inferrer =
138138 JsonSchemaInferrer .newBuilder ().addFormatInferrers (FormatInferrers .ip ()).build ();
139139 assertEquals ("ipv4" ,
140- inferrer .inferForSample (jnf .textNode ("12.34.56.78" )).path ("format" ).textValue ());
140+ inferrer .inferForSample (jnf .stringNode ("12.34.56.78" )).path ("format" ).textValue ());
141141 assertEquals ("ipv6" ,
142- inferrer .inferForSample (jnf .textNode ("2001:0db8:85a3:0000:0000:8a2e:0370:7334" ))
142+ inferrer .inferForSample (jnf .stringNode ("2001:0db8:85a3:0000:0000:8a2e:0370:7334" ))
143143 .path ("format" ).textValue ());
144144 assertEquals ("ipv6" ,
145- inferrer .inferForSample (jnf .textNode ("a::F" )).path ("format" ).textValue ());
146- assertEquals ("ipv6" , inferrer .inferForSample (jnf .textNode ("5::" )).path ("format" ).textValue ());
147- assertEquals ("ipv6" , inferrer .inferForSample (jnf .textNode ("::" )).path ("format" ).textValue ());
145+ inferrer .inferForSample (jnf .stringNode ("a::F" )).path ("format" ).textValue ());
146+ assertEquals ("ipv6" ,
147+ inferrer .inferForSample (jnf .stringNode ("5::" )).path ("format" ).textValue ());
148+ assertEquals ("ipv6" ,
149+ inferrer .inferForSample (jnf .stringNode ("::" )).path ("format" ).textValue ());
148150 }
149151 {
150152 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
151153 .addFormatInferrers (FormatInferrers .chained (
152154 FormatInferrers .noOp (), FormatInferrers .noOp (), FormatInferrers .noOp (),
153155 FormatInferrers .ip (), FormatInferrers .email ()))
154156 .build ();
155- assertNull (inferrer .inferForSample (jnf .textNode (Instant .now ().toString ())).get ("format" ));
157+ assertNull (inferrer .inferForSample (jnf .stringNode (Instant .now ().toString ())).get ("format" ));
156158 }
157159 {
158160 final String dateTimeString = Instant .now ().toString ();
@@ -161,8 +163,8 @@ public void testFormatInferrers() {
161163 testStrLenFormatInferrer , FormatInferrers .dateTime ()))
162164 .build ();
163165 assertEquals (String .valueOf (dateTimeString .length ()),
164- inferrer .inferForSample (jnf .textNode (dateTimeString )).path ("format" ).textValue ());
165- assertEquals ("0" , inferrer .inferForSample (jnf .textNode ("" )).path ("format" ).textValue ());
166+ inferrer .inferForSample (jnf .stringNode (dateTimeString )).path ("format" ).textValue ());
167+ assertEquals ("0" , inferrer .inferForSample (jnf .stringNode ("" )).path ("format" ).textValue ());
166168 }
167169 }
168170
@@ -368,7 +370,7 @@ public String generateDescription(@Nonnull TitleDescriptionGeneratorInput input)
368370 @ Test
369371 public void testDefault () {
370372 final List <JsonNode > samples =
371- ImmutableList .of (jnf .textNode ("a" ), jnf .textNode ("b" ), jnf .textNode ("c" ));
373+ ImmutableList .of (jnf .stringNode ("a" ), jnf .stringNode ("b" ), jnf .stringNode ("c" ));
372374 {
373375 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
374376 .setDefaultPolicy (DefaultPolicies .noOp ())
@@ -408,7 +410,7 @@ public void testExamples() {
408410 .setExamplesPolicy (ExamplesPolicies .useFirstSamples (3 ))
409411 .build ();
410412 final ObjectNode schema = inferrer .inferForSamples (IntStream .range (0 , 5 )
411- .mapToObj (Integer ::toString ).map (jnf ::textNode ).collect (Collectors .toList ()));
413+ .mapToObj (Integer ::toString ).map (jnf ::stringNode ).collect (Collectors .toList ()));
412414 assertNull (schema .get ("examples" ));
413415 }
414416 {
@@ -417,7 +419,7 @@ public void testExamples() {
417419 .setExamplesPolicy (ExamplesPolicies .useFirstSamples (3 ))
418420 .build ();
419421 final ObjectNode schema = inferrer .inferForSamples (IntStream .range (0 , 5 )
420- .mapToObj (Integer ::toString ).map (jnf ::textNode ).collect (Collectors .toList ()));
422+ .mapToObj (Integer ::toString ).map (jnf ::stringNode ).collect (Collectors .toList ()));
421423 assertEquals (ImmutableSet .of ("0" , "1" , "2" ), toStringSet (schema .path ("examples" )));
422424 }
423425 {
@@ -426,7 +428,7 @@ public void testExamples() {
426428 .setExamplesPolicy (ExamplesPolicies .useFirstSamples (3 , "boolean" ::equals ))
427429 .build ();
428430 final ObjectNode schema = inferrer .inferForSamples (IntStream .range (0 , 5 )
429- .mapToObj (Integer ::toString ).map (jnf ::textNode ).collect (Collectors .toList ()));
431+ .mapToObj (Integer ::toString ).map (jnf ::stringNode ).collect (Collectors .toList ()));
430432 assertNull (schema .get ("examples" ));
431433 }
432434 {
@@ -441,7 +443,7 @@ public void testExamples() {
441443 .setExamplesPolicy (ExamplesPolicies .useFirstSamples (3 , "string" ::equals ))
442444 .build ();
443445 final ObjectNode schema = inferrer .inferForSamples (IntStream .range (0 , 5 )
444- .mapToObj (Integer ::toString ).map (jnf ::textNode ).collect (Collectors .toList ()));
446+ .mapToObj (Integer ::toString ).map (jnf ::stringNode ).collect (Collectors .toList ()));
445447 assertEquals (ImmutableSet .of ("0" , "1" , "2" ), toStringSet (schema .path ("examples" )));
446448 }
447449 {
@@ -452,8 +454,9 @@ public void testExamples() {
452454 return null ;
453455 })
454456 .build ();
455- inferrer .inferForSamples (IntStream .range (0 , 5 ).mapToObj (Integer ::toString ).map (jnf ::textNode )
456- .collect (Collectors .toList ()));
457+ inferrer .inferForSamples (
458+ IntStream .range (0 , 5 ).mapToObj (Integer ::toString ).map (jnf ::stringNode )
459+ .collect (Collectors .toList ()));
457460 }
458461 {
459462 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
@@ -477,7 +480,7 @@ public void testMultipleOf() {
477480 ImmutableList .of (jnf .numberNode (0 ), jnf .numberNode (0 ), jnf .numberNode (0 ));
478481 final List <JsonNode > samples4 =
479482 ImmutableList .of (jnf .numberNode (2 ), jnf .numberNode (4 ), jnf .numberNode (6.5 ));
480- final List <JsonNode > samples5 = ImmutableList .of (jnf .textNode ("foo" ), jnf .textNode ("bar" ));
483+ final List <JsonNode > samples5 = ImmutableList .of (jnf .stringNode ("foo" ), jnf .stringNode ("bar" ));
481484 {
482485 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
483486 .setMultipleOfPolicy (input -> {
@@ -547,7 +550,7 @@ public void testEnum() {
547550 assertSame (EnumExtractors .noOp (), EnumExtractors .chained ());
548551 assertSame (EnumExtractors .noOp (), EnumExtractors .chained (EnumExtractors .noOp ()));
549552 final List <JsonNode > timeUnitSamples = Stream .of (TimeUnit .DAYS , TimeUnit .HOURS )
550- .map (tu -> jnf .textNode (tu .name ())).collect (ImmutableList .toImmutableList ());
553+ .map (tu -> jnf .stringNode (tu .name ())).collect (ImmutableList .toImmutableList ());
551554 {
552555 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ().build ();
553556 final ObjectNode schema = inferrer .inferForSamples (timeUnitSamples );
@@ -591,8 +594,8 @@ public void testEnum() {
591594 }))
592595 .build ();
593596 final ObjectNode schema =
594- inferrer .inferForSamples (Arrays .asList (jnf .textNode ("foo" ), jnf .numberNode (123 )));
595- assertEquals (ImmutableSet .of (jnf .textNode ("foo" ), jnf .numberNode (123 )),
597+ inferrer .inferForSamples (Arrays .asList (jnf .stringNode ("foo" ), jnf .numberNode (123 )));
598+ assertEquals (ImmutableSet .of (jnf .stringNode ("foo" ), jnf .numberNode (123 )),
596599 stream (schema .get ("enum" )).collect (Collectors .toSet ()));
597600 }
598601 {
@@ -601,7 +604,7 @@ public void testEnum() {
601604 EnumExtractors .validEnum (DayOfWeek .class )))
602605 .build ();
603606 final ObjectNode schema =
604- inferrer .inferForSamples (Arrays .asList (jnf .textNode ("TUESDAY" ), jnf .textNode ("MARCH" )));
607+ inferrer .inferForSamples (Arrays .asList (jnf .stringNode ("TUESDAY" ), jnf .stringNode ("MARCH" )));
605608 final JsonNode anyOf = schema .get ("anyOf" );
606609 assertTrue (anyOf .isArray ());
607610 assertTrue (
@@ -669,7 +672,7 @@ public void testArrayLengthFeatures() {
669672 @ Test
670673 public void testStringLengthFeatures () {
671674 final List <JsonNode > samples =
672- ImmutableList .of (jnf .textNode ("" ), jnf .textNode ("a" ), jnf .textNode ("foobar" ));
675+ ImmutableList .of (jnf .stringNode ("" ), jnf .stringNode ("a" ), jnf .stringNode ("foobar" ));
673676 {
674677 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
675678 .setStringLengthFeatures (EnumSet .of (StringLengthFeature .MIN_LENGTH ))
@@ -702,7 +705,7 @@ public void testStringLengthFeatures() {
702705 @ Test
703706 public void testStringLengthAndFormat () {
704707 final String dateTimeString = Instant .now ().toString ();
705- final List <JsonNode > samples = ImmutableList .of (jnf .textNode (dateTimeString ));
708+ final List <JsonNode > samples = ImmutableList .of (jnf .stringNode (dateTimeString ));
706709 final JsonSchemaInferrer inferrer = JsonSchemaInferrer .newBuilder ()
707710 .setStringLengthFeatures (EnumSet .allOf (StringLengthFeature .class ))
708711 .addFormatInferrers (FormatInferrers .dateTime ())
0 commit comments