Skip to content

Commit 9584837

Browse files
authored
Merge branch 'main' into oneof
2 parents 95d7243 + 0763a59 commit 9584837

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ components:
6060
example: 123
6161
Order:
6262
type: object
63+
additionalProperties: true
6364
required:
6465
- productId
6566
- quantity

datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/SerializationTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
1212
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
1313
import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination;
14+
import com.sap.cloud.sdk.datamodel.openapi.sample.model.Order;
1415
import com.sap.cloud.sdk.datamodel.openapi.sample.model.SodaWithId;
1516

1617
@WireMockTest
@@ -48,7 +49,7 @@ void testPutPayload()
4849
}
4950

5051
@Test
51-
void testJacksonSerialization()
52+
void testJacksonSerializeSodaWithId()
5253
throws JsonProcessingException
5354
{
5455
expected = """
@@ -75,6 +76,26 @@ void testJacksonSerialization()
7576
assertThat(new ObjectMapper().writeValueAsString(obj)).isEqualToIgnoringWhitespace(expected);
7677
}
7778

79+
@Test
80+
void testJacksonSerializeOrder()
81+
throws JsonProcessingException
82+
{
83+
expected = """
84+
{
85+
"productId": 100,
86+
"quantity": 5,
87+
"totalPrice": 6.0,
88+
"typelessProperty":null,
89+
"nullableProperty":null,
90+
"shoesize": 44
91+
}
92+
""";
93+
final Order order = Order.create().productId(100L).quantity(5).totalPrice(6.0f);
94+
order.setCustomField("shoesize", 44);
95+
assertThat(new ObjectMapper().writeValueAsString(order)).isEqualToIgnoringWhitespace(expected);
96+
assertThat(new ObjectMapper().readValue(expected, Order.class)).isEqualTo(order);
97+
}
98+
7899
private void verify( String requestBody )
79100
{
80101
WireMock

datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/GenerationConfigurationConverter.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@ private void useCreatorsForInterfaceSubtypes( @Nonnull final CodegenModel m )
154154
}
155155
}
156156
}
157+
158+
@SuppressWarnings( { "rawtypes", "RedundantSuppression" } )
159+
@Override
160+
protected void updateModelForObject( @Nonnull final CodegenModel m, @Nonnull final Schema schema )
161+
{
162+
// Disable additional attributes to prevent model classes from extending "HashMap"
163+
// SAP Cloud SDK offers custom field APIs to handle additional attributes already
164+
schema.setAdditionalProperties(Boolean.FALSE);
165+
super.updateModelForObject(m, schema);
166+
}
157167
};
158168
}
159169

release_notes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121

2222
### 🐛 Fixed Issues
2323

24-
-
24+
- Fix non-compilable code using OpenAPI generator with schema definitions having `additionalProperties: true`.
25+
Previously they would result in model classes extending `HashMap`, which disabled proper deserialization and serialization.

0 commit comments

Comments
 (0)