Skip to content

Commit

Permalink
#160 Fix Array solving
Browse files Browse the repository at this point in the history
  • Loading branch information
jemacineiras committed Jun 14, 2023
1 parent 0c50a86 commit a2932e9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ public class CodeGenerationException extends RuntimeException {
public CodeGenerationException(final String message, final Throwable cause) {
super(message, cause);
}

public CodeGenerationException(final String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Map;
import java.util.Objects;

import com.sngular.api.generator.plugin.openapi.exception.CodeGenerationException;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -102,7 +103,7 @@ private String mapIntoString(final Map<String, String> mappings) {
final boolean hasInner = baseString.contains("?");

if (hasInner && Objects.isNull(innerType)) {
throw new RuntimeException(String.format("Field object type '%s' missing an inner type", baseType));
throw new CodeGenerationException(String.format("Field object type '%s' missing an inner type", baseType));
}

return hasInner ? baseString.replace("?", innerType.mapIntoString(TYPE_MAPPINGS)) : baseString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

public final class TypeConstants {

private static final Set<String> BOOLEAN_VALUES = Set.of(Boolean.TRUE.toString(), Boolean.FALSE.toString());

public static final String NUMBER = "number";

public static final String BOOLEAN = "boolean";
Expand Down Expand Up @@ -77,17 +75,15 @@ public final class TypeConstants {
);

public static boolean isBoolean(final String isBoolean) {
return Boolean.parseBoolean(isBoolean);
return Boolean.parseBoolean(isBoolean.toLowerCase());
}

public enum TimeType {
LOCAL,
ZONED,
OFFSET
}

private TypeConstants() {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private static List<SchemaFieldObject> processFieldObjectList(
} else if (ApiTool.hasAdditionalProperties(schema)) {
fieldObjectArrayList.addAll(processMap(fieldName, schema, specFile, totalSchemas, compositedSchemas, antiLoopList));
} else if (ApiTool.hasRef(schema)) {
fieldObjectArrayList.add(processRef(fieldName, schema, specFile));
fieldObjectArrayList.add(processRef(fieldName, schema, specFile, new SchemaFieldObjectType(MapperUtil.getSimpleType(schema, specFile))));
} else if (ApiTool.isObject(schema) && !ApiTool.hasProperties(schema)) {
fieldObjectArrayList.add(SchemaFieldObject
.builder()
Expand Down Expand Up @@ -278,11 +278,12 @@ private static List<SchemaFieldObject> processFieldObjectList(
return fieldObjectArrayList;
}

private static SchemaFieldObject processRef(final String fieldName, final JsonNode schema, final SpecFile specFile) {
private static SchemaFieldObject processRef(final String fieldName, final JsonNode schema, final SpecFile specFile,
final SchemaFieldObjectType dataType) {
final String refSchemaName = getRef(schema, specFile);
final var field = SchemaFieldObject.builder()
.baseName(fieldName)
.dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(schema, specFile)))
.dataType(dataType)
.build();
setFieldType(field, schema, schema, specFile, refSchemaName);
return field;
Expand Down Expand Up @@ -415,17 +416,14 @@ private static List<SchemaFieldObject> processArray(
} else {
final var items = ApiTool.getItems(schema);
if (ApiTool.hasRef(items)) {
final String refSchemaName = getRef(items, specFile);
final var field = SchemaFieldObject
.builder()
.baseName(fieldName)
.dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile)))
.build();
setFieldType(field, items, items, specFile, refSchemaName);
fieldObjectArrayList.add(field);
final var refSchema = totalSchemas.get(cleanRefName(items));
if (ApiTool.isEnum(refSchema)) {
fieldObjectArrayList.add(processEnumField(refSchemaName, refSchema, specFile, ApiTool.getEnumValues(refSchema), schema));
fieldObjectArrayList.add(processRef(fieldName, items, specFile,
SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile))));
if (totalSchemas.containsKey(cleanRefName(items))) {
final var refSchema = totalSchemas.get(cleanRefName(items));
if (ApiTool.isEnum(refSchema)) {
final String refSchemaName = getRef(schema, specFile);
fieldObjectArrayList.add(processEnumField(refSchemaName, refSchema, specFile, ApiTool.getEnumValues(refSchema), schema));
}
}
} else if (ApiTool.isComposed(items)) {
final String composedSchemaName = StringUtils.defaultIfBlank(className, fieldName);
Expand Down

0 comments on commit a2932e9

Please sign in to comment.