Video: Generating Code in RepreZen API Studio

RepreZen API Studio has over 75 code generation templates for Swagger-OpenAPI 2.0, ready to run, and even supports custom code generation.  If you haven't already watched the introductory video, this is the fastest way to understand how code generation works in API Studio:



Step-By-Step: Creating a JSON Schema

API Studio doesn't have a JSON Schema generator for Swagger-OpenAPI 2.0, but the definitions object in OpenAPI is, in most respects, a valid JSON Schema.  With a little hand-editing, you'll have a JSON Schema for your API spec. 


1. Create a new GenTarget, and set the GenTemplate to Swagger [JSON]

With your OpenAPI 2.0 document open in the editor, click the New Generation Target... button on the toolbar, drop-down the GenTemplate list, and choose Swagger [JSON]:

     


This will create a new GenTarget, as a folder in your project.  If you open the Project Explorer view, you can see the new /gentargets/[project_name]/Swagger [JSON] folder. 


That folder contains a .gen configuration file, which should be opened automatically in the editor.


2. Click the "Generate" button in the toolbar. 

This will execute the GenTarget, and create a generated subfolder under the gentarget folder. 




3. Remove everything but the definitions object.

You will need to delete everything but the definitions object, and the root-level object that contains it. The resulting file will serve as a JSON Schema, containing your JSON/YAML data structure definitions. 


Here's a screenshot showing a properly formed JSON Schema, with most of the individual schema definitions collapsed:



4. Validate Your Schema


Note that the OpenAPI 2.0 schema format, called Schema Object in the specification, has some differences from standard JSON Schema. There are some standard JSON Schema features that are not supported by OpenAPI 2.0, and some OpenAPI 2.0 features of its own that are not supported in JSON Schema. 


We recommend that you use a tool like JSON Schema Lint to ensure that your final schema is correct. 


The schema does not have a root-level object, but you can move one of the schemas from definitions to the root object, to validate an instance document against that schema. 

Here, we've moved the Index_Root definition from the definitions object to the top level:



5. Save your Schema to a Safe Location


Finally, we recommend that you move your final schema from the GenTarget directory to a safe location, where it will not be overwritten the next time you run code generation.