-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
149 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.gradle | ||
node_modules | ||
output | ||
output | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,75 @@ | ||
const filter = module.exports; | ||
const _ = require('lodash'); | ||
|
||
module.exports = ({ Nunjucks }) => { | ||
Nunjucks.addFilter('camelCase', (str) => { | ||
return _.camelCase(str); | ||
}); | ||
|
||
Nunjucks.addFilter('upperFirst', (str) => { | ||
return _.upperFirst(str); | ||
}); | ||
function toJavaType(str){ | ||
switch(str) { | ||
case 'integer': | ||
case 'int32': | ||
return 'int'; | ||
case 'long': | ||
case 'int64': | ||
return 'long'; | ||
case 'boolean': | ||
return 'boolean'; | ||
case 'date': | ||
return 'java.time.LocalDate'; | ||
case 'dateTime': | ||
case 'date-time': | ||
return 'java.time.LocalDateTime'; | ||
case 'string': | ||
case 'password': | ||
case 'byte': | ||
return 'String'; | ||
case 'float': | ||
return 'float'; | ||
case 'double': | ||
return 'double'; | ||
case 'binary': | ||
return 'byte[]'; | ||
default: | ||
return 'Object'; | ||
} | ||
} | ||
filter.toJavaType = toJavaType; | ||
|
||
Nunjucks.addFilter('toJavaType', (str) => { | ||
switch(str) { | ||
case 'integer': | ||
case 'int32': | ||
return 'int'; | ||
case 'long': | ||
case 'int64': | ||
return 'long'; | ||
case 'boolean': | ||
return 'boolean'; | ||
case 'date': | ||
return 'java.time.LocalDate'; | ||
case 'dateTime': | ||
case 'date-time': | ||
return 'java.time.LocalDateTime'; | ||
case 'string': | ||
case 'password': | ||
case 'byte': | ||
return 'String'; | ||
case 'float': | ||
return 'float'; | ||
case 'double': | ||
return 'double'; | ||
case 'binary': | ||
return 'byte[]'; | ||
default: | ||
return 'Object'; | ||
} | ||
}); | ||
|
||
Nunjucks.addFilter('isProtocol', (api, protocol) => { | ||
return JSON.stringify(api.json()).includes('"protocol":"' + protocol + '"'); | ||
}); | ||
|
||
Nunjucks.addFilter('print', (str) => { | ||
console.error(str); | ||
}); | ||
function isProtocol(api, protocol){ | ||
return JSON.stringify(api.json()).includes('"protocol":"' + protocol + '"'); | ||
}; | ||
filter.isProtocol = isProtocol; | ||
|
||
Nunjucks.addFilter('examplesToString', (ex) => { | ||
let retStr = ""; | ||
ex.forEach(example => { | ||
if (retStr !== "") {retStr += ", "} | ||
if (typeof example == "object") { | ||
try { | ||
retStr += JSON.stringify(example); | ||
} catch (ignore) { | ||
retStr += example; | ||
} | ||
} else { | ||
function examplesToString(ex){ | ||
let retStr = ""; | ||
ex.forEach(example => { | ||
if (retStr !== "") {retStr += ", "} | ||
if (typeof example == "object") { | ||
try { | ||
retStr += JSON.stringify(example); | ||
} catch (ignore) { | ||
retStr += example; | ||
} | ||
}); | ||
return retStr; | ||
}); | ||
|
||
Nunjucks.addFilter('splitByLines', (str) => { | ||
if (str) { | ||
return str.split(/\r?\n|\r/).filter((s) => s !== ""); | ||
} else { | ||
return ""; | ||
retStr += example; | ||
} | ||
}); | ||
return retStr; | ||
}; | ||
filter.examplesToString = examplesToString; | ||
|
||
Nunjucks.addFilter('isRequired', (name, list) => { | ||
return list && list.includes(name); | ||
}); | ||
function splitByLines(str){ | ||
if (str) { | ||
return str.split(/\r?\n|\r/).filter((s) => s !== ""); | ||
} else { | ||
return ""; | ||
} | ||
}; | ||
filter.splitByLines = splitByLines; | ||
|
||
Nunjucks.addFilter('schemeExists', (collection, scheme) => { | ||
return _.some(collection, {'scheme': scheme}); | ||
}); | ||
function isRequired(name, list){ | ||
return list && list.includes(name); | ||
}; | ||
filter.isRequired = isRequired; | ||
|
||
function schemeExists(collection, scheme){ | ||
return _.some(collection, {'scheme': scheme}); | ||
}; | ||
filter.schemeExists = schemeExists; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters