use model utils check instead of instanceof

This commit is contained in:
William Cheng 2024-04-11 21:23:04 +08:00
parent 03af25ce34
commit b4c315ebce
2 changed files with 7 additions and 8 deletions

View File

@ -770,9 +770,8 @@ public class InlineModelResolver {
for (Map.Entry<String, Schema> propertiesEntry : properties.entrySet()) { for (Map.Entry<String, Schema> propertiesEntry : properties.entrySet()) {
String key = propertiesEntry.getKey(); String key = propertiesEntry.getKey();
Schema property = propertiesEntry.getValue(); Schema property = propertiesEntry.getValue();
if (property instanceof ObjectSchema && ((ObjectSchema) property).getProperties() != null if (ModelUtils.isObjectSchema(property)) {
&& ((ObjectSchema) property).getProperties().size() > 0) { Schema op = property;
ObjectSchema op = (ObjectSchema) property;
String modelName = resolveModelName(op.getTitle(), path + "_" + key); String modelName = resolveModelName(op.getTitle(), path + "_" + key);
Schema model = modelFromProperty(openAPI, op, modelName); Schema model = modelFromProperty(openAPI, op, modelName);
String existing = matchGenerated(model); String existing = matchGenerated(model);
@ -789,8 +788,8 @@ public class InlineModelResolver {
} }
} else if (ModelUtils.isArraySchema(property)) { } else if (ModelUtils.isArraySchema(property)) {
Schema inner = ModelUtils.getSchemaItems(property); Schema inner = ModelUtils.getSchemaItems(property);
if (inner instanceof ObjectSchema) { if (ModelUtils.isObjectSchema(inner)) {
ObjectSchema op = (ObjectSchema) inner; Schema op = inner;
if (op.getProperties() != null && op.getProperties().size() > 0) { if (op.getProperties() != null && op.getProperties().size() > 0) {
flattenProperties(openAPI, op.getProperties(), path); flattenProperties(openAPI, op.getProperties(), path);
String modelName = resolveModelName(op.getTitle(), path + "_" + key); String modelName = resolveModelName(op.getTitle(), path + "_" + key);
@ -819,8 +818,8 @@ public class InlineModelResolver {
} }
} else if (ModelUtils.isMapSchema(property)) { } else if (ModelUtils.isMapSchema(property)) {
Schema inner = ModelUtils.getAdditionalProperties(property); Schema inner = ModelUtils.getAdditionalProperties(property);
if (inner instanceof ObjectSchema) { if (ModelUtils.isObjectSchema(inner)) {
ObjectSchema op = (ObjectSchema) inner; Schema op = inner;
if (op.getProperties() != null && op.getProperties().size() > 0) { if (op.getProperties() != null && op.getProperties().size() > 0) {
flattenProperties(openAPI, op.getProperties(), path); flattenProperties(openAPI, op.getProperties(), path);
String modelName = resolveModelName(op.getTitle(), path + "_" + key); String modelName = resolveModelName(op.getTitle(), path + "_" + key);

View File

@ -281,7 +281,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
private void collectEnumSchemas(String parentName, String sName, Schema schema) { private void collectEnumSchemas(String parentName, String sName, Schema schema) {
if (ModelUtils.isArraySchema(schema)) { if (ModelUtils.isArraySchema(schema)) {
collectEnumSchemas(parentName, sName, ModelUtils.getSchemaItems(schema)); collectEnumSchemas(parentName, sName, ModelUtils.getSchemaItems(schema));
} else if (schema instanceof MapSchema && schema.getAdditionalProperties() instanceof Schema) { } else if (ModelUtils.isMapSchema(schema) && schema.getAdditionalProperties() instanceof Schema) {
collectEnumSchemas(parentName, sName, (Schema) schema.getAdditionalProperties()); collectEnumSchemas(parentName, sName, (Schema) schema.getAdditionalProperties());
} else if (isEnumSchema(schema)) { } else if (isEnumSchema(schema)) {
String h = hashEnum(schema); String h = hashEnum(schema);