Merge pull request #295 from zrubing/Add-snake-case-property
Add snake case property
This commit is contained in:
commit
2717bf0295
@ -1,5 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
## Unreleased
|
||||
* Option to generate properties with snake_case(#295)
|
||||
|
||||
## 0.4.2
|
||||
|
||||
* Use statement not available on Azure SQL (#243)
|
||||
|
@ -11,7 +11,7 @@ export default interface IGenerationOptions {
|
||||
noConfigs: boolean;
|
||||
convertCaseFile: "pascal" | "param" | "camel" | "none";
|
||||
convertCaseEntity: "pascal" | "camel" | "none";
|
||||
convertCaseProperty: "pascal" | "camel" | "none";
|
||||
convertCaseProperty: "pascal" | "camel" | "snake" | "none";
|
||||
convertEol: "LF" | "CRLF";
|
||||
propertyVisibility: "public" | "protected" | "private" | "none";
|
||||
lazy: boolean;
|
||||
|
@ -212,6 +212,9 @@ function createHandlebarsHelpers(generationOptions: IGenerationOptions): void {
|
||||
case "none":
|
||||
retStr = str;
|
||||
break;
|
||||
case "snake":
|
||||
retStr = changeCase.snakeCase(str);
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unknown case style");
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ function checkYargsParameters(options: options): options {
|
||||
},
|
||||
cp: {
|
||||
alias: "case-property",
|
||||
choices: ["pascal", "camel", "none"],
|
||||
choices: ["pascal", "camel", "snake", "none"],
|
||||
default: options.generationOptions.convertCaseProperty,
|
||||
describe: "Convert property names to specified case",
|
||||
},
|
||||
|
@ -30,6 +30,12 @@ describe("Model customization phase", async () => {
|
||||
options: { name: "name" },
|
||||
tscName: "name",
|
||||
tscType: "string"
|
||||
},
|
||||
{
|
||||
type: "character varying",
|
||||
options: { name: "complicatedName" },
|
||||
tscName: "complexName",
|
||||
tscType: "string"
|
||||
}
|
||||
],
|
||||
indices: [
|
||||
@ -251,6 +257,7 @@ describe("Model customization phase", async () => {
|
||||
.toString();
|
||||
expect(postContent).to.contain("Title: string;");
|
||||
expect(postAuthorContent).to.contain("Posts: Post[];");
|
||||
expect(postAuthorContent).to.contain("ComplexName: string;");
|
||||
|
||||
compileGeneratedModel(generationOptions.resultsPath, [""], false);
|
||||
});
|
||||
@ -279,9 +286,39 @@ describe("Model customization phase", async () => {
|
||||
.toString();
|
||||
expect(postContent).to.contain("title: string;");
|
||||
expect(postAuthorContent).to.contain("posts: Post[];");
|
||||
expect(postAuthorContent).to.contain("complexName: string;");
|
||||
|
||||
compileGeneratedModel(generationOptions.resultsPath, [""]);
|
||||
});
|
||||
it("snake_case", () => {
|
||||
const data = generateSampleData();
|
||||
const generationOptions = generateGenerationOptions();
|
||||
clearGenerationDir();
|
||||
|
||||
generationOptions.convertCaseProperty = "snake";
|
||||
const customizedModel = modelCustomizationPhase(
|
||||
data,
|
||||
generationOptions,
|
||||
{}
|
||||
);
|
||||
modelGenerationPhase(
|
||||
getDefaultConnectionOptions(),
|
||||
generationOptions,
|
||||
customizedModel
|
||||
);
|
||||
const filesGenPath = path.resolve(resultsPath, "entities");
|
||||
const postContent = fs
|
||||
.readFileSync(path.resolve(filesGenPath, "Post.ts"))
|
||||
.toString();
|
||||
const postAuthorContent = fs
|
||||
.readFileSync(path.resolve(filesGenPath, "PostAuthor.ts"))
|
||||
.toString();
|
||||
expect(postContent).to.contain("title: string;");
|
||||
expect(postAuthorContent).to.contain("posts: Post[];");
|
||||
expect(postAuthorContent).to.contain("complex_name: string;");
|
||||
|
||||
compileGeneratedModel(generationOptions.resultsPath, [""],false);
|
||||
});
|
||||
});
|
||||
describe("EOL", async () => {
|
||||
it("LF", () => {
|
||||
|
Loading…
Reference in New Issue
Block a user