RepreZen API Studio provides an extensive collection of GenTemplates for OpenAPI, and a smaller set of GenTemplates for RAPID-ML. You can make use of the Swagger-OpenAPI GenTemplates from your RAPID-ML model, using a 2-stage transformation, as described in this article. 


Stage 1: RAPID-ML --> Swagger (RAPID-XChange Contract)


The first-stage GenTarget takes your source RAPID-ML model as the input , and generates a Swagger-OpenAPI 2.0 document. At this time, the Swagger (RAPID-XChange Contract) GenTemplate provides the most complete mapping from RAPID-ML to OpenAPI 2.0. 


Configure the GenTarget as follows:

  1. Open the source RAPID-ML file in the editor.
     
  2. Click the New GenTarget button in the toolbar, or use the corresponding command from the dashboard.
     
  3. In the GenTemplate drop-down list, choose Swagger (RAPID-XChange Contract), and click Finish.
     
  4. The .gen configuration file will be open, and the code generation button in the toolbar will show this GenTarget as the default. Click the button to run the code generator, and this will create an OpenAPI 2.0 document in the generated subfolder, in JSON and YAML formats.


Stage 2: Swagger --> Target GenTemplate


The second-stage GenTarget will take the generated OpenAPI 2.0 document as input, and use one of the available GenTemplates to create the target output.

  1. Open the generated OpenAPI 2.0 YAML file from the first-stage GenTarget.
     
  2. Click the New GenTarget button in the toolbar, or use the corresponding command from the dashboard.
     
  3. In the GenTemplate drop-down list, choose the target GenTemplate you want to use, and click Finish.
     
  4. The .gen configuration file will be open, and the code generation button in the toolbar will show this GenTarget as the default. Click the button to run the code generator, and this will create the target output in the generated subfolder.


Create a dependency chain between the two GenTargets


Now that you've created both GenTargets, you can run them in sequence to generate the required output. But we can make this easier by declaring the first-stage GenTarget as a prerequisite for the second-stage GenTarget. This creates a dependency chain, so that executing the Stage 2 GenTarget will automatically run the Stage 1 GenTarget first.

  1. Open the .gen configuration file in second-stage GenTarget.
     
  2. Find the prerequisites key, which has no assigned value by default.  Add the highlighted lines:
---
name: "Java Client"
genTemplateId: "com.modelsolv.reprezen.gentemplates.swagger.codegen.JavaClientCodegen"
relativeOutputDir: generated
prerequisites:
- name: "rxcGenerator"
  genFilePath: "../Swagger (RAPID-XChange Contract)/Swagger (RAPID-XChange Contract).gen"
primarySource:
  path: "../Swagger (RAPID-XChange Contract)/generated/TaxBlaster.yaml"

The genFilePath property is a relative path to the .gen configuration file of the first-stage GenTarget.  If you created your first-stage GenTarget in a different location, or with a different name, you'll need to correct the path. 


You can delete the generated subfolder from the first-stage GenTarget, then run the second-stage GenTarget to verify that the two stages automatically execute in the proper sequence. 


Running the Two-Stage Transformation


When you have the source RAPID-ML model open, the list of available GenTargets in the toolbar is filtered to show only the GenTargets that use that RAPID-Model as the primary source. This won't include your second-stage GenTarget, because that one uses the generated OpenAPI 2.0 document as the primary source. 


To run the second-stage GenTarget, open the Project Explorer view, and select any folder that includes the second-stage GenTarget. Any of these folders will work:

  1. The project root folder.
  2. The /gentargets folder
  3. The /gentargets/<SourceModel> folder that contains your second-stage GenTarget folder. 
  4. The second-stage GenTarget folder, or any file within it.

Once you have selected one of these folders, drop-down the code generation menu, and select the second-stage GenTarget to run it. 


Note that is selection is "sticky," so it will be selected by default whenever you select that same folder in Project Explorer. Subsequently, you only need to click the generate button in the toolbar; you don't need to drop down the menu.