Skip to content

Commit e5d7abf

Browse files
committed
refactored isMetadataOnlySchema to ModelUtils.java
1 parent 9244d67 commit e5d7abf

2 files changed

Lines changed: 27 additions & 26 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ private void gatherInlineModels(Schema schema, String modelPrefix) {
422422
// For example, there may be an `description` only schema that is used to override the descrption.
423423
// In these cases, we can simply discard those schemas.
424424
List<Schema> nonMetadataOnlySchemas = (List<Schema>) schema.getAllOf().stream()
425-
.filter(v -> isMetadataOnlySchema((Schema) v))
425+
.filter(v -> ModelUtils.isMetadataOnlySchema((Schema) v))
426426
.collect(Collectors.toList());
427427

428428
if (nonMetadataOnlySchemas.size() == 1) {
@@ -485,31 +485,6 @@ private void gatherInlineModels(Schema schema, String modelPrefix) {
485485
}
486486
}
487487

488-
/**
489-
* Returns true if a schema is only metadata and not an actual type.
490-
* For example, a schema that only has a `description` without any `properties` or `$ref` defined.
491-
*
492-
* @param schema the schema
493-
* @return if the schema is only metadata and not an actual type
494-
*/
495-
boolean isMetadataOnlySchema(Schema schema) {
496-
return schema.get$ref() != null ||
497-
schema.getProperties() != null ||
498-
schema.getType() != null ||
499-
schema.getAdditionalProperties() != null ||
500-
schema.getAllOf() != null ||
501-
schema.getAnyOf() != null ||
502-
schema.getOneOf() != null ||
503-
schema.getPrefixItems() != null ||
504-
schema.getItems() != null ||
505-
schema.getTypes() != null ||
506-
schema.getPatternProperties() != null ||
507-
schema.getContains() != null ||
508-
schema.get$dynamicAnchor() != null ||
509-
schema.get$anchor() != null ||
510-
schema.getContentSchema() != null;
511-
}
512-
513488
/**
514489
* Flatten inline models in content
515490
*

modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,6 +2312,32 @@ public static boolean isUnsupportedSchema(OpenAPI openAPI, Schema schema) {
23122312
return false;
23132313
}
23142314

2315+
/**
2316+
* Returns true if a schema is only metadata and not an actual type.
2317+
* For example, a schema that only has a `description` without any `properties` or `$ref` defined.
2318+
*
2319+
* @param schema the schema
2320+
* @return if the schema is only metadata and not an actual type
2321+
*/
2322+
public static boolean isMetadataOnlySchema(Schema schema) {
2323+
return schema.get$ref() != null ||
2324+
schema.getProperties() != null ||
2325+
schema.getType() != null ||
2326+
schema.getAdditionalProperties() != null ||
2327+
schema.getAllOf() != null ||
2328+
schema.getAnyOf() != null ||
2329+
schema.getOneOf() != null ||
2330+
schema.getPrefixItems() != null ||
2331+
schema.getItems() != null ||
2332+
schema.getTypes() != null ||
2333+
schema.getPatternProperties() != null ||
2334+
schema.getContains() != null ||
2335+
schema.get$dynamicAnchor() != null ||
2336+
schema.get$anchor() != null ||
2337+
schema.getContentSchema() != null;
2338+
}
2339+
2340+
23152341
@FunctionalInterface
23162342
private interface OpenAPISchemaVisitor {
23172343

0 commit comments

Comments
 (0)