Skip to content

Commit 4261296

Browse files
joseegman-idoneeajoseegarciaclaude
authored
Fix Maven Central publish and refine prefixItems element type (6.5.1) (#383)
Release fix: - Bump central-publishing-maven-plugin 0.6.0 -> 0.11.0. Version 0.6.0 fails deserializing the Sonatype Central API response with UnrecognizedPropertyException on the new `warnings` field (the client lacks @JsonIgnoreProperties(ignoreUnknown=true)); newer versions tolerate it. The bundle uploaded fine — only the post-upload status parse failed. Minor improvement (deferred OpenAPI 3.1 item): - prefixItems tuples now generate List<T> when every position shares one type, instead of always List<Object> (mixed/untypable still degrade to Object). Bumps version 6.5.0 -> 6.5.1 (Maven Central versions are immutable, so the failed 6.5.0 publish requires a fresh version). Full multiapi-engine suite: 110/110 (mvn clean test). Co-authored-by: joseegarcia <jose.garcia@disashop.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent bcbbd34 commit 4261296

5 files changed

Lines changed: 47 additions & 19 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.5.0</version>
7+
<version>6.5.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: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,15 @@ private static List<SchemaFieldObject> processArray(
448448
final List<SchemaFieldObject> fieldObjectArrayList = new LinkedList<>();
449449

450450
if (!ApiTool.hasItems(schema) || ApiTool.getItems(schema).isBoolean()) {
451-
// No `items` schema, or `items: false` (JSON Schema 2020-12). If the array
452-
// declares positional `prefixItems` (tuple), or nothing typable at all, the
453-
// element type degrades to Object -> List<Object>.
451+
// No `items` schema, or `items: false` (JSON Schema 2020-12). A `prefixItems`
452+
// tuple becomes a List of its common element type when every position shares one
453+
// type, otherwise (mixed types, or nothing typable) the element type is Object.
454454
final boolean isTuple = ApiTool.hasPrefixItems(schema);
455455
fieldObjectArrayList.add(SchemaFieldObject
456456
.builder()
457457
.baseName(fieldName)
458458
.dataType(isTuple
459-
? SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, TypeConstants.OBJECT)
459+
? SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, uniformPrefixItemType(schema, specFile))
460460
: new SchemaFieldObjectType(TypeConstants.OBJECT))
461461
.build());
462462
} else {
@@ -922,8 +922,35 @@ private static String resolveArrayItemType(final JsonNode schema, final CommonSp
922922
if (Objects.nonNull(items) && !items.isBoolean()) {
923923
return ApiTool.hasRef(items) ? MapperUtil.getPojoNameFromRef(items, specFile, null) : ApiTool.getType(items);
924924
}
925-
// `prefixItems` (tuple) or `items: false` -> degrade the element type to Object.
926-
return TypeConstants.OBJECT;
925+
// `prefixItems` (tuple): common element type if uniform, else Object. `items: false` -> Object.
926+
return uniformPrefixItemType(schema, specFile);
927+
}
928+
929+
private static String uniformPrefixItemType(final JsonNode schema, final CommonSpecFile specFile) {
930+
if (!ApiTool.hasPrefixItems(schema)) {
931+
return TypeConstants.OBJECT;
932+
}
933+
final JsonNode prefixItems = ApiTool.getPrefixItems(schema);
934+
if (Objects.isNull(prefixItems) || !prefixItems.isArray() || !prefixItems.elements().hasNext()) {
935+
return TypeConstants.OBJECT;
936+
}
937+
String common = null;
938+
for (final JsonNode item : prefixItems) {
939+
final String type;
940+
if (ApiTool.hasRef(item)) {
941+
type = MapperUtil.getPojoNameFromRef(item, specFile, null);
942+
} else if (ApiTool.hasType(item)) {
943+
type = MapperUtil.getSimpleType(item, specFile);
944+
} else {
945+
return TypeConstants.OBJECT;
946+
}
947+
if (Objects.isNull(common)) {
948+
common = type;
949+
} else if (!common.equals(type)) {
950+
return TypeConstants.OBJECT;
951+
}
952+
}
953+
return Objects.isNull(common) ? TypeConstants.OBJECT : common;
927954
}
928955

929956
private static SchemaFieldObject buildPatternPropertiesField(

multiapi-engine/src/test/resources/openapigenerator/testOpenApi31Completeness/assets/GadgetDTO.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.springframework.web.multipart.MultipartFile;
1010
import java.util.List;
1111
import java.util.ArrayList;
12+
import java.math.BigDecimal;
1213
import java.util.Map;
1314
import java.util.HashMap;
1415

@@ -24,7 +25,7 @@ public class GadgetDTO {
2425
@JsonProperty(value ="metadata")
2526
private Map<String, String> metadata;
2627
@JsonProperty(value ="coords")
27-
private List<Object> coords;
28+
private List<BigDecimal> coords;
2829
@JsonProperty(value ="owner")
2930
private PersonDTO owner;
3031
@JsonProperty(value ="serial")
@@ -52,7 +53,7 @@ public static class GadgetDTOBuilder {
5253
private Object nothing;
5354
private String id;
5455
private Map<String, String> metadata = new HashMap<String, String>();
55-
private List<Object> coords = new ArrayList<Object>();
56+
private List<BigDecimal> coords = new ArrayList<BigDecimal>();
5657
private PersonDTO owner;
5758
private String serial;
5859

@@ -81,14 +82,14 @@ public GadgetDTO.GadgetDTOBuilder metadataValue(String key, String value) {
8182
return this;
8283
}
8384

84-
public GadgetDTO.GadgetDTOBuilder coords(List<Object> coords) {
85+
public GadgetDTO.GadgetDTOBuilder coords(List<BigDecimal> coords) {
8586
if (!coords.isEmpty()) {
8687
this.coords.addAll(coords);
8788
}
8889
return this;
8990
}
9091

91-
public GadgetDTO.GadgetDTOBuilder coord(Object coord) {
92+
public GadgetDTO.GadgetDTOBuilder coord(BigDecimal coord) {
9293
if (Objects.nonNull(coord)) {
9394
this.coords.add(coord);
9495
}
@@ -144,10 +145,10 @@ public void setMetadata(Map<String, String> metadata) {
144145
}
145146

146147
@Schema(name = "coords", required = false)
147-
public List<Object> getCoords() {
148+
public List<BigDecimal> getCoords() {
148149
return coords;
149150
}
150-
public void setCoords(List<Object> coords) {
151+
public void setCoords(List<BigDecimal> coords) {
151152
this.coords = coords;
152153
}
153154

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.5.0'
24+
version = '6.5.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.5.0'
34+
implementation 'com.sngular:multiapi-engine:6.5.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.5.0'
103+
implementation 'com.sngular:scs-multiapi-gradle-plugin:6.5.1'
104104
implementation 'org.assertj:assertj-core:3.24.2'
105105
}
106106

scs-multiapi-maven-plugin/pom.xml

Lines changed: 3 additions & 3 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.5.0</version>
7+
<version>6.5.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.5.0</version>
274+
<version>6.5.1</version>
275275
</dependency>
276276
<dependency>
277277
<groupId>org.apache.maven</groupId>
@@ -560,7 +560,7 @@
560560
<plugin>
561561
<groupId>org.sonatype.central</groupId>
562562
<artifactId>central-publishing-maven-plugin</artifactId>
563-
<version>0.6.0</version>
563+
<version>0.11.0</version>
564564
<extensions>true</extensions>
565565
<configuration>
566566
<autoPublish>true</autoPublish>

0 commit comments

Comments
 (0)