openapi-codegen
Version:
OpenAPI 3.0 CodeGen
126 lines (102 loc) • 3.38 kB
Markdown
//raw.githubusercontent.com/Mermade/openapi-codegen/master/schemas/config.json)
```json
{
"type": "documentation",
"defaults": {
"exampleProperty": "exampleValue"
},
"directories": [
"docs"
],
"partials": {
"model": "model.mustache",
"operation": "operation.mustache"
},
"transformations": [
{ "template": "Hello from \{\{projectName\}\}", "output": "README.md" },
{ "input": "index.mustache", "output": "docs/index.html" }
]
}
```
* [Defaults](modelProperties.md)
Lambdas are special tags which invoke a predefined function named after the tag.
The function receives the template fragment between the tags. More info
about lambdas can be found [here](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/templating.md#mustache-lambdas)
We support the following pre-defined lambdas at the moment:
| lambda | example | description |
|------------|----------------------------------------|-----------------------|
| lowercase | \{\{
| uppercase | \{\{
| snakecase | \{\{
| pascalcase | \{\{
| camelcase | \{\{
| kebabcase | \{\{
Some languages have various reserved words or unusual way of formatting arguments.
Sometimes custom lambdas are needed to solve the issues.
A custom generator is simply a javascript module, for example:
```js
const Hogan = require('hogan.js');
const RESERVED_WORDS = new Set([
'for'
]);
function sanitizeName(text) {
return "__"+text+"__"
}
function escapeReservedWord(text) {
return "'"+text+"'"
}
function hello_lambda() {
return function(text) {
return 'Hello ' + Hogan.compile(text).render(this);
}
}
function complex_lambda() {
return function(template) {
var path = Hogan.compile(template).render(this);
path = this.pathParams.reduce(function (acc, param) {
if (param.isPathParam) {
return acc.replace(
"{"+param.paramName+"}", param.paramNamePascalCase);
} else {
return acc.replace()
}
}, path);
return path.split("/").slice(1).join(", ")
}
}
module.exports = {
sanitizeName: sanitizeName,
reservedWords: RESERVED_WORDS,
escapeReservedWord: escapeReservedWord,
lambdas: {
hello: hello_lambda,
path_template: complex_lambda
}
};
```
The module has to be configured in your config under the `generator` property. Here is an example:
```json
{
"defaults": {
"modelNaming": "snake_case",
},
"generator": "../mygenerator.js",
"partials": {
},
"directories": [ "src" ],
"transformations": [
],
"perApi": [
],
"perModel": [
]
}
```
[ ](https: