Skip to content

Commit 98f3deb

Browse files
joseegarciaclaude
andcommitted
Map array of binary strings to List<MultipartFile>
processArray resolved simple array item types via MapperUtil.getSimpleType, which has no binary detection, so `type: array, items: {type: string, format: binary}` produced List<String>. Detect binary items with ApiTool.isBinary (covers both OpenAPI 3.0 `format: binary` and 3.1 contentEncoding/contentMediaType) and map them to MultipartFile, matching the existing scalar-property behaviour in processStringProperty. Adds an array-of-binary property to the testSimpleBuild Document schema as a regression test. Fixes #386 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 267aa2d commit 98f3deb

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,11 @@ private static List<SchemaFieldObject> processArray(
493493
.dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getPojoName(fieldName, specFile)))
494494
.build());
495495
} else {
496+
final String itemType = ApiTool.isBinary(items) ? TypeConstants.MULTIPART_FILE : MapperUtil.getSimpleType(items, specFile);
496497
final SchemaFieldObject field = SchemaFieldObject
497498
.builder()
498499
.baseName(fieldName)
499-
.dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile)))
500+
.dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, itemType))
500501
.build();
501502
fieldObjectArrayList.add(field);
502503
addPropertiesToFieldObject(field, schema);

multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/api-rest.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,11 @@ components:
522522
type: string
523523
format: binary
524524
example: invoice01234.pdf
525+
attachments:
526+
type: array
527+
items:
528+
type: string
529+
format: binary
525530
description:
526531
type: string
527532
example: Invoice for the sale 01234

multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/DocumentDTO.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import org.springframework.web.multipart.MultipartFile;
5+
import java.util.List;
6+
import java.util.ArrayList;
57
import lombok.Builder;
8+
import lombok.Singular;
69
import lombok.Value;
710
import lombok.extern.jackson.Jacksonized;
811

@@ -12,14 +15,19 @@ public class DocumentDTO {
1215
@JsonProperty(value ="description")
1316
private String description;
1417

18+
@JsonProperty(value ="attachments")
19+
@Singular("attachment")
20+
private List<MultipartFile> attachments;
21+
1522
@JsonProperty(value ="document")
1623
private MultipartFile document;
1724

1825

1926
@Builder
2027
@Jacksonized
21-
private DocumentDTO(String description, MultipartFile document) {
28+
private DocumentDTO(String description, List<MultipartFile> attachments, MultipartFile document) {
2229
this.description = description;
30+
this.attachments = attachments;
2331
this.document = document;
2432

2533
}

0 commit comments

Comments
 (0)