44import java .nio .file .Files ;
55import java .nio .file .Path ;
66import java .util .ArrayList ;
7- import java .util .Iterator ;
87import java .util .LinkedHashMap ;
98import java .util .List ;
109import java .util .Map ;
1312import org .slf4j .Logger ;
1413import org .slf4j .LoggerFactory ;
1514
16- import com .fasterxml .jackson .databind .JsonNode ;
17- import com .fasterxml .jackson .databind .ObjectMapper ;
15+ import tools .jackson .databind .JsonNode ;
16+ import tools .jackson .databind .ObjectMapper ;
17+ import tools .jackson .databind .json .JsonMapper ;
1818
1919import io .swagger .v3 .oas .models .media .Schema ;
2020import io .swagger .v3 .oas .models .media .StringSchema ;
5151public class JsonSchemaUtil {
5252
5353 private static final Logger LOG = LoggerFactory .getLogger (JsonSchemaUtil .class );
54- private static final ObjectMapper MAPPER = new ObjectMapper ();
54+ private static final ObjectMapper MAPPER = new JsonMapper ();
5555
5656 private JsonSchemaUtil () {
5757 }
@@ -105,7 +105,7 @@ static Schema nodeToSchema(JsonNode node) {
105105 return null ;
106106 }
107107
108- String type = node .has ("type" ) ? node .get ("type" ).asText () : "object" ;
108+ String type = node .has ("type" ) ? node .get ("type" ).asString () : "object" ;
109109 Schema schema ;
110110 switch (type ) {
111111 case "string" :
@@ -126,13 +126,13 @@ static Schema nodeToSchema(JsonNode node) {
126126 }
127127
128128 if (node .has ("title" )) {
129- schema .setTitle (node .get ("title" ).asText ());
129+ schema .setTitle (node .get ("title" ).asString ());
130130 }
131131 if (node .has ("description" )) {
132- schema .setDescription (node .get ("description" ).asText ());
132+ schema .setDescription (node .get ("description" ).asString ());
133133 }
134134 if (node .has ("format" )) {
135- schema .setFormat (node .get ("format" ).asText ());
135+ schema .setFormat (node .get ("format" ).asString ());
136136 }
137137 if (node .has ("enum" )) {
138138 List <Object > enumValues = new ArrayList <>();
@@ -144,17 +144,15 @@ static Schema nodeToSchema(JsonNode node) {
144144 } else if (val .isDouble ()) {
145145 enumValues .add (val .doubleValue ());
146146 } else {
147- enumValues .add (val .asText ());
147+ enumValues .add (val .asString ());
148148 }
149149 }
150150 schema .setEnum (enumValues );
151151 }
152152
153153 if (node .has ("properties" )) {
154154 Map <String , Schema > props = new LinkedHashMap <>();
155- Iterator <Map .Entry <String , JsonNode >> fields = node .get ("properties" ).fields ();
156- while (fields .hasNext ()) {
157- Map .Entry <String , JsonNode > field = fields .next ();
155+ for (Map .Entry <String , JsonNode > field : node .get ("properties" ).properties ()) {
158156 Schema propSchema = nodeToSchema (field .getValue ());
159157 if (propSchema != null ) {
160158 props .put (field .getKey (), propSchema );
@@ -164,12 +162,10 @@ static Schema nodeToSchema(JsonNode node) {
164162 }
165163
166164 // Collect x- extension fields
167- Iterator <Map .Entry <String , JsonNode >> allFields = node .fields ();
168- while (allFields .hasNext ()) {
169- Map .Entry <String , JsonNode > field = allFields .next ();
165+ for (Map .Entry <String , JsonNode > field : node .properties ()) {
170166 if (field .getKey ().startsWith ("x-" )) {
171- schema .addExtension (field .getKey (), field .getValue ().isTextual ()
172- ? field .getValue ().asText ()
167+ schema .addExtension (field .getKey (), field .getValue ().isString ()
168+ ? field .getValue ().asString ()
173169 : field .getValue ());
174170 }
175171 }
0 commit comments