Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

328 support for multipart #351

Merged
merged 39 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4eae2e0
Updated lombok version
oscar-ares Mar 1, 2024
b3dfaf7
328 added removal of @RequestBody anotation when requestBody is multi…
oscar-ares Mar 5, 2024
e51827e
Fix test
jemacineiras Aug 6, 2024
9fd58de
Refactor
jemacineiras Aug 12, 2024
f300445
Refactor
jemacineiras Aug 16, 2024
f2da2de
Fix test
jemacineiras Aug 20, 2024
035893c
Fix AsyncApi Schema Generator
jemacineiras Aug 20, 2024
8bed01b
Fix OpenApi generator
jemacineiras Aug 23, 2024
582c4c3
Fix OpenApi generator
jemacineiras Aug 26, 2024
bef65c4
Fix OpenApi generator
jemacineiras Aug 28, 2024
2c7315f
Fix OpenApi generator
jemacineiras Sep 4, 2024
61f9325
Fix OpenApi generator
jemacineiras Sep 9, 2024
3c0eed9
Rework staff
jemacineiras Sep 9, 2024
61c7012
Rework things
jemacineiras Sep 21, 2024
11082b2
Fix OpenApi generator
jemacineiras Sep 21, 2024
e047fd2
Fix things
jemacineiras Sep 21, 2024
adbbcb6
Fix OpenApi generator
jemacineiras Sep 22, 2024
2baa29d
Fix Async Generator
jemacineiras Sep 23, 2024
ae5b07d
Fix Openapi Generator
jemacineiras Sep 23, 2024
6c35935
Fix Engine
jemacineiras Sep 23, 2024
fe66078
Fix Test
jemacineiras Sep 23, 2024
e44a9b5
Fix Test
jemacineiras Sep 25, 2024
6e3bc79
Improve test
jemacineiras Sep 26, 2024
37aeaf7
improve code style
jemacineiras Sep 30, 2024
05d0543
Fix github comments
jemacineiras Sep 30, 2024
ef22e5f
Fix Codacy comments
jemacineiras Oct 13, 2024
ce80741
Fix Codacy comments
jemacineiras Oct 13, 2024
341dd00
Codacy comments
jemacineiras Oct 16, 2024
1e5b130
Maven Publish
jemacineiras Oct 22, 2024
6bc3354
Merge branch 'main' into 255-openapiasyncapi-homogenize-mappercontent…
jemacineiras Oct 22, 2024
7c94bb8
Maven Publish
jemacineiras Oct 22, 2024
83cea15
328 added removal of @RequestBody anotation when requestBody is multi…
oscar-ares Mar 5, 2024
14af860
Maven Publish
jemacineiras Oct 22, 2024
c48a706
Merge branch '328-support-for-multipart' of sngular.github.com:sngula…
jemacineiras Oct 22, 2024
5bfba23
Maven Publish
jemacineiras Oct 22, 2024
893f66e
Fix Multipart
jemacineiras Oct 22, 2024
e2fa955
Fix test path problems
jemacineiras Nov 2, 2024
4c1e774
Fix test path problems
jemacineiras Nov 2, 2024
4a97f5c
Fix test path problems
jemacineiras Nov 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix Openapi Generator
  • Loading branch information
jemacineiras committed Sep 23, 2024
commit ae5b07df0bc48c6dec4aeffadfe2ee9b44111403
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ protected void cleanData() {
clearRoot();
addToRoot("checkBasicTypes", BASIC_DATA_TYPES);
classTemplateList.clear();
generateExceptionTemplate = false;
}

protected abstract void clearRoot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

public class MapperContentUtil {


private MapperContentUtil() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public static String getRefSchemaKey(final JsonNode parameter) {
return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + StringCaseUtils.titleToSnakeCase(pathObjectRef[pathObjectRef.length - 1]));
}

public static String getRefSchemaKey(final String parameter) {
final String[] pathObjectRef = parameter.split("/");
return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + getSchemaKey(pathObjectRef[pathObjectRef.length - 1]));
}

public static String getKeySchemaName(final String parameter) {
return StringCaseUtils.toCamelCase(getKey(parameter));
}
Expand All @@ -71,11 +76,6 @@ public static String getKey(final String keyString) {
return pathObjectRef[pathObjectRef.length - 1];
}

public static String getRefSchemaKey(final String parameter) {
final String[] pathObjectRef = parameter.split("/");
return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + getSchemaKey(pathObjectRef[pathObjectRef.length - 1]));
}

public static String getSchemaKey(final String schemaName) {
return StringCaseUtils.titleToSnakeCase(schemaName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,39 @@ public final class ModelBuilder {

private static final String ADDITIONAL_PROPERTIES = "additionalProperties";

private static final Map<String, SchemaObject> cachedSchemas = new HashMap<>();

public static SchemaObject buildSchemaObject(
final Map<String, JsonNode> totalSchemas, final String className, final JsonNode model,
final Set<String> antiLoopList, final Map<String, SchemaObject> compositedSchemas, final String parentPackage, final CommonSpecFile specFile,
final Path baseDir) {
final Set<String> antiLoopList, final Map<String, SchemaObject> compositedSchemas, final String parentPackage,
final CommonSpecFile specFile, final Path baseDir) {

antiLoopList.add(WordUtils.capitalizeFully(className));
final var schemaBuilder = SchemaObject.builder()
.schemaName(WordUtils.capitalizeFully(className))
.className(MapperUtil.getPojoName(className, specFile));

final var listSchema = getFields(null, totalSchemas, model, specFile, compositedSchemas, antiLoopList, WordUtils.capitalizeFully(className), baseDir);
if (!ApiTool.isEnum(model)) {
final var listSchema = getFields(null, totalSchemas, model, specFile, compositedSchemas, antiLoopList, WordUtils.capitalizeFully(className), baseDir);

final var schemaBuilder = SchemaObject.builder()
.schemaName(WordUtils.capitalizeFully(className))
.className(MapperUtil.getPojoName(className, specFile))
.importList(getImportList(listSchema, specFile.getModelPackage()));

if (ApiTool.isAllOf(model)) {
schemaBuilder.schemaCombinator(ALL_OF_COMBINATOR);
} else if (ApiTool.isAnyOf(model)) {
schemaBuilder.schemaCombinator(ANY_OF_COMBINATOR);
} else if (ApiTool.isOneOf(model)) {
schemaBuilder.schemaCombinator(ONE_OF_COMBINATOR);
} else {
schemaBuilder.schemaCombinator("");
}
schemaBuilder.importList(getImportList(listSchema, specFile.getModelPackage()));

return schemaBuilder
.fieldObjectList(listSchema)
.parentPackage(parentPackage.toLowerCase())
.build();
if (ApiTool.isAllOf(model)) {
schemaBuilder.schemaCombinator(ALL_OF_COMBINATOR);
} else if (ApiTool.isAnyOf(model)) {
schemaBuilder.schemaCombinator(ANY_OF_COMBINATOR);
} else if (ApiTool.isOneOf(model)) {
schemaBuilder.schemaCombinator(ONE_OF_COMBINATOR);
} else {
schemaBuilder.schemaCombinator("");
}

schemaBuilder
.fieldObjectList(listSchema)
.parentPackage(parentPackage.toLowerCase());
}
cachedSchemas.putAll(compositedSchemas);
return schemaBuilder.build();
}

private static List<String> getImportList(final Set<SchemaFieldObject> fieldObjectList, final String modelPackage) {
Expand Down Expand Up @@ -233,20 +237,48 @@ private static List<SchemaFieldObject> processObjectProperty(final String buildi
final var refSchema = totalSchemas.get(MapperUtil.getRefSchemaKey(fieldBody));
if (!antiLoopList.contains(typeName) && Objects.nonNull(refSchema) && ApiTool.hasType(refSchema)
&& ApiTool.hasItems(refSchema) || ApiTool.getRefValue(fieldBody).contains(fieldName)) {
if (antiLoopList.contains(typeName) && ApiTool.getRefValue(fieldBody).contains(fieldName)) {
fieldObjectArrayList.add(SchemaFieldObject
.builder()
.baseName(fieldName)
.required(ApiTool.checkIfRequired(schema, fieldName))
.dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile),
MapperUtil.getPojoName(typeName, specFile)))
.build());
} else {
antiLoopList.add(typeName);
fieldObjectArrayList.addAll(processFieldObjectList(buildingSchema, fieldName, typeName, refSchema, specFile, totalSchemas, compositedSchemas,
antiLoopList, baseDir));
}
} else if (ApiTool.isEnum(refSchema)) {
fieldObjectArrayList.add(processEnumField(fieldName, refSchema, specFile, ApiTool.getEnumValues(refSchema), schema));
} else {
compositedSchemas.put(typeName, buildSchemaObject(totalSchemas, typeName, refSchema, antiLoopList, compositedSchemas, "", specFile, baseDir ));
} else if (ApiTool.isObject(refSchema) || ApiTool.isComposed(refSchema)) {
compositedSchemas.put(typeName, buildSchemaObject(totalSchemas, typeName, refSchema, antiLoopList, compositedSchemas, "", specFile, baseDir ));
fieldObjectArrayList.add(SchemaFieldObject
.builder()
.baseName(fieldName)
.required(ApiTool.checkIfRequired(schema, fieldName))
.dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile),
MapperUtil.getPojoName(typeName, specFile)))
.build());
} else if (ApiTool.isBoolean(refSchema) || ApiTool.isString(refSchema) || ApiTool.isNumber(refSchema) || ApiTool.isDateTime(refSchema)) {
fieldObjectArrayList.add(SchemaFieldObject
.builder()
.baseName(fieldName)
.required(ApiTool.checkIfRequired(schema, fieldName))
.dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile),
MapperUtil.getPojoName(typeName, specFile)))
.build());
.builder()
.baseName(fieldName)
.required(ApiTool.checkIfRequired(schema, fieldName))
.dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(refSchema, specFile)))
.constValue(ApiTool.getConst(refSchema))
.build());
} else if (antiLoopList.contains(typeName)) {
if (cachedSchemas.containsKey(typeName)) {
fieldObjectArrayList.add(SchemaFieldObject
.builder()
.baseName(fieldName)
.required(ApiTool.checkIfRequired(schema, fieldName))
.dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile),
MapperUtil.getPojoName(typeName, specFile)))
.build());
}
}
} else if (ApiTool.isEnum(fieldBody)) {
fieldObjectArrayList.add(processEnumField(fieldName, fieldBody, specFile, ApiTool.getEnumValues(fieldBody), fieldBody));
Expand Down Expand Up @@ -611,7 +643,6 @@ private static Set<SchemaFieldObject> processAllOf(

for (JsonNode ref : schemaList) {
if (ApiTool.hasRef(ref)) {
final String schemaName = MapperUtil.getRefSchemaName(ref);
final var schemaToProcess = totalSchemas.get(MapperUtil.getRefSchemaKey(ref));
ApiTool.getProperties(schemaToProcess).forEachRemaining(processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, ref, antiLoopList, baseDir));
for (var fieldObject : fieldObjectArrayList) {
Expand All @@ -635,9 +666,8 @@ private static Set<SchemaFieldObject> processAnyOfOneOf(final String buildingSch
antiLoopList.add(schemaName);
fieldObjectArrayList.addAll(compositedSchemas.get(schemaName).getFieldObjectList());
} else {
final var schemaObject = solveRef(internalSchema, totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir);
compositedSchemas.put(schemaName, schemaObject);
antiLoopList.add(schemaName);
final var schemaObject = solveRef(internalSchema, totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir);
fieldObjectArrayList.addAll(schemaObject.getFieldObjectList());
}
} else if (compositedSchemas.containsKey(schemaName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ public static JsonNode solveRef(final String refValue, final Map<String, JsonNod
final var refValueArr = refValue.split("#");
final var filePath = refValueArr[0];
solvedRef = OpenApiUtil.getPojoFromRef(rootFilePath.toAbsolutePath(), filePath);
final var refName = MapperUtil.getRefSchemaKey(refValueArr[1]);
schemaMap.putAll(ApiTool.getComponentSchemas(solvedRef));
solvedRef = solvedRef.findValue(refName);
solvedRef = solvedRef.findValue(MapperUtil.getKey(refValueArr[1]));
}
} else {
solvedRef = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private static List<RequestObject> mapRequestObject(
"InlineObject" + operationIdWithCap, globalObject, baseDir))
.build());
} else {
final var requestBodyNode = globalObject.getRequestBodyNode(MapperUtil.getRefSchemaName(requestBody)).orElseThrow();
final var requestBodyNode = globalObject.getRequestBodyNode(MapperUtil.getRefSchemaKey(requestBody)).orElseThrow();
requestObjects.add(RequestObject.builder()
.required(ApiTool.hasNode(requestBody, REQUIRED))
.contentObjects(mapContentObject(specFile, ApiTool.getNode(requestBodyNode, CONTENT),
Expand All @@ -222,7 +222,7 @@ private static List<ParameterObject> mapParameterObjects(
if (Objects.nonNull(parameters) && !parameters.isEmpty()) {
for (final JsonNode parameter : parameters) {
if (ApiTool.hasRef(parameter)) {
final JsonNode refParameter = globalObject.getParameterNode(MapperUtil.getRefSchemaName(parameter)).orElseThrow();
final JsonNode refParameter = globalObject.getParameterNode(MapperUtil.getRefSchemaKey(parameter)).orElseThrow();
parameterObjects.add(buildParameterObject(specFile, globalObject, refParameter, baseDir));
} else if (ApiTool.hasNode(parameter, CONTENT)) {
parameterObjects.addAll(buildParameterContent(contentClassName, parameter, specFile, globalObject, baseDir));
Expand Down Expand Up @@ -384,8 +384,7 @@ private static SchemaFieldObjectType getSchemaType(

if (ApiTool.hasRef(schema)) {
final String refSchemaPojoName = MapperUtil.getRef(schema, specFile);
final JsonNode refSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), globalObject.getSchemaMap(),
baseDir.resolve(specFile.getFilePath()).getParent());
final JsonNode refSchema = getRefSchema(schema, specFile, globalObject, baseDir);
type = getSchemaType(refSchema, refSchemaPojoName, specFile, globalObject, baseDir);
} else if (ApiTool.hasAdditionalProperties(schema)) {
type = getMapSchemaType(schema, pojoName, specFile, globalObject, baseDir);
Expand All @@ -400,6 +399,25 @@ private static SchemaFieldObjectType getSchemaType(
return type;
}

private static JsonNode getRefSchema(JsonNode schema, SpecFile specFile, GlobalObject globalObject, Path baseDir) {
JsonNode refSchema = null;
final String refValue = ApiTool.getRefValue(schema);
if (refValue.contains("schemas")) {
refSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), globalObject.getSchemaMap(),
baseDir.resolve(specFile.getFilePath()).getParent());
} else if (refValue.contains("requestBodies")) {
refSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), globalObject.getRequestBodyMap(),
baseDir.resolve(specFile.getFilePath()).getParent());
} else if (refValue.contains("parameters")) {
refSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), globalObject.getParameterMap(),
baseDir.resolve(specFile.getFilePath()).getParent());
} else if (refValue.contains("responseBodies")) {
refSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), globalObject.getResponseMap(),
baseDir.resolve(specFile.getFilePath()).getParent());
}
return refSchema;
}

private static SchemaFieldObjectType getObjectOrType(
final JsonNode schema, final String pojoName, final SpecFile specFile, final GlobalObject globalObject,
final Path baseDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ import lombok.Singular;
</#list>
import lombok.Value;
import lombok.extern.jackson.Jacksonized;
<#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf">
import ${packageModel}.exception.ModelClassException;
</#if>

@Value
public class ${schema.className} {
Expand Down
Loading