Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move model related SQLs into Model folder
  • Loading branch information
ybelenko committed Apr 11, 2020
commit c0e4131b6e951213ecfb7f6151880bc5be912260
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
import org.openapitools.codegen.meta.features.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.lang3.StringUtils;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.File;

import static org.openapitools.codegen.utils.StringUtils.underscore;

Expand Down Expand Up @@ -83,6 +85,7 @@ public MysqlSchemaCodegen() {
// clear import mapping (from default generator) as mysql does not use import directives
importMapping.clear();

setModelPackage("Model");
modelTemplateFiles.put("sql_query.mustache", ".sql");
//modelTestTemplateFiles.put("model_test.mustache", ".php");
// no doc files
Expand Down Expand Up @@ -240,6 +243,9 @@ public void processOpts() {
this.setIdentifierNamingConvention((String) additionalProperties.get(IDENTIFIER_NAMING_CONVENTION));
}

// make model src path available in mustache template
additionalProperties.put("modelSrcPath", "./" + toSrcPath(modelPackage));

supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("mysql_schema.mustache", "", "mysql_schema.sql"));
}
Expand Down Expand Up @@ -1212,4 +1218,22 @@ public String getIdentifierNamingConvention() {
return this.identifierNamingConvention;
}

/**
* Slightly modified version of AbstractPhpCodegen.toSrcPath method.
*
* @param packageName package name
*
* @return path
*/
public String toSrcPath(String packageName) {
// Trim prefix file separators from package path
String packagePath = StringUtils.removeStart(
// Replace period, backslash, forward slash with file separator in package name
packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement("/")),
File.separator
);

// Trim trailing file separators from the overall path
return StringUtils.removeEnd(packagePath, File.separator);
}
}