Code Assistant

The Code Assistant

The DocDriven Code Assistant is a tool designed to help developers generate code automatically based on the examples provided in a repository, adhering to custom code conventions.

This guide will walk you through the steps to set up and use the Code Assistant to generate code for your API designs.

Starting the Code Assistant

To get started, open the Assistant by navigating to the “Code Assistant" tab from the Project Details interface. You will find an introductory screen with a button labeled "Start the assistant". Click on this button to begin the setup process.

Select a Repository with Code Examples

In the "Select a repository with the code examples to follow" section, you need to select the repository that contains the code examples you want the Code Assistant to follow. First, select the name of the GitHub repository. Then, select the branch that contains the code examples.

Valid docdriven.config.json Documentation

In order for the Code Assistant to work, it requires a valid docdriven.config.json file at the root of the repository. This file contains a set of instructions (templates) that the assistant follows when generating code. Below is a detailed description of what a valid docdriven.config.json should look like and the properties it must include.

Required Properties

Each template in the docdriven.config.json file must include the following properties:

  • name: A human-readable name for the template. This can be anything and is used for display purposes only.
  • example: A relative path to an example file that the Code Assistant should reference when generating the new file. The example file should be similar in design to the file that the Assistant will generate.
  • outputDirectory: The path where the generated file should be placed. This path is relative to the root of the repository.
  • target: The type of data the Code Assistant will work with to generate the file. This can be either "Endpoints" or "Schemas". If the Assistant is generating a file that contains API endpoints, the target should be "Endpoints". If the Assistant is generating a file that contains data models, the target should be "Schemas".


Here is an example of what a valid docdriven.config.json file looks like. This example is from a .NET repository that codes Controllers for an API project:

    "templates": [
            "name": ".NET Controller",
            "example": "examples/dotnet/PetController.cs",
            "outputDirectory": "API/Controllers",
            "target": "Endpoints"

Properties Breakdown

  1. name: The template has a name ".NET Controller".
  2. example: The Code Assistant will reference the example file located at examples/dotnet/PetController.cs when generating new files.
  3. outputDirectory: The generated file will be placed in the API/Controllers directory.
  4. target: The target type is "Endpoints" because this template is for generating API endpoints.

Now that you know what a valid docdriven.config.json file should look like, you can create one in the root of your repository. After creating and adding this file, you can refresh the Code Assistant interface and continue with the code generation process.

Assign Work to the Code Assistant

In the "Assign work to the code assistant" section, you will specify the type of work you want the assistant to perform. The tool will look for a valid docdriven.config.json file in your repository. For each task, select the type of work from the dropdown menu. Then, specify the groups or areas within your codebase where the work should be focused. If you have additional tasks, click on the "+ Add additional work" button to add more items and specify their details.

Output Settings

In the "Output" section, decide what you want to do with the generated code. You can choose to create a pull request, which is suggested as it allows you to review changes before merging, commit to the same branch you selected initially, or commit the generated code to a different branch or repository. After making your selection, click the "Run code assistant" button to initiate the code generation process.

Monitoring Progress

To monitor the progress and check logs of the code generation process for any issues or confirmations of completion, navigate to the "Log" tab.

The DocDriven Code Assistant simplifies the process of generating code by following your specific code conventions and examples. By following the steps outlined in this guide, you can efficiently set up and use the tool to accelerate your development process.