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

feat: gen snake_case filenames for golang #106

Merged
merged 2 commits into from
Nov 5, 2020
Merged
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
18 changes: 17 additions & 1 deletion tools/quicktype-wrapper/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ async function getJSONSchemasPaths(directory: string) {
return paths;
}

/**
* Gets a filename from a type (proto message *Data name)
* @param {string} typeName The type, like DocumentEventData
* @param {string} lang The language, like golang
* @returns {string} The filename, like document_event_data
*/
function getFilename(typeName: string, lang: string) {
if (lang === 'GOLANG') {
// Snake case
return typeName.split(/(?=[A-Z])/).join('_').toLowerCase();
} else {
// Pascal case (default)
return typeName;
}
}

/**
* Gets a list of tuples of all JSON schemas and code generated from them
* @param directory The path to the directory with schemas.
Expand Down Expand Up @@ -162,7 +178,7 @@ if (!module.parent) {
await mkdirp(absFilePathDir);

// Write file
const typeFilename = `${typeName}.${LANGUAGE_EXT[L]}`;
const typeFilename = `${getFilename(typeName, L)}.${LANGUAGE_EXT[L]}`;
const absFilePath = `${absFilePathDir}/${typeFilename}`;
writeFileSync(absFilePath, fileContentsMaybeWithLicenseHeader);
bufferedOutput.push(
Expand Down