Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix generateAliasAsModels in the default generator #3951

Merged
merged 1 commit into from
Sep 26, 2019
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 @@ -35,6 +35,7 @@
import org.openapitools.codegen.config.GlobalSettings;
import org.openapitools.codegen.api.TemplatingEngineAdapter;
import org.openapitools.codegen.ignore.CodegenIgnoreProcessor;
import org.openapitools.codegen.languages.PythonClientExperimentalCodegen;
import org.openapitools.codegen.meta.GeneratorMetadata;
import org.openapitools.codegen.meta.Stability;
import org.openapitools.codegen.serializer.SerializerUtils;
Expand Down Expand Up @@ -492,7 +493,9 @@ private Model getParent(Model model) {
Map<String, Object> modelTemplate = (Map<String, Object>) ((List<Object>) models.get("models")).get(0);
if (modelTemplate != null && modelTemplate.containsKey("model")) {
CodegenModel m = (CodegenModel) modelTemplate.get("model");
if (m.isAlias && !ModelUtils.isGenerateAliasAsModel()) {
if (m.isAlias && !(config instanceof PythonClientExperimentalCodegen)) {
// alias to number, string, enum, etc, which should not be generated as model
// for PythonClientExperimentalCodegen, all aliases are generated as models
continue; // Don't create user-defined classes for aliases
}
}
Expand Down Expand Up @@ -942,7 +945,6 @@ public String getFullTemplateContents(String templateName) {
* Returns the path of a template, allowing access to the template where consuming literal contents aren't desirable or possible.
*
* @param name the template name (e.g. model.mustache)
*
* @return The {@link Path} to the template
*/
@Override
Expand Down Expand Up @@ -1062,21 +1064,21 @@ private void processOperation(String resourcePath, String httpMethod, Operation
if (authMethods != null && !authMethods.isEmpty()) {
codegenOperation.authMethods = config.fromSecurity(authMethods);
List<Map<String, Object>> scopes = new ArrayList<Map<String, Object>>();
if (codegenOperation.authMethods != null){
for (CodegenSecurity security : codegenOperation.authMethods){
if (codegenOperation.authMethods != null) {
for (CodegenSecurity security : codegenOperation.authMethods) {
if (security != null && security.isBasicBearer != null && security.isBasicBearer &&
securities != null){
for (SecurityRequirement req : securities){
securities != null) {
for (SecurityRequirement req : securities) {
if (req == null) continue;
for (String key : req.keySet()){
if (security.name != null && key.equals(security.name)){
for (String key : req.keySet()) {
if (security.name != null && key.equals(security.name)) {
int count = 0;
for (String sc : req.get(key)){
for (String sc : req.get(key)) {
Map<String, Object> scope = new HashMap<String, Object>();
scope.put("scope", sc);
scope.put("description", "");
count++;
if (req.get(key) != null && count < req.get(key).size()){
if (req.get(key) != null && count < req.get(key).size()) {
scope.put("hasMore", "true");
} else {
scope.put("hasMore", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ public void processOpts() {

// default this to true so the python ModelSimple models will be generated
ModelUtils.setGenerateAliasAsModel(true);
if (additionalProperties.containsKey(CodegenConstants.GENERATE_ALIAS_AS_MODEL)) {
LOGGER.info(CodegenConstants.GENERATE_ALIAS_AS_MODEL + " is hard coded to true in this generator. Alias models will only be generated if they contain validations or enums");
}

LOGGER.info(CodegenConstants.GENERATE_ALIAS_AS_MODEL + " is hard coded to true in this generator. Alias models will only be generated if they contain validations or enums");
}

/**
Expand All @@ -108,6 +105,7 @@ public String dateToString(Schema p, Date date, DateFormat dateFormatter, DateFo

/**
* Return the default value of the property
*
* @param p OpenAPI property object
* @return string presentation of the default value of the property
*/
Expand Down Expand Up @@ -194,7 +192,7 @@ public String toDefaultValue(Schema p) {
}
return defaultValue;
} else {
return defaultObject.toString();
return defaultObject.toString();
}
}

Expand Down Expand Up @@ -387,7 +385,7 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
} else {
if (cp.isEnum == true || cp.hasValidation == true) {
// this model has validations and/or enums so we will generate it
Schema sc = ModelUtils.getSchemaFromResponse(response);
Schema sc = ModelUtils.getSchemaFromResponse(response);
newBaseType = ModelUtils.getSimpleRef(sc.get$ref());
}
}
Expand All @@ -406,9 +404,9 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
/**
* Set op's returnBaseType, returnType, examples etc.
*
* @param operation endpoint Operation
* @param schemas a map of the schemas in the openapi spec
* @param op endpoint CodegenOperation
* @param operation endpoint Operation
* @param schemas a map of the schemas in the openapi spec
* @param op endpoint CodegenOperation
* @param methodResponse the default ApiResponse for the endpoint
*/
@Override
Expand Down Expand Up @@ -568,7 +566,7 @@ public CodegenModel fromModel(String name, Schema schema) {

// fix all property references to non-object models, make those properties non-primitive and
// set their dataType and complexType to the model name, so documentation will refer to the correct model
ArrayList<List<CodegenProperty>> listOfLists= new ArrayList<List<CodegenProperty>>();
ArrayList<List<CodegenProperty>> listOfLists = new ArrayList<List<CodegenProperty>>();
listOfLists.add(result.vars);
listOfLists.add(result.allVars);
listOfLists.add(result.requiredVars);
Expand Down