File tree Expand file tree Collapse file tree 4 files changed +37
-2
lines changed
test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api
openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator Expand file tree Collapse file tree 4 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ components:
6060 example : 123
6161 Order :
6262 type : object
63+ additionalProperties : true
6364 required :
6465 - productId
6566 - quantity
Original file line number Diff line number Diff line change 1111import com .github .tomakehurst .wiremock .junit5 .WireMockRuntimeInfo ;
1212import com .github .tomakehurst .wiremock .junit5 .WireMockTest ;
1313import com .sap .cloud .sdk .cloudplatform .connectivity .DefaultHttpDestination ;
14+ import com .sap .cloud .sdk .datamodel .openapi .sample .model .Order ;
1415import 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
Original file line number Diff line number Diff line change 1111
1212import org .openapitools .codegen .ClientOptInput ;
1313import org .openapitools .codegen .CodegenConstants ;
14+ import org .openapitools .codegen .CodegenModel ;
1415import org .openapitools .codegen .CodegenOperation ;
1516import org .openapitools .codegen .config .GlobalSettings ;
1617import org .openapitools .codegen .languages .JavaClientCodegen ;
2324
2425import io .swagger .parser .OpenAPIParser ;
2526import io .swagger .v3 .oas .models .OpenAPI ;
27+ import io .swagger .v3 .oas .models .media .Schema ;
2628import io .swagger .v3 .parser .core .models .AuthorizationValue ;
2729import io .swagger .v3 .parser .core .models .ParseOptions ;
2830import lombok .extern .slf4j .Slf4j ;
@@ -89,6 +91,16 @@ public OperationsMap postProcessOperationsWithModels(
8991 }
9092 return super .postProcessOperationsWithModels (ops , allModels );
9193 }
94+
95+ @ SuppressWarnings ( { "rawtypes" , "RedundantSuppression" } )
96+ @ Override
97+ protected void updateModelForObject ( @ Nonnull final CodegenModel m , @ Nonnull final Schema schema )
98+ {
99+ // Disable additional attributes to prevent model classes from extending "HashMap"
100+ // SAP Cloud SDK offers custom field APIs to handle additional attributes already
101+ schema .setAdditionalProperties (Boolean .FALSE );
102+ super .updateModelForObject (m , schema );
103+ }
92104 };
93105 }
94106
Original file line number Diff line number Diff line change 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.
You can’t perform that action at this time.
0 commit comments