Generate Service source code based on a project and a generator
The ol generate command generates the services of a specified project and stores them on your local machine. In most cases, services are created on the OL Hub and not by the CLI ol generate command. However, the command alternative is handy in certain situations, for example, when multiple services have to be created automatically, in bulk, by a script.
The command accepts at least two options --project and --generator. Projects are created and defined on the OL Hub. To learn which projects are available on the OL Hub and can be used as values for the --project option, run the ol list projects command.
A Generator sets the service technology profile. The same service can be executed by different data consumers, each having its programming language, software architecture, application framework, or design patterns. Each data consumer can require the service to be in a different technology profile. For example, the same service can be generated in Java and have a RESTful API by one generator and nodeJS and have AWS Lambda framework by another. Run the ol list generators command to learn which generators are available and can be used as the value for the --generator option.
When executing this command, the CLI fetches the project business field information from the OL-Hub and then uses the selected generator to create the project service files. The command stores the sources in a newly created project directory carrying the project name, ready for compilation and execution.
The ol generate command creates the service with the help of templates. You can customize the service you are generating by modifying those templates. First, run the ol list templates command to review and edit the templates.
You can determine which files will comprise your generated service by specifying to generate the templates to exclude from the service generation process. Use the --skip-all option to not include any template or --skip with the name of a template to skip as a value.
Rules
- The project name has to be identical to the names listed by the ol list projects command.
- The generator name has to be identical to the names listed by the ol list generators command.
Syntax
ol generate [OPTIONS]
Options
--project, -p (required)
The name of the project from which to generate the service (as it appears in the list displayed by the ol list projects).
--project-version, -pv
The project version number (possible values: int >= 0, latest, last, draft)
--generator, -g (required)
The generator's name to be used to generate the service (as it appears in the list displayed by ol list generators).
--deployment, -d
The deployment script type to include inside the generated project:
openshift
The deployment script type to include inside the generated project is OpenShift.
--model, -m
A Free Marker template variable and value. If the variable is included in a custom template, the value will be replacing the variable in the file generated from the template. For example, if the variable name customValue is included in a custom template, then --model customValue="some-value" will result in the string "some-value" replacing the variable name in the file generated from the custom template.
--template, -t
The details of a template are used only in the current run of the ol generate command. The value of the --template option includes the template name and path and the location of the template-based file in the generated service folder. Write the --template value according to this syntax: pathToTemplate=projectTargetPath. For example, d:\tmp\text.ftl=1/1.txt
--templates-path
The destination folder in which to store custom templates
--provider
The source of the service fields metadata:
- hub: The project metadata (contract, method, and field configurations) are read from the OL Hub on service startup.
- opz: The generator downloads the project metadata from the OL Hub and packs it into the OPZ file; see exporting projects to learn more about OPZ files. This option enables services to run without access to the OL Hub.
--cache, -c
Enable caching with the selected cache solution within the generated project:
- redis: Use Redis caching
- hazelcast: Use Hazelcast caching
--license
If the selected --provider is OPZ, download the hub account license file from the hub and include it in the OPZ file.
--connection
If the selected --provider is OPZ, download the project connection properties from the hub and include them in the OPZ file.
--skip-all
Skip all custom templates when generating the service source code.
--skip
Skip the specified custom template(s) when generating the service source code.
--build-tool
Switch between build tools (if supported by generator) [gradle|maven]
Example
Standard usage
> ol generate --generator spring-java-rest-full-code --project project-mf-cics-cobol --skip entity-junit.ftl --skip service-junit.ftl --template d:\tmp\text.ftl 1/1.txt --model customValue=some_value --deployment openshift
$ ol generate --generator spring-java-rest-full-code --project project-mf-cics-cobol --skip entity-junit.ftl --skip service-junit.ftl --template d:\tmp\text.ftl 1/1.txt --model customValue=some_value --deployment openshift