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

fix: reverting the temp fix for go made in #571 #579

Open
wants to merge 2 commits 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
2 changes: 1 addition & 1 deletion examples/go/go-client/helper/rest/flex/v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Class | Method | HTTP request | Description
## Documentation For Models

- [ListCredentialAwsResponse](docs/ListCredentialAwsResponse.md)
- [UpdateCallResponse](docs/UpdateCallResponse.md)
- [UpdateCall200Response](docs/UpdateCall200Response.md)
- [TestResponseObject](docs/TestResponseObject.md)
- [ListCredentialAwsResponseMeta](docs/ListCredentialAwsResponseMeta.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

package openapi

// UpdateCallResponse struct for UpdateCallResponse
type UpdateCallResponse struct {
// UpdateCall200Response struct for UpdateCall200Response
type UpdateCall200Response struct {
// Non-string path parameter in the response.
Sid *int `json:"sid,omitempty"`
}
4 changes: 2 additions & 2 deletions examples/go/go-client/helper/rest/flex/v1/voice.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"strings"
)

func (c *ApiService) UpdateCall(Sid string) (*UpdateCallResponse, error) {
func (c *ApiService) UpdateCall(Sid string) (*UpdateCall200Response, error) {
path := "/v1/Voice/{Sid}"
path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)

Expand All @@ -34,7 +34,7 @@ func (c *ApiService) UpdateCall(Sid string) (*UpdateCallResponse, error) {

defer resp.Body.Close()

ps := &UpdateCallResponse{}
ps := &UpdateCall200Response{}
if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
return nil, err
}
Expand Down
70 changes: 4 additions & 66 deletions src/main/java/com/twilio/oai/TwilioGoGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.twilio.oai.common.Utility;

import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collector;
import java.util.stream.Collectors;

Expand All @@ -20,7 +22,6 @@
import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.model.OperationMap;
import org.openapitools.codegen.model.OperationsMap;
import org.openapitools.codegen.utils.StringUtils;

import static com.twilio.oai.common.ApplicationConstants.STRING;

Expand Down Expand Up @@ -68,68 +69,6 @@ public ModelsMap postProcessModels(final ModelsMap objs) {
return results;
}

boolean containsAllOf(String modelName) {
return modelName.contains("allOf");
}

boolean containsStatusCode(String modelName) {
return Pattern.compile("_\\d{3}_").matcher(modelName).find();
}

String removeStatusCode(String modelName) {
if(modelName == null || modelName.isEmpty())
return modelName;
return modelName.replaceFirst("_\\d{3}", "");
}

String removeDigits(String modelName) {
if(modelName == null || modelName.isEmpty() || modelName.contains("2010"))
return modelName;
return modelName.replaceFirst("\\d{3}", "");
}

String modelNameWithoutStatusCode(String modelName) {
if(modelName == null || modelName.isEmpty())
return modelName;
String newModelName = removeStatusCode(modelName);
if(Objects.equals(newModelName, modelName))
newModelName = removeDigits(newModelName);
return StringUtils.camelize(newModelName);
}

@Override
public Map<String, ModelsMap> updateAllModels(Map<String, ModelsMap> objs) {
objs = super.updateAllModels(objs);

Set<String> modelNames = objs.keySet()
.stream()
.filter(key -> (containsStatusCode(key) || containsAllOf(key)))
.map(this::modelNameWithoutStatusCode)
.collect(Collectors.toSet());

objs.entrySet().removeIf(entry -> containsAllOf(entry.getKey()) || modelNames.contains(entry.getKey()));
Map<String, ModelsMap> updatedObjs = new HashMap<>();

objs.forEach((key, value) -> {
if (containsStatusCode(key)) {
ModelMap modelMap = value.getModels().get(0);
String importPath = (String) modelMap.get("importPath");
CodegenModel model = modelMap.getModel();
key = modelNameWithoutStatusCode(key);
model.setName(modelNameWithoutStatusCode(model.name));
model.setClassname(modelNameWithoutStatusCode(model.classname));
model.setClassVarName(modelNameWithoutStatusCode(model.classVarName));
model.setClassFilename(removeStatusCode(model.classFilename));
modelMap.setModel(model);
modelMap.put("importPath", removeDigits(importPath));
value.put("classname", removeDigits((String) value.get("classname")));
}
updatedObjs.put(key, value);
});

return updatedObjs;
}

@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
super.postProcessModelProperty(model, property);
Expand Down Expand Up @@ -184,7 +123,6 @@ public OperationsMap postProcessOperationsWithModels(final OperationsMap objs, L
for (final CodegenOperation co : opList) {
Utility.populateCrudOperations(co);
Utility.resolveContentType(co);
co.returnType = modelNameWithoutStatusCode(co.returnType);

if (co.nickname.startsWith("List")) {
// make sure the format matches the other methods
Expand Down
Loading