Skip to content

Commit d2e961b

Browse files
joseegman-idoneeajoseegarciaclaude
authored
Map array of binary strings to List<MultipartFile> (sngular#387)
* 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 sngular#386 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Bump version to 6.6.1 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: joseegarcia <jose.garcia@disashop.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 267aa2d commit d2e961b

6 files changed

Lines changed: 22 additions & 8 deletions

File tree

multiapi-engine/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.sngular</groupId>
66
<artifactId>multiapi-engine</artifactId>
7-
<version>6.6.0</version>
7+
<version>6.6.1</version>
88
<packaging>jar</packaging>
99

1010
<properties>

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
}

scs-multiapi-gradle-plugin/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repositories {
2121
}
2222

2323
group = 'com.sngular'
24-
version = '6.6.0'
24+
version = '6.6.1'
2525

2626
def SCSMultiApiPluginGroupId = group
2727
def SCSMultiApiPluginVersion = version
@@ -31,7 +31,7 @@ dependencies {
3131
shadow localGroovy()
3232
shadow gradleApi()
3333

34-
implementation 'com.sngular:multiapi-engine:6.6.0'
34+
implementation 'com.sngular:multiapi-engine:6.6.1'
3535
testImplementation 'org.assertj:assertj-core:3.24.2'
3636
testImplementation 'com.puppycrawl.tools:checkstyle:10.12.3'
3737
testImplementation 'org.junit.platform:junit-platform-launcher:1.9.2'
@@ -100,7 +100,7 @@ testing {
100100

101101
integrationTest(JvmTestSuite) {
102102
dependencies {
103-
implementation 'com.sngular:scs-multiapi-gradle-plugin:6.6.0'
103+
implementation 'com.sngular:scs-multiapi-gradle-plugin:6.6.1'
104104
implementation 'org.assertj:assertj-core:3.24.2'
105105
}
106106

scs-multiapi-maven-plugin/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.sngular</groupId>
66
<artifactId>scs-multiapi-maven-plugin</artifactId>
7-
<version>6.6.0</version>
7+
<version>6.6.1</version>
88
<packaging>maven-plugin</packaging>
99

1010
<name>AsyncApi - OpenApi Code Generator Maven Plugin</name>
@@ -271,7 +271,7 @@
271271
<dependency>
272272
<groupId>com.sngular</groupId>
273273
<artifactId>multiapi-engine</artifactId>
274-
<version>6.6.0</version>
274+
<version>6.6.1</version>
275275
</dependency>
276276
<dependency>
277277
<groupId>org.apache.maven</groupId>

0 commit comments

Comments
 (0)