Skip to content

chore: handle any Type objects correctly #652

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 13 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class ScimName
private string GivenName {get; set;}
[JsonProperty("familyName")]
private string FamilyName {get; set;}
[JsonProperty("TestAnyType")]
private object TestAnyType {get; set;}
public ScimName() { }
public class Builder
{
Expand All @@ -53,6 +55,11 @@ public Builder WithFamilyName(string familyName)
_scimName.FamilyName= familyName;
return this;
}
public Builder WithTestAnyType(object testAnyType)
{
_scimName.TestAnyType= testAnyType;
return this;
}
public ScimName Build()
{
return _scimName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private void addPostParams(final Request request) {

}
}

private void addHeaderParams(final Request request) {
if (xTwilioWebhookEnabled != null) {
request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,5 @@ private void addPostParams(final Request request) {

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,5 @@ private void addPostParams(final Request request) {

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,5 @@ private void addPostParams(final Request request) {

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ private void addPostParams(final Request request) {

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public class NewCredentialsCreator extends Creator<NewCredentials>{
private LocalDate testDate;
private NewCredentials.Status testEnum;
private List<Map<String, Object>> testObjectArray;
private Map<String, Object> testAnyType;
private List<Map<String, Object>> testAnyArray;
private Object testAnyType;
private List<Object> testAnyArray;
private List<NewCredentials.Permissions> permissions;
private String someA2PThing;

Expand Down Expand Up @@ -148,15 +148,15 @@ public NewCredentialsCreator setTestObjectArray(final List<Map<String, Object>>
public NewCredentialsCreator setTestObjectArray(final Map<String, Object> testObjectArray){
return setTestObjectArray(Promoter.listOfOne(testObjectArray));
}
public NewCredentialsCreator setTestAnyType(final Map<String, Object> testAnyType){
public NewCredentialsCreator setTestAnyType(final Object testAnyType){
this.testAnyType = testAnyType;
return this;
}
public NewCredentialsCreator setTestAnyArray(final List<Map<String, Object>> testAnyArray){
public NewCredentialsCreator setTestAnyArray(final List<Object> testAnyArray){
this.testAnyArray = testAnyArray;
return this;
}
public NewCredentialsCreator setTestAnyArray(final Map<String, Object> testAnyArray){
public NewCredentialsCreator setTestAnyArray(final Object testAnyArray){
return setTestAnyArray(Promoter.listOfOne(testAnyArray));
}
public NewCredentialsCreator setPermissions(final List<NewCredentials.Permissions> permissions){
Expand Down Expand Up @@ -253,12 +253,12 @@ private void addPostParams(final Request request) {

}
if (testAnyType != null) {
request.addPostParam("TestAnyType", Converter.mapToJson(testAnyType));
request.addPostParam("TestAnyType", Converter.objectToJson(testAnyType));

}
if (testAnyArray != null) {
for (Map<String, Object> prop : testAnyArray) {
request.addPostParam("TestAnyArray", Converter.mapToJson(prop));
for (Object prop : testAnyArray) {
request.addPostParam("TestAnyArray", prop.toString());
}

}
Expand All @@ -273,4 +273,5 @@ private void addPostParams(final Request request) {

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
public class ApiKeyUpdater extends Updater<ApiKey>{
private String pathSid;
private String friendlyName;
private Map<String, Object> policy;
private Object policy;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test cases when any-type is property and within nested object.


public ApiKeyUpdater(final String pathSid){
this.pathSid = pathSid;
Expand All @@ -61,7 +61,7 @@ public ApiKeyUpdater setFriendlyName(final String friendlyName){
this.friendlyName = friendlyName;
return this;
}
public ApiKeyUpdater setPolicy(final Map<String, Object> policy){
public ApiKeyUpdater setPolicy(final Object policy){
this.policy = policy;
return this;
}
Expand Down Expand Up @@ -99,8 +99,9 @@ private void addPostParams(final Request request) {

}
if (policy != null) {
request.addPostParam("Policy", Converter.mapToJson(policy));
request.addPostParam("Policy", Converter.objectToJson(policy));

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class NewApiKeyCreator extends Creator<NewApiKey>{
private String accountSid;
private String friendlyName;
private NewApiKey.Keytype keyType;
private Map<String, Object> policy;
private Object policy;

public NewApiKeyCreator(final String accountSid) {
this.accountSid = accountSid;
Expand All @@ -75,7 +75,7 @@ public NewApiKeyCreator setKeyType(final NewApiKey.Keytype keyType){
this.keyType = keyType;
return this;
}
public NewApiKeyCreator setPolicy(final Map<String, Object> policy){
public NewApiKeyCreator setPolicy(final Object policy){
this.policy = policy;
return this;
}
Expand Down Expand Up @@ -120,8 +120,9 @@ private void addPostParams(final Request request) {

}
if (policy != null) {
request.addPostParam("Policy", Converter.mapToJson(policy));
request.addPostParam("Policy", Converter.objectToJson(policy));

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,5 @@ private void addPostParams(final NoAuthRequest request) {

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ static public class ScimName {
@JsonProperty("familyName")
@Getter @Setter private String familyName;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("TestAnyType")
@Getter @Setter private Object testAnyType;
public String getTestAnyType() {
return Converter.objectToJson(testAnyType);
}

public static ScimName fromJson(String jsonString, ObjectMapper mapper) throws IOException {
return mapper.readValue(jsonString, ScimName.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,5 @@ private void addPostParams(final NoAuthRequest request) {

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ private void addPostParams(final Request request) {

}
}

}
2 changes: 2 additions & 0 deletions examples/spec/twilio_iam_organizations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,8 @@ components:
minLength: 0
type: string
description: The user's last or family name
TestAnyType:
description: This is any type object
description: User's name
ScimResourceTypes:
type: object
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/com/twilio/oai/resolver/LanguageParamResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
public class LanguageParamResolver extends Resolver<CodegenParameter> {
protected IConventionMapper mapper;
protected CodegenModelResolver codegenModelResolver;
public static final String OBJECT = "object";
private static final String LIST_OBJECT = "List<Object>";

public LanguageParamResolver(IConventionMapper mapper) {
this.mapper = mapper;
Expand Down Expand Up @@ -46,11 +48,19 @@ public CodegenParameter resolve(CodegenParameter codegenParameter, ApiResourceBu
return codegenParameter;
}

protected void handleAnyType(CodegenParameter codegenParameter, ApiResourceBuilder apiResourceBuilder) {
return;
}

protected void resolveProperties(CodegenParameter codegenParameter, ApiResourceBuilder apiResourceBuilder) {
mapper
.properties()
.getString(codegenParameter.dataFormat)
.ifPresent(dataType -> codegenParameter.dataType = dataType);
handleAnyType(codegenParameter, apiResourceBuilder);

if(codegenParameter.vendorExtensions.get("x-is-anytype") == null) {
mapper
.properties()
.getString(codegenParameter.dataFormat)
.ifPresent(dataType -> codegenParameter.dataType = dataType);
}
}

protected void resolveSerialize(CodegenParameter codegenParameter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
@AllArgsConstructor
public class LanguagePropertyResolver extends Resolver<CodegenProperty> {
protected IConventionMapper mapper;


public static final String OBJECT = "object";

@Override
public CodegenProperty resolve(CodegenProperty codegenProperty, ApiResourceBuilder apiResourceBuilder) {
Expand All @@ -33,14 +32,21 @@ public CodegenProperty resolve(CodegenProperty codegenProperty, ApiResourceBuild
return codegenProperty;
}

protected void handleAnyType(CodegenProperty codegenProperty, ApiResourceBuilder apiResourceBuilder) {
return;
}

protected void resolveProperties(CodegenProperty codegenProperty, ApiResourceBuilder apiResourceBuilder) {
mapper
.properties()
.getString(codegenProperty.dataFormat)
.or(() -> mapper.properties().getString(codegenProperty.dataType))
.ifPresent(dataType -> codegenProperty.dataType = dataType);
handleAnyType(codegenProperty, apiResourceBuilder);
if(codegenProperty.vendorExtensions.get("x-is-anytype") == null) {
mapper
.properties()
.getString(codegenProperty.dataFormat)
.or(() -> mapper.properties().getString(codegenProperty.dataType))
.ifPresent(dataType -> codegenProperty.dataType = dataType);
}
}

protected void resolveSerialize(CodegenProperty codegenProperty) {
mapper
.serialize()
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/twilio/oai/resolver/Resolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ protected String getDataType(final CodegenParameter codegenParameter) {
return codegenParameter.dataFormat;
}

if (codegenParameter.isAnyType || codegenParameter.isFreeFormObject) {
if (codegenParameter.isFreeFormObject) {
return OBJECT;
}

if(codegenParameter.isAnyType) {
return "any-type";
}

return codegenParameter.dataType;
}

Expand All @@ -36,10 +40,14 @@ protected String getDataType(final CodegenProperty codegenProperty) {
return codegenProperty.dataFormat;
}

if (codegenProperty.isAnyType || codegenProperty.isFreeFormObject) {
if (codegenProperty.isFreeFormObject) {
return OBJECT;
}

if(codegenProperty.isAnyType) {
return "any-type";
}

return codegenProperty.openApiType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ public CodegenParameter resolve(CodegenParameter parameter, ApiResourceBuilder a
}

private void assignDataType(CodegenParameter parameter) {
mapper
.properties()
.getString(parameter.dataFormat)
.or(() -> mapper.properties().getString(parameter.dataType))
.ifPresent(dataType -> parameter.dataType = dataType);
if(parameter.vendorExtensions.get("x-is-anytype") == null) {
mapper
.properties()
.getString(parameter.dataFormat)
.or(() -> mapper.properties().getString(parameter.dataType))
.ifPresent(dataType -> parameter.dataType = dataType);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,23 @@ public JavaParameterResolver(IConventionMapper mapper) {

@Override
public void resolveProperties(CodegenParameter parameter, ApiResourceBuilder apiResourceBuilder) {
if(parameter.dataType.equalsIgnoreCase(OBJECT) || parameter.dataType.equals(LIST_OBJECT)) {
final String objectType = mapper.properties().getString(OBJECT).orElseThrow();
if((parameter.dataType.equalsIgnoreCase(OBJECT) || parameter.dataType.equals(LIST_OBJECT)) && parameter.vendorExtensions.get("x-is-anytype") == null) {
String objectType = mapper.properties().getString(OBJECT).orElseThrow();

if (parameter.isAnyType || (parameter.isArray && parameter.items.isAnyType)) {
objectType = "Object";
parameter.vendorExtensions.put("x-is-anytype", true);
}

else
parameter.isFreeFormObject = true;

if (parameter.dataType.equals(LIST_OBJECT)) {
parameter.dataType = ApplicationConstants.LIST_START + objectType + ApplicationConstants.LIST_END;
parameter.baseType = objectType;
} else {
parameter.dataType = objectType;
}

parameter.isFreeFormObject = true;
}

mapper.promotions().getMap(parameter.dataFormat).ifPresent(promotions -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.twilio.oai.Segments;
import com.twilio.oai.StringHelper;
import com.twilio.oai.api.ApiResourceBuilder;
import com.twilio.oai.common.ApplicationConstants;
import com.twilio.oai.common.EnumConstants;
import com.twilio.oai.resolver.LanguagePropertyResolver;
import com.twilio.oai.resolver.IConventionMapper;
Expand All @@ -18,6 +19,7 @@
import static com.twilio.oai.common.ApplicationConstants.VENDOR_PREFIX;

public class JavaPropertyResolver extends LanguagePropertyResolver {
private static final String LIST_OBJECT = "List<Object>";
public JavaPropertyResolver(IConventionMapper mapper) {
super(mapper);
}
Expand Down Expand Up @@ -48,6 +50,28 @@ public void resolveProperties(CodegenProperty property, ApiResourceBuilder apiR
}
}

@Override
protected void handleAnyType(CodegenProperty codegenProperty, ApiResourceBuilder apiResourceBuilder) {
if((codegenProperty.dataType.equalsIgnoreCase(OBJECT) || codegenProperty.dataType.equals(LIST_OBJECT)) && codegenProperty.vendorExtensions.get("x-is-anytype") == null) {
String objectType = mapper.properties().getString(OBJECT).orElseThrow();

if (codegenProperty.isAnyType || (codegenProperty.isArray && codegenProperty.items.isAnyType)) {
objectType = "Object";
codegenProperty.vendorExtensions.put("x-is-anytype", true);
}

else
codegenProperty.isFreeFormObject = true;

if (codegenProperty.dataType.equals(LIST_OBJECT)) {
codegenProperty.dataType = ApplicationConstants.LIST_START + objectType + ApplicationConstants.LIST_END;
codegenProperty.baseType = objectType;
} else {
codegenProperty.dataType = objectType;
}
}
}

ConfigurationSegment getMapperByType(Segments segments) {
switch (segments) {
case SEGMENT_PROPERTIES:
Expand Down
Loading
Loading