From e9caba63db2d68f4cb59edcb8d52f1a7c186bb9c Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Wed, 4 Sep 2024 09:15:54 +0200 Subject: [PATCH] feat (Verification/StartSMS): Support additional properties onto Start request --- .../VerificationsStartServiceTest.java | 16 ++- .../VerificationsDtoConverterTest.java | 19 +++- .../VerificationStartServiceTest.java | 19 ++-- .../sinch/sdk/core/utils/databind/Mapper.java | 30 +++-- .../request/VerificationStartRequestSms.java | 17 +++ .../VerificationStartRequestSmsImpl.java | 30 +++-- .../internal/VerificationStartSmsOptions.java | 16 +++ .../VerificationStartSmsOptionsImpl.java | 57 +++++++++- .../VerificationStartRequestTest.java | 14 ++- .../VerificationStartSmsOptionsTest.java | 103 ++++++++++++++++++ .../VerificationStartResponseTest.java | 14 ++- .../VerificationStartRequestDataDto.json | 0 .../VerificationStartRequestFlashCallDto.json | 0 .../VerificationStartRequestPhoneCallDto.json | 0 .../VerificationStartRequestSmsDto.json | 3 +- .../VerificationStartSmsOptionsDto.json | 5 + ...SmsOptionsWithAdditionalPropertiesDto.json | 7 ++ .../VerificationStartResponseDataDto.json | 0 ...VerificationStartResponseFlashCallDto.json | 0 ...VerificationStartResponsePhoneCallDto.json | 0 .../VerificationStartResponseSmsDto.json | 0 .../verification/VerificationService.java | 2 +- 22 files changed, 299 insertions(+), 53 deletions(-) rename openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/{ => request}/VerificationStartRequestTest.java (90%) create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/request/internal/VerificationStartSmsOptionsTest.java rename openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/{ => response}/VerificationStartResponseTest.java (87%) rename openapi-contracts/src/test/resources/domains/verification/v1/start/{ => request}/VerificationStartRequestDataDto.json (100%) rename openapi-contracts/src/test/resources/domains/verification/v1/start/{ => request}/VerificationStartRequestFlashCallDto.json (100%) rename openapi-contracts/src/test/resources/domains/verification/v1/start/{ => request}/VerificationStartRequestPhoneCallDto.json (100%) rename openapi-contracts/src/test/resources/domains/verification/v1/start/{ => request}/VerificationStartRequestSmsDto.json (72%) create mode 100644 openapi-contracts/src/test/resources/domains/verification/v1/start/request/internal/VerificationStartSmsOptionsDto.json create mode 100644 openapi-contracts/src/test/resources/domains/verification/v1/start/request/internal/VerificationStartSmsOptionsWithAdditionalPropertiesDto.json rename openapi-contracts/src/test/resources/domains/verification/v1/start/{ => response}/VerificationStartResponseDataDto.json (100%) rename openapi-contracts/src/test/resources/domains/verification/v1/start/{ => response}/VerificationStartResponseFlashCallDto.json (100%) rename openapi-contracts/src/test/resources/domains/verification/v1/start/{ => response}/VerificationStartResponsePhoneCallDto.json (100%) rename openapi-contracts/src/test/resources/domains/verification/v1/start/{ => response}/VerificationStartResponseSmsDto.json (100%) diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/adapters/VerificationsStartServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/adapters/VerificationsStartServiceTest.java index 565a02017..2a2499cdc 100644 --- a/client/src/test/java/com/sinch/sdk/domains/verification/adapters/VerificationsStartServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/verification/adapters/VerificationsStartServiceTest.java @@ -1,5 +1,6 @@ package com.sinch.sdk.domains.verification.adapters; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -9,11 +10,12 @@ import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.domains.verification.adapters.converters.VerificationsDtoConverterTest; -import com.sinch.sdk.domains.verification.models.dto.v1.start.VerificationStartResponseTest; +import com.sinch.sdk.domains.verification.models.dto.v1.start.response.VerificationStartResponseTest; import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseCallout; import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseFlashCall; import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseSMS; import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseSeamless; +import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSms; import com.sinch.sdk.domains.verification.models.v1.start.request.internal.VerificationStartRequestInternalImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,16 +24,18 @@ @TestWithResources public class VerificationsStartServiceTest extends VerificationBaseTest { - @GivenJsonResource("/domains/verification/v1/start/VerificationStartRequestPhoneCallDto.json") + @GivenJsonResource( + "/domains/verification/v1/start/request/VerificationStartRequestPhoneCallDto.json") public VerificationStartRequestInternalImpl startVerificationPhoneCallRequestDto; - @GivenJsonResource("/domains/verification/v1/start/VerificationStartRequestFlashCallDto.json") + @GivenJsonResource( + "/domains/verification/v1/start/request/VerificationStartRequestFlashCallDto.json") public VerificationStartRequestInternalImpl startVerificationFlashCallRequestDto; - @GivenJsonResource("/domains/verification/v1/start/VerificationStartRequestDataDto.json") + @GivenJsonResource("/domains/verification/v1/start/request/VerificationStartRequestDataDto.json") public VerificationStartRequestInternalImpl startVerificationDataRequestDto; - @GivenJsonResource("/domains/verification/v1/start/VerificationStartRequestSmsDto.json") + @GivenJsonResource("/domains/verification/v1/start/request/VerificationStartRequestSmsDto.json") public VerificationStartRequestInternalImpl startVerificationSmsRequestDto; @Mock com.sinch.sdk.domains.verification.api.v1.VerificationStartService v1; @@ -46,7 +50,7 @@ public void initMocks() { @Test void startSms() throws ApiException { - when(v1.startSms(eq(startVerificationSmsRequestDto.getVerificationStartRequestSmsImpl()))) + when(v1.startSms(any(VerificationStartRequestSms.class))) .thenReturn( VerificationStartResponseTest.expectedStartVerificationSmsDto .getVerificationStartResponseSmsImpl()); diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverterTest.java index b19647823..5fda5e3ca 100644 --- a/client/src/test/java/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverterTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverterTest.java @@ -17,8 +17,8 @@ import com.sinch.sdk.domains.verification.models.VerificationStatusType; import com.sinch.sdk.domains.verification.models.dto.v1.report.VerificationReportRequestDtoTest; import com.sinch.sdk.domains.verification.models.dto.v1.report.VerificationReportResponseDtoTest; -import com.sinch.sdk.domains.verification.models.dto.v1.start.VerificationStartRequestTest; -import com.sinch.sdk.domains.verification.models.dto.v1.start.VerificationStartResponseTest; +import com.sinch.sdk.domains.verification.models.dto.v1.start.request.VerificationStartRequestTest; +import com.sinch.sdk.domains.verification.models.dto.v1.start.response.VerificationStartResponseTest; import com.sinch.sdk.domains.verification.models.dto.v1.status.VerificationStatusResponseTest; import com.sinch.sdk.domains.verification.models.requests.SMSCodeType; import com.sinch.sdk.domains.verification.models.requests.StartVerificationCalloutOptions; @@ -35,6 +35,8 @@ import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseFlashCall; import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseSMS; import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseSeamless; +import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequest; +import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSms; import java.time.Instant; import org.junit.jupiter.api.Test; @@ -136,9 +138,18 @@ void convertStartDataRequest() { @Test void convertStartSmsRequest() { + VerificationStartRequest expected = + VerificationStartRequestSms.builder() + .setCustom("a custom") + .setReference("a reference") + .setIdentity( + com.sinch.sdk.domains.verification.models.v1.NumberIdentity.valueOf("+endpoint")) + .setExpiry("01:02:03") + .setCodeType(VerificationStartRequestSms.CodeTypeEnum.ALPHANUMERIC) + .setTemplate("My template require to use '{{CODE}}' code") + .build(); TestHelpers.recursiveEquals( - VerificationsDtoConverter.convert(startVerificationSmsRequest), - VerificationStartRequestTest.startVerificationSmsDto.getVerificationStartRequestSmsImpl()); + VerificationsDtoConverter.convert(startVerificationSmsRequest), expected); } @Test diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStartServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStartServiceTest.java index fc75f572a..89629faba 100644 --- a/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStartServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStartServiceTest.java @@ -1,5 +1,6 @@ package com.sinch.sdk.domains.verification.api.v1.adapters; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; @@ -13,8 +14,8 @@ import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.domains.verification.adapters.VerificationBaseTest; import com.sinch.sdk.domains.verification.api.v1.internal.VerificationsStartApi; -import com.sinch.sdk.domains.verification.models.dto.v1.start.VerificationStartRequestTest; -import com.sinch.sdk.domains.verification.models.dto.v1.start.VerificationStartResponseTest; +import com.sinch.sdk.domains.verification.models.dto.v1.start.request.VerificationStartRequestTest; +import com.sinch.sdk.domains.verification.models.dto.v1.start.response.VerificationStartResponseTest; import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequest; import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSms; import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSmsImpl; @@ -33,16 +34,18 @@ @TestWithResources public class VerificationStartServiceTest extends VerificationBaseTest { - @GivenJsonResource("/domains/verification/v1/start/VerificationStartRequestPhoneCallDto.json") + @GivenJsonResource( + "/domains/verification/v1/start/request/VerificationStartRequestPhoneCallDto.json") public VerificationStartRequestInternal startVerificationPhoneCallRequestDto; - @GivenJsonResource("/domains/verification/v1/start/VerificationStartRequestFlashCallDto.json") + @GivenJsonResource( + "/domains/verification/v1/start/request/VerificationStartRequestFlashCallDto.json") public VerificationStartRequestInternal startVerificationFlashCallRequestDto; - @GivenJsonResource("/domains/verification/v1/start/VerificationStartRequestDataDto.json") + @GivenJsonResource("/domains/verification/v1/start/request/VerificationStartRequestDataDto.json") public VerificationStartRequestInternal startVerificationDataRequestDto; - @GivenJsonResource("/domains/verification/v1/start/VerificationStartRequestSmsDto.json") + @GivenJsonResource("/domains/verification/v1/start/request/VerificationStartRequestSmsDto.json") public VerificationStartRequestInternal startVerificationSmsRequestDto; @Mock VerificationsStartApi api; @@ -62,7 +65,7 @@ public void initMocks() { @Test void startSms() throws ApiException { - when(api.startVerification(eq(startVerificationSmsRequestDto), eq(null))) + when(api.startVerification(any(VerificationStartRequestInternal.class), eq(null))) .thenReturn(VerificationStartResponseTest.expectedStartVerificationSmsDto); VerificationStartResponseSms response = @@ -95,7 +98,7 @@ void startSmsWithAcceptLanguage() throws ApiException { new VerificationStartRequestInternalImpl(); internalWithAcceptLanguage.setActualInstance(withAcceptLanguage); - when(api.startVerification(eq(internalWithAcceptLanguage), eq("es-ES"))) + when(api.startVerification(any(VerificationStartRequestInternal.class), eq("es-ES"))) .thenReturn(VerificationStartResponseTest.expectedStartVerificationSmsDto); VerificationStartResponseSms response = diff --git a/core/src/main/com/sinch/sdk/core/utils/databind/Mapper.java b/core/src/main/com/sinch/sdk/core/utils/databind/Mapper.java index a81a2928a..5a6dd6145 100644 --- a/core/src/main/com/sinch/sdk/core/utils/databind/Mapper.java +++ b/core/src/main/com/sinch/sdk/core/utils/databind/Mapper.java @@ -1,5 +1,6 @@ package com.sinch.sdk.core.utils.databind; +import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; @@ -47,19 +48,24 @@ public void serializeAsField( // Do not serialize uninitialized fields to avoid sending a null value when not required boolean serialize; - // Call getter to obtain value: if of OptionalValue type: use it to check serialization - // state - Object value = pojo.getClass().getMethod(member.getName()).invoke(pojo); - if (value instanceof OptionalValue) { - serialize = ((OptionalValue) value).isPresent(); + if (member.hasAnnotation(JsonAnyGetter.class)) { + serialize = true; } else { - /* @Deprecated - * Not find the expected OptionalValue: fallback to xxxDefined function call - * The xxDefined function feature will have to be deprecated in favour of OptionalValue usage - * This part could be suppressed as soon as all domains had moved to the OptionalValue support from OAS generated files - */ - serialize = - (boolean) pojo.getClass().getMethod(member.getName() + "Defined").invoke(pojo); + // Call getter to obtain value: if of OptionalValue type: use it to check + // serialization + // state + Object value = pojo.getClass().getMethod(member.getName()).invoke(pojo); + if (value instanceof OptionalValue) { + serialize = ((OptionalValue) value).isPresent(); + } else { + /* @Deprecated + * Not find the expected OptionalValue: fallback to xxxDefined function call + * The xxDefined function feature will have to be deprecated in favour of OptionalValue usage + * This part could be suppressed as soon as all domains had moved to the OptionalValue support from OAS generated files + */ + serialize = + (boolean) pojo.getClass().getMethod(member.getName() + "Defined").invoke(pojo); + } } // not set but is field is required ? if (!serialize) { diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/VerificationStartRequestSms.java b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/VerificationStartRequestSms.java index f64a545b8..778041ac9 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/VerificationStartRequestSms.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/VerificationStartRequestSms.java @@ -104,6 +104,15 @@ public static String valueOf(CodeTypeEnum e) { */ String getAcceptLanguage(); + /** + * Return the extra-additional property with the specified name. Used in case of delegation + * pattern in use by class + * + * @param key the name of the property + * @return the additional property with the specified name + */ + Object getExtraOption(String key); + /** * Getting builder * @@ -181,6 +190,14 @@ interface Builder */ Builder setAcceptLanguage(String acceptLanguage); + /** + * see getter + * + * @return Current builder + * @see #getExtraOption + */ + Builder putExtraOption(String key, Object value); + /** * Create instance * diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/VerificationStartRequestSmsImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/VerificationStartRequestSmsImpl.java index ba80837ee..8a6c550e3 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/VerificationStartRequestSmsImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/VerificationStartRequestSmsImpl.java @@ -126,8 +126,10 @@ public String getExpiry() { } public OptionalValue expiry() { - return null != smsOptions - ? smsOptions.map(VerificationStartSmsOptions::getExpiry) + return null != smsOptions && smsOptions.isPresent() + ? smsOptions + .map(f -> ((VerificationStartSmsOptionsImpl) f).expiry()) + .orElse(OptionalValue.empty()) : OptionalValue.empty(); } @@ -140,7 +142,7 @@ public CodeTypeEnum getCodeType() { } public OptionalValue codeType() { - return null != smsOptions + return null != smsOptions && smsOptions.isPresent() ? smsOptions.map(f -> CodeTypeEnum.from(smsOptions.get().getCodeType().value())) : OptionalValue.empty(); } @@ -154,8 +156,10 @@ public String getTemplate() { } public OptionalValue template() { - return null != smsOptions - ? smsOptions.map(VerificationStartSmsOptions::getTemplate) + return null != smsOptions && smsOptions.isPresent() + ? smsOptions + .map(f -> ((VerificationStartSmsOptionsImpl) f).template()) + .orElse(OptionalValue.empty()) : OptionalValue.empty(); } @@ -170,11 +174,18 @@ public String getAcceptLanguage() { } public OptionalValue acceptLanguage() { - return null != smsOptions - ? smsOptions.map(VerificationStartSmsOptions::getAcceptLanguage) + return null != smsOptions && smsOptions.isPresent() + ? smsOptions + .map(f -> ((VerificationStartSmsOptionsImpl) f).acceptLanguage()) + .orElse(OptionalValue.empty()) : OptionalValue.empty(); } + @JsonIgnore + public Object getExtraOption(String key) { + return null != smsOptions && smsOptions.isPresent() ? smsOptions.get().get(key) : null; + } + /** Return true if this VerificationStartRequestSms object is equal to o. */ @Override public boolean equals(Object o) { @@ -283,6 +294,11 @@ public Builder setAcceptLanguage(String acceptLanguage) { return this; } + public Builder putExtraOption(String key, Object value) { + getDelegatedBuilder().put(key, value); + return this; + } + private VerificationStartSmsOptions.Builder getDelegatedBuilder() { if (null == _delegatedBuilder) { this._delegatedBuilder = VerificationStartSmsOptions.builder(); diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/internal/VerificationStartSmsOptions.java b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/internal/VerificationStartSmsOptions.java index 522f36e08..580197427 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/internal/VerificationStartSmsOptions.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/internal/VerificationStartSmsOptions.java @@ -84,6 +84,14 @@ public static String valueOf(CodeTypeEnum e) { */ String getAcceptLanguage(); + /** + * Return the additional property with the specified name. + * + * @param key the name of the property + * @return the additional property with the specified name + */ + Object get(String key); + /** * Getting builder * @@ -132,6 +140,14 @@ interface Builder { */ Builder setAcceptLanguage(String acceptLanguage); + /** + * see getter + * + * @return Current builder + * @see #get + */ + Builder put(String key, Object value); + /** * Create instance * diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/internal/VerificationStartSmsOptionsImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/internal/VerificationStartSmsOptionsImpl.java index 82509907f..9ed8e96f3 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/internal/VerificationStartSmsOptionsImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/internal/VerificationStartSmsOptionsImpl.java @@ -1,5 +1,7 @@ package com.sinch.sdk.domains.verification.models.v1.start.request.internal; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonFilter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; @@ -7,6 +9,8 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.sinch.sdk.core.models.OptionalValue; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; @JsonPropertyOrder({ @@ -33,17 +37,25 @@ public class VerificationStartSmsOptionsImpl implements VerificationStartSmsOpti private OptionalValue acceptLanguage; + /** + * A container for additional, undeclared properties. This is a holder for any undeclared + * properties as specified with the 'additionalProperties' keyword in the OAS document. + */ + private OptionalValue> additionalProperties; + public VerificationStartSmsOptionsImpl() {} protected VerificationStartSmsOptionsImpl( OptionalValue expiry, OptionalValue codeType, OptionalValue template, - OptionalValue acceptLanguage) { + OptionalValue acceptLanguage, + OptionalValue> additionalProperties) { this.expiry = expiry; this.codeType = codeType; this.template = template; this.acceptLanguage = acceptLanguage; + this.additionalProperties = additionalProperties; } @JsonIgnore @@ -88,6 +100,23 @@ public OptionalValue acceptLanguage() { return acceptLanguage; } + @JsonIgnore + public Object get(String key) { + + if (null == this.additionalProperties || !additionalProperties.isPresent()) { + return null; + } + return this.additionalProperties.get().get(key); + } + + @JsonAnyGetter + public Map additionalProperties() { + if (null == this.additionalProperties || !additionalProperties.isPresent()) { + return null; + } + return additionalProperties.get(); + } + /** Return true if this VerificationStartRequestSms_allOf_smsOptions object is equal to o. */ @Override public boolean equals(Object o) { @@ -103,22 +132,31 @@ public boolean equals(Object o) { && Objects.equals(this.codeType, verificationStartRequestSmsAllOfSmsOptions.codeType) && Objects.equals(this.template, verificationStartRequestSmsAllOfSmsOptions.template) && Objects.equals( - this.acceptLanguage, verificationStartRequestSmsAllOfSmsOptions.acceptLanguage); + this.acceptLanguage, verificationStartRequestSmsAllOfSmsOptions.acceptLanguage) + && Objects.equals( + this.additionalProperties, + verificationStartRequestSmsAllOfSmsOptions.additionalProperties) + && super.equals(o); } @Override public int hashCode() { - return Objects.hash(expiry, codeType, template, acceptLanguage); + return Objects.hash( + expiry, codeType, template, acceptLanguage, super.hashCode(), additionalProperties); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class VerificationStartSmsOptionsImpl {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" expiry: ").append(toIndentedString(expiry)).append("\n"); sb.append(" codeType: ").append(toIndentedString(codeType)).append("\n"); sb.append(" template: ").append(toIndentedString(template)).append("\n"); sb.append(" acceptLanguage: ").append(toIndentedString(acceptLanguage)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -139,6 +177,7 @@ static class Builder implements VerificationStartSmsOptions.Builder { OptionalValue codeType = OptionalValue.empty(); OptionalValue template = OptionalValue.empty(); OptionalValue acceptLanguage = OptionalValue.empty(); + OptionalValue> additionalProperties = OptionalValue.empty(); @JsonProperty(JSON_PROPERTY_EXPIRY) public Builder setExpiry(String expiry) { @@ -164,8 +203,18 @@ public Builder setAcceptLanguage(String acceptLanguage) { return this; } + @JsonAnySetter + public Builder put(String key, Object value) { + if (!this.additionalProperties.isPresent()) { + this.additionalProperties = OptionalValue.of(new HashMap()); + } + this.additionalProperties.get().put(key, value); + return this; + } + public VerificationStartSmsOptions build() { - return new VerificationStartSmsOptionsImpl(expiry, codeType, template, acceptLanguage); + return new VerificationStartSmsOptionsImpl( + expiry, codeType, template, acceptLanguage, additionalProperties); } } } diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/VerificationStartRequestTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/request/VerificationStartRequestTest.java similarity index 90% rename from openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/VerificationStartRequestTest.java rename to openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/request/VerificationStartRequestTest.java index 6a5b973d8..52a730688 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/VerificationStartRequestTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/request/VerificationStartRequestTest.java @@ -1,4 +1,4 @@ -package com.sinch.sdk.domains.verification.models.dto.v1.start; +package com.sinch.sdk.domains.verification.models.dto.v1.start.request; import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; @@ -59,6 +59,7 @@ public class VerificationStartRequestTest extends VerificationBaseTest { .setExpiry("01:02:03") .setCodeType(VerificationStartRequestSms.CodeTypeEnum.ALPHANUMERIC) .setTemplate("My template require to use '{{CODE}}' code") + .putExtraOption("my key", "my value") .build()); public static VerificationStartRequestInternalImpl startVerificationSmsDtoWithAcceptLanguage = @@ -72,18 +73,21 @@ public class VerificationStartRequestTest extends VerificationBaseTest { .setCodeType(VerificationStartRequestSms.CodeTypeEnum.ALPHANUMERIC) .setTemplate("My template require to use '{{CODE}}' code") .setAcceptLanguage("es-ES") + .putExtraOption("my key", "my value") .build()); - @GivenTextResource("/domains/verification/v1/start/VerificationStartRequestPhoneCallDto.json") + @GivenTextResource( + "/domains/verification/v1/start/request/VerificationStartRequestPhoneCallDto.json") String jsonStartVerificationPhoneCall; - @GivenTextResource("/domains/verification/v1/start/VerificationStartRequestFlashCallDto.json") + @GivenTextResource( + "/domains/verification/v1/start/request/VerificationStartRequestFlashCallDto.json") String jsonStartVerificationFlashCall; - @GivenTextResource("/domains/verification/v1/start/VerificationStartRequestDataDto.json") + @GivenTextResource("/domains/verification/v1/start/request/VerificationStartRequestDataDto.json") String jsonStartVerificationData; - @GivenTextResource("/domains/verification/v1/start/VerificationStartRequestSmsDto.json") + @GivenTextResource("/domains/verification/v1/start/request/VerificationStartRequestSmsDto.json") String jsonStartVerificationSms; @Test diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/request/internal/VerificationStartSmsOptionsTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/request/internal/VerificationStartSmsOptionsTest.java new file mode 100644 index 000000000..8cf9f4740 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/request/internal/VerificationStartSmsOptionsTest.java @@ -0,0 +1,103 @@ +package com.sinch.sdk.domains.verification.models.dto.v1.start.request.internal; + +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.verification.adapters.VerificationBaseTest; +import com.sinch.sdk.domains.verification.models.v1.start.request.internal.VerificationStartSmsOptions; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class VerificationStartSmsOptionsTest extends VerificationBaseTest { + + public static VerificationStartSmsOptions startVerificationSmsOptionDto = + VerificationStartSmsOptions.builder() + .setExpiry("01:02:03") + .setCodeType(VerificationStartSmsOptions.CodeTypeEnum.ALPHANUMERIC) + .setTemplate("My template require to use '{{CODE}}' code") + .build(); + + public static VerificationStartSmsOptions startVerificationSmsOptionWithAdditionalPropertiesDto = + VerificationStartSmsOptions.builder() + .setExpiry("01:02:03") + .setCodeType(VerificationStartSmsOptions.CodeTypeEnum.ALPHANUMERIC) + .setTemplate("My template require to use '{{CODE}}' code") + .put("a key", "a value") + .put("secondKey", "second value") + .build(); + + public static VerificationStartSmsOptions startVerificationSmsOptionDtoWithAcceptLanguage = + VerificationStartSmsOptions.builder() + .setExpiry("01:02:03") + .setCodeType(VerificationStartSmsOptions.CodeTypeEnum.ALPHANUMERIC) + .setTemplate("My template require to use '{{CODE}}' code") + .setAcceptLanguage("es-ES") + .build(); + + @GivenTextResource( + "/domains/verification/v1/start/request/internal/VerificationStartSmsOptionsDto.json") + String jsonVerificationStartSmsOptions; + + @GivenTextResource( + "/domains/verification/v1/start/request/internal/VerificationStartSmsOptionsWithAdditionalPropertiesDto.json") + String jsonVerificationStartSmsOptionsWithAdditionalProperties; + + @Test + void serializeStartVerificationSmsOptions() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(startVerificationSmsOptionDto); + + JSONAssert.assertEquals(jsonVerificationStartSmsOptions, serializedString, true); + } + + @Test + void deserializeStartVerificationSmsOptions() throws JsonProcessingException { + Object deserialized = + objectMapper.readValue(jsonVerificationStartSmsOptions, VerificationStartSmsOptions.class); + + TestHelpers.recursiveEquals(deserialized, startVerificationSmsOptionDto); + } + + @Test + void serializeStartVerificationSmsOptionsWithAdditionalProperties() + throws JsonProcessingException, JSONException { + String serializedString = + objectMapper.writeValueAsString(startVerificationSmsOptionWithAdditionalPropertiesDto); + + JSONAssert.assertEquals( + jsonVerificationStartSmsOptionsWithAdditionalProperties, serializedString, true); + } + + @Test + void deserializeStartVerificationSmsOptionsWithAdditionalProperties() + throws JsonProcessingException { + Object deserialized = + objectMapper.readValue( + jsonVerificationStartSmsOptionsWithAdditionalProperties, + VerificationStartSmsOptions.class); + + TestHelpers.recursiveEquals( + deserialized, startVerificationSmsOptionWithAdditionalPropertiesDto); + } + + @Test + void serializeStartSmsCallWithAcceptLanguage() throws JsonProcessingException, JSONException { + String serializedString = + objectMapper.writeValueAsString(startVerificationSmsOptionDtoWithAcceptLanguage); + // acceptLanguage do not have to be serialized + JSONAssert.assertEquals(jsonVerificationStartSmsOptions, serializedString, true); + } + + @Test + void deserializeStartSmsCallWithAcceptLanguage() throws JsonProcessingException { + Object deserialized = + objectMapper.readValue(jsonVerificationStartSmsOptions, VerificationStartSmsOptions.class); + + // we are not expecting acceptLanguage to be unserialized because of not sent to network + // so this test is based onto startVerificationSmsOptionDto is having same content has the + // acceptLanguage instance... but without the language + TestHelpers.recursiveEquals(deserialized, startVerificationSmsOptionDto); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/VerificationStartResponseTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/response/VerificationStartResponseTest.java similarity index 87% rename from openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/VerificationStartResponseTest.java rename to openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/response/VerificationStartResponseTest.java index 8d9e3c632..ab1edfd0e 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/VerificationStartResponseTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/response/VerificationStartResponseTest.java @@ -1,9 +1,10 @@ -package com.sinch.sdk.domains.verification.models.dto.v1.start; +package com.sinch.sdk.domains.verification.models.dto.v1.start.response; import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.BaseTest; import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.verification.models.dto.v1.start.LinkTest; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseData; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseDataImpl; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseFlashCall; @@ -19,7 +20,8 @@ @TestWithResources public class VerificationStartResponseTest extends BaseTest { - @GivenJsonResource("/domains/verification/v1/start/VerificationStartResponsePhoneCallDto.json") + @GivenJsonResource( + "/domains/verification/v1/start/response/VerificationStartResponsePhoneCallDto.json") VerificationStartResponseInternal loadedStartVerificationPhoneCallDto; public static VerificationStartResponseInternalImpl expectedStartVerificationPhoneCallDto = @@ -30,7 +32,8 @@ public class VerificationStartResponseTest extends BaseTest { .setLinks(LinkTest.expectedLinks) .build()); - @GivenJsonResource("/domains/verification/v1/start/VerificationStartResponseFlashCallDto.json") + @GivenJsonResource( + "/domains/verification/v1/start/response/VerificationStartResponseFlashCallDto.json") VerificationStartResponseInternal loadedStartVerificationFlashCallDto; public static VerificationStartResponseInternalImpl expectedStartVerificationFlashCallDto = @@ -45,7 +48,8 @@ public class VerificationStartResponseTest extends BaseTest { .setDenyCallAfter(0) .build()); - @GivenJsonResource("/domains/verification/v1/start/VerificationStartResponseDataDto.json") + @GivenJsonResource( + "/domains/verification/v1/start/response/VerificationStartResponseDataDto.json") VerificationStartResponseInternal loadedStartVerificationDataDto; public static VerificationStartResponseInternalImpl expectedStartVerificationDataDto = @@ -57,7 +61,7 @@ public class VerificationStartResponseTest extends BaseTest { .setTargetUri("target URI") .build()); - @GivenJsonResource("/domains/verification/v1/start/VerificationStartResponseSmsDto.json") + @GivenJsonResource("/domains/verification/v1/start/response/VerificationStartResponseSmsDto.json") VerificationStartResponseInternal loadedStartVerificationSmsDto; public static VerificationStartResponseInternalImpl expectedStartVerificationSmsDto = diff --git a/openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartRequestDataDto.json b/openapi-contracts/src/test/resources/domains/verification/v1/start/request/VerificationStartRequestDataDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartRequestDataDto.json rename to openapi-contracts/src/test/resources/domains/verification/v1/start/request/VerificationStartRequestDataDto.json diff --git a/openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartRequestFlashCallDto.json b/openapi-contracts/src/test/resources/domains/verification/v1/start/request/VerificationStartRequestFlashCallDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartRequestFlashCallDto.json rename to openapi-contracts/src/test/resources/domains/verification/v1/start/request/VerificationStartRequestFlashCallDto.json diff --git a/openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartRequestPhoneCallDto.json b/openapi-contracts/src/test/resources/domains/verification/v1/start/request/VerificationStartRequestPhoneCallDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartRequestPhoneCallDto.json rename to openapi-contracts/src/test/resources/domains/verification/v1/start/request/VerificationStartRequestPhoneCallDto.json diff --git a/openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartRequestSmsDto.json b/openapi-contracts/src/test/resources/domains/verification/v1/start/request/VerificationStartRequestSmsDto.json similarity index 72% rename from openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartRequestSmsDto.json rename to openapi-contracts/src/test/resources/domains/verification/v1/start/request/VerificationStartRequestSmsDto.json index fbf5c3a97..b29236752 100644 --- a/openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartRequestSmsDto.json +++ b/openapi-contracts/src/test/resources/domains/verification/v1/start/request/VerificationStartRequestSmsDto.json @@ -9,6 +9,7 @@ "smsOptions": { "expiry": "01:02:03", "codeType": "Alphanumeric", - "template": "My template require to use '{{CODE}}' code" + "template": "My template require to use '{{CODE}}' code", + "my key": "my value" } } diff --git a/openapi-contracts/src/test/resources/domains/verification/v1/start/request/internal/VerificationStartSmsOptionsDto.json b/openapi-contracts/src/test/resources/domains/verification/v1/start/request/internal/VerificationStartSmsOptionsDto.json new file mode 100644 index 000000000..d1b25f7f1 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/verification/v1/start/request/internal/VerificationStartSmsOptionsDto.json @@ -0,0 +1,5 @@ +{ + "expiry": "01:02:03", + "codeType": "Alphanumeric", + "template": "My template require to use '{{CODE}}' code" +} \ No newline at end of file diff --git a/openapi-contracts/src/test/resources/domains/verification/v1/start/request/internal/VerificationStartSmsOptionsWithAdditionalPropertiesDto.json b/openapi-contracts/src/test/resources/domains/verification/v1/start/request/internal/VerificationStartSmsOptionsWithAdditionalPropertiesDto.json new file mode 100644 index 000000000..a2b47822b --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/verification/v1/start/request/internal/VerificationStartSmsOptionsWithAdditionalPropertiesDto.json @@ -0,0 +1,7 @@ +{ + "expiry": "01:02:03", + "codeType": "Alphanumeric", + "template": "My template require to use '{{CODE}}' code", + "a key": "a value", + "secondKey": "second value" +} diff --git a/openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartResponseDataDto.json b/openapi-contracts/src/test/resources/domains/verification/v1/start/response/VerificationStartResponseDataDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartResponseDataDto.json rename to openapi-contracts/src/test/resources/domains/verification/v1/start/response/VerificationStartResponseDataDto.json diff --git a/openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartResponseFlashCallDto.json b/openapi-contracts/src/test/resources/domains/verification/v1/start/response/VerificationStartResponseFlashCallDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartResponseFlashCallDto.json rename to openapi-contracts/src/test/resources/domains/verification/v1/start/response/VerificationStartResponseFlashCallDto.json diff --git a/openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartResponsePhoneCallDto.json b/openapi-contracts/src/test/resources/domains/verification/v1/start/response/VerificationStartResponsePhoneCallDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartResponsePhoneCallDto.json rename to openapi-contracts/src/test/resources/domains/verification/v1/start/response/VerificationStartResponsePhoneCallDto.json diff --git a/openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartResponseSmsDto.json b/openapi-contracts/src/test/resources/domains/verification/v1/start/response/VerificationStartResponseSmsDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/verification/v1/start/VerificationStartResponseSmsDto.json rename to openapi-contracts/src/test/resources/domains/verification/v1/start/response/VerificationStartResponseSmsDto.json diff --git a/sample-app/src/main/java/com/sinch/sample/webhooks/verification/VerificationService.java b/sample-app/src/main/java/com/sinch/sample/webhooks/verification/VerificationService.java index e1b7f54ff..fec48f05f 100644 --- a/sample-app/src/main/java/com/sinch/sample/webhooks/verification/VerificationService.java +++ b/sample-app/src/main/java/com/sinch/sample/webhooks/verification/VerificationService.java @@ -27,7 +27,7 @@ public VerificationRequestEventResponse verificationEvent(VerificationRequestEve var method = event.getMethod(); if (MethodEnum.SMS.equals(method)) { - builder = VerificationRequestEventResponseSms.builder().setCode("1234"); + builder = VerificationRequestEventResponseSms.builder(); } else if (MethodEnum.FLASH_CALL.equals(method)) { builder = VerificationRequestEventResponseFlashCall.builder().setDialTimeout(12); } else if (MethodEnum.PHONE_CALL.equals(method)) {