@@ -249,8 +249,11 @@ public String toOperationId(String operationId) {
249249
250250 /**
251251 * Creates an array schema from the provided object schema.
252+ *
253+ * @param objectSchema the schema of the object to be wrapped in an array schema
254+ * @return the created array schema
252255 */
253- public Schema createArraySchema (Schema objectSchema ) {
256+ private Schema createArraySchema (Schema objectSchema ) {
254257 ArraySchema arraySchema = new ArraySchema ();
255258 arraySchema .items (objectSchema );
256259 return arraySchema ;
@@ -259,17 +262,25 @@ public Schema createArraySchema(Schema objectSchema) {
259262
260263 /**
261264 * Creates a map schema from the provided object schema.
265+ *
266+ * @param objectSchema the schema of the object to be wrapped in a map schema
267+ * @return the created map schema
262268 */
263- public Schema createMapSchema (Schema objectSchema ) {
269+ private Schema createMapSchema (Schema objectSchema ) {
264270 MapSchema mapSchema = new MapSchema ();
265271 mapSchema .additionalProperties (objectSchema );
266272 return mapSchema ;
267273 }
268274
269275 /**
270- * Creates a new model schema for a property.
276+ * Adds a new schema to the OpenAPI components.
277+ *
278+ * @param schema the schema to be added
279+ * @param schemaName the name of the schema
280+ * @param visitedSchema a set of schemas that have already been visited
281+ * @return the reference schema
271282 */
272- public Schema addSchemas (Schema schema , String schemaName , Set <Schema > visitedSchema ) {
283+ private Schema addSchemas (Schema schema , String schemaName , Set <Schema > visitedSchema ) {
273284 LOGGER .info ("Generating new model: {}" , schemaName );
274285
275286 ObjectSchema model = new ObjectSchema ();
@@ -290,7 +301,13 @@ public Schema addSchemas(Schema schema, String schemaName, Set<Schema> visitedSc
290301 return refSchema ;
291302 }
292303
293- public String getType (Schema schema ) {
304+ /**
305+ * Derive name from schema primitive type
306+ *
307+ * @param schema the schema to derive the name from
308+ * @return the derived name
309+ */
310+ private String getNameFromSchemaPrimitiveType (Schema schema ) {
294311 if (!ModelUtils .isPrimitiveType (schema )) return "" ;
295312 if (ModelUtils .isNumberSchema (schema )) {
296313 if (schema .getFormat () != null ) {
@@ -303,9 +320,12 @@ public String getType(Schema schema) {
303320 }
304321
305322 /**
306- * Recursively generates schemas for nested maps and arrays
323+ * Recursively generates schemas for nested maps and arrays.
324+ * @param schema the schema to be processed
325+ * @param visitedSchemas a set of schemas that have already been visited
326+ * @return the processed schema
307327 */
308- public Schema generateNestedSchema (Schema schema , Set <Schema > visitedSchemas ) {
328+ private Schema generateNestedSchema (Schema schema , Set <Schema > visitedSchemas ) {
309329 if (visitedSchemas .contains (schema )) {
310330 LOGGER .warn ("Skipping recursive schema" );
311331 return schema ;
@@ -318,7 +338,7 @@ public Schema generateNestedSchema(Schema schema, Set<Schema> visitedSchemas) {
318338 String newSchemaName = ModelUtils .getSimpleRef (ModelUtils .getSchemaItems (schema ).get$ref ()) + ARRAY_SUFFIX ;
319339 return addSchemas (schema , newSchemaName , visitedSchemas );
320340 }else if (ModelUtils .isPrimitiveType (itemsSchema )){
321- String newSchemaName = getType (itemsSchema ) + ARRAY_SUFFIX ;
341+ String newSchemaName = getNameFromSchemaPrimitiveType (itemsSchema ) + ARRAY_SUFFIX ;
322342 return addSchemas (schema , newSchemaName , visitedSchemas );
323343 } else {
324344 Schema childSchema = generateNestedSchema (itemsSchema , visitedSchemas );
@@ -333,7 +353,7 @@ public Schema generateNestedSchema(Schema schema, Set<Schema> visitedSchemas) {
333353 String newSchemaName = ModelUtils .getSimpleRef (ModelUtils .getAdditionalProperties (schema ).get$ref ()) + MAP_SUFFIX ;
334354 return addSchemas (schema , newSchemaName , visitedSchemas );
335355 }else if (ModelUtils .isPrimitiveType (mapValueSchema )){
336- String newSchemaName = getType (mapValueSchema ) + MAP_SUFFIX ;
356+ String newSchemaName = getNameFromSchemaPrimitiveType (mapValueSchema ) + MAP_SUFFIX ;
337357 return addSchemas (schema , newSchemaName , visitedSchemas );
338358 } else {
339359 Schema innerSchema = generateNestedSchema (mapValueSchema , visitedSchemas );
@@ -346,9 +366,12 @@ public Schema generateNestedSchema(Schema schema, Set<Schema> visitedSchemas) {
346366 }
347367
348368 /**
349- * Processes nested schemas for maps and arrays.
369+ * Processes nested schemas for complex type(map, array, oneOf)
370+ *
371+ * @param schema the schema to be processed
372+ * @param visitedSchemas a set of schemas that have already been visited
350373 */
351- public void processNestedSchemas (Schema schema , Set <Schema > visitedSchemas ) {
374+ private void processNestedSchemas (Schema schema , Set <Schema > visitedSchemas ) {
352375 if (ModelUtils .isMapSchema (schema ) && ModelUtils .getAdditionalProperties (schema ) != null ) {
353376 Schema mapValueSchema = ModelUtils .getAdditionalProperties (schema );
354377 mapValueSchema = ModelUtils .getReferencedSchema (openAPI , mapValueSchema );
@@ -386,7 +409,7 @@ public void processNestedSchemas(Schema schema, Set<Schema> visitedSchemas) {
386409 }
387410
388411 /**
389- * Wraps models to handle nested schemas for maps and arrays .
412+ * Traverses models and properties to wrap nested schemas.
390413 */
391414 private void wrapModels () {
392415 Map <String , Schema > models = openAPI .getComponents ().getSchemas ();
@@ -412,6 +435,12 @@ private void wrapModels() {
412435 }
413436 }
414437
438+ /**
439+ * Traverses a composed schema and its properties to wrap nested schemas.
440+ *
441+ * @param children the list of child schemas to be processed
442+ * @param visitedSchema a set of schemas that have already been visited
443+ */
415444 private void wrapComposedChildren (List <Schema > children , Set <Schema > visitedSchema ) {
416445 if (children == null || children .isEmpty ()) {
417446 return ;
0 commit comments