generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 23
feat(openapi-generator): Suppress faulty additionalProperties: true
#689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8155673
Additional unit test checking for serialization of Order
a-d cb7a250
Merge remote-tracking branch 'origin/main' into openapi/fix-additonal…
a-d 7bd61ed
Initial problem
a-d da03cb2
Add fix
a-d ce8583b
Apply fix
a-d 626a111
Fix PMD warnings
a-d 7d10987
Merge remote-tracking branch 'origin/main' into openapi/fix-additonal…
a-d eb0ead1
Update
a-d 00a3bec
Fix PMD finding
a-d de634ef
Add test assertion
a-d b64c696
Add release note
a-d 1a5e417
Update datamodel/openapi/openapi-api-sample/pom.xml
MatKuhr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; | ||
| import com.github.tomakehurst.wiremock.junit5.WireMockTest; | ||
| import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination; | ||
| import com.sap.cloud.sdk.datamodel.openapi.sample.model.Order; | ||
| import com.sap.cloud.sdk.datamodel.openapi.sample.model.SodaWithId; | ||
|
|
||
| @WireMockTest | ||
|
|
@@ -48,7 +49,7 @@ void testPutPayload() | |
| } | ||
|
|
||
| @Test | ||
| void testJacksonSerialization() | ||
| void testJacksonSerializeSodaWithId() | ||
| throws JsonProcessingException | ||
| { | ||
| expected = """ | ||
|
|
@@ -75,6 +76,25 @@ void testJacksonSerialization() | |
| assertThat(new ObjectMapper().writeValueAsString(obj)).isEqualToIgnoringWhitespace(expected); | ||
| } | ||
|
|
||
| @Test | ||
| void testJacksonSerializeOrder() | ||
newtork marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throws JsonProcessingException | ||
| { | ||
| expected = """ | ||
| { | ||
| "productId": 100, | ||
| "quantity": 5, | ||
| "totalPrice": 6.0, | ||
| "typelessProperty":null, | ||
| "nullableProperty":null, | ||
| "shoesize": 44 | ||
| } | ||
| """; | ||
| final Order order = Order.create().productId(100L).quantity(5).totalPrice(6.0f); | ||
| order.setCustomField("shoesize", 44); | ||
| assertThat(new ObjectMapper().writeValueAsString(order)).isEqualToIgnoringWhitespace(expected); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Comment) Without the enabled feature toggle this test assertion fails: |
||
| } | ||
|
|
||
| private void verify( String requestBody ) | ||
| { | ||
| WireMock | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...rc/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/GeneratorCustomProperties.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package com.sap.cloud.sdk.datamodel.openapi.generator; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
||
| import com.sap.cloud.sdk.datamodel.openapi.generator.model.GenerationConfiguration; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| /** | ||
| * Optional feature toggles, may be used internally only. | ||
| */ | ||
| @RequiredArgsConstructor | ||
| enum GeneratorCustomProperties | ||
| { | ||
| /** | ||
| * Disable additional properties in generated models. They resolve to model classes extending from HashMap, | ||
| * effectively disabling serialization. Jackson by default only serializes the map entries and will ignore all | ||
| * fields from the model class. | ||
| */ | ||
| STOP_ADDITIONAL_PROPERTIES("stopAdditionalProperties", "false"); | ||
newtork marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private final String key; | ||
| private final String defaultValue; | ||
|
|
||
| /** | ||
| * Check if the feature is enabled. | ||
| * | ||
| * @param config | ||
| * The generation configuration. | ||
| * @return True if the feature is enabled, false otherwise. | ||
| */ | ||
| public boolean isEnabled( @Nonnull final GenerationConfiguration config ) | ||
| { | ||
| final var value = getValue(config); | ||
| return !value.isEmpty() && !"false".equalsIgnoreCase(value.trim()); | ||
| } | ||
|
|
||
| /** | ||
| * Get the value of the feature. | ||
| * | ||
| * @param config | ||
| * The generation configuration. | ||
| * @return The value of the feature. | ||
| */ | ||
| @Nonnull | ||
| public String getValue( @Nonnull final GenerationConfiguration config ) | ||
| { | ||
| return config.getAdditionalProperties().getOrDefault(key, defaultValue); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.