Skip to content
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

chore: ignored error response in java and c# #620

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions src/main/java/com/twilio/oai/StringHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,20 @@ private String convertFirstChar(final String inputWord, final UnaryOperator<Stri
? inputWord
: firstCharFunction.apply(inputWord.substring(0, 1)) + inputWord.substring(1);
}

public static boolean isSuccess(String responseCode) {
// Check if responseCode matches the success pattern for 2xx or 3xx
if (responseCode.matches("^[23](\\d{2}|x[0-9]|[0-9]x|xx)$")) {
return true;
}

// Check if the response code is an integer between 200 and 399
try {
int code = Integer.parseInt(responseCode);
return (code >= 200 && code <= 399);
} catch (NumberFormatException e) {
// Handle case where responseCode is not a valid integer
return false;
}
}
}
26 changes: 14 additions & 12 deletions src/main/java/com/twilio/oai/api/CsharpApiResourceBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,20 @@ private List<CodegenParameter> getNonPathParams(List<CodegenParameter> allParams
public ApiResourceBuilder updateResponseModel(Resolver<CodegenProperty> codegenPropertyIResolver, Resolver<CodegenModel> codegenModelResolver) {
List<CodegenModel> responseModels = new ArrayList<>();
codegenOperationList.forEach(codegenOperation -> {
codegenOperation.responses.forEach(response -> {
String modelName = response.dataType;
if (response.dataType != null && response.dataType.startsWith(EnumConstants.CsharpDataTypes.LIST.getValue())){
modelName = response.baseType;
}
Optional<CodegenModel> responseModel = Utility.getModel(allModels, modelName, recordKey, codegenOperation);
if ((responseModel == null) || responseModel.isEmpty() || (Integer.parseInt(response.code) >= 400)) {
return;
}
codegenModelResolver.resolve(responseModel.get(), this);
responseModels.add(responseModel.get());
});
codegenOperation.responses.stream()
.filter(response -> StringHelper.isSuccess(response.code.trim()))
.forEach(response -> {
String modelName = response.dataType;
if (response.dataType != null && response.dataType.startsWith(EnumConstants.CsharpDataTypes.LIST.getValue())){
modelName = response.baseType;
}
Optional<CodegenModel> responseModel = Utility.getModel(allModels, modelName, recordKey, codegenOperation);
if ((responseModel == null) || responseModel.isEmpty() || (Integer.parseInt(response.code) >= 400)) {
return;
}
codegenModelResolver.resolve(responseModel.get(), this);
responseModels.add(responseModel.get());
});
});
this.apiResponseModels = getDistinctResponseModel(responseModels);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public ApiResourceBuilder updateResponseModel(Resolver<CodegenProperty> codegenP
jsonRequestBodyResolver.setResourceName(resourceName);
co.responses
.stream()
.filter(response -> SUCCESS.test(Integer.parseInt(response.code.trim())))
.filter(response -> StringHelper.isSuccess(response.code.trim()))
.map(response -> {
if (response.dataType != null && response.dataType.startsWith(EnumConstants.JavaDataTypes.LIST.getValue())) {
return response.baseType;
Expand Down
Loading