Swagger Codegen Generators Configuration
There are different aspects of customizing the code generator beyond just creating or modifying templates. Each language has a supporting configuration file to handle different type mappings, etc:
Each of these files creates reasonable defaults so you can get running quickly. But if you want to configure package names, prefixes, model folders, etc. you can use a json config file to pass the values.
and config.json
contains the following as an example:
Supported config options can be different per language. Running config-help -l {lang}
will show available options.
These options are applied via configuration file (e.g. config.json) or by passing them with java -jar swagger-codegen-cli.jar -D{optionName}={optionValue}
.
If
-D{optionName}
does not work, please open a ticket and we’ll look into it.
Output
Your config file for Java can look like
For all the unspecified options default values will be used.
Another way to override default options is to extend the config class for the specific language.
To change, for example, the prefix for the Objective-C generated files, simply subclass the ObjcClientCodegen.java
:
and specify the classname
when running the generator:
Your subclass will now be loaded and overrides the PREFIX
value in the superclass.
Bringing your own models
Sometimes you don’t want a model generated. In this case, you can simply specify an import mapping to tell the codegen what not to create. When doing this, every location that references a specific model will refer back to your classes. Note, this may not apply to all languages…
To specify an import mapping, use the --import-mappings
argument and specify the model-to-import logic as such:
Or for multiple mappings:
or