> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/sast-and-sca/ocular/tutorials/extend-schema.md).

# Extending the Ocular Schema

Ocular ships with a utility called **schema-extender** that allows you to extend any of the default [Code Property Graph schemas](https://github.com/ShiftLeftSecurity/codepropertygraph/tree/master/codepropertygraph/src/main/resources/schemas).

You can define additional nodes, edges, and properties in a specific JSON file, then run schema-extender so that the schema is ready for use in Ocular immediately. The schema-extender is useful for tasks like defining your own passes, and it can be used in conjunction with [an enhanced version of the Code Property Graph Query Language](/sast-and-sca/ocular/enhance-cpgql.md).

## Usage <a href="#usage" id="usage"></a>

1. Add your new schema (in a JSON file) to **schema-extender/schemas**; you can use an existing schema as a template
2. Run `./schema-extender.sh`

The next time you start Ocular, your added nodes, edges, and properties are equal members of the **io.shiftleft.codepropertygraph.generated** package.

## Example: additional `Foo` edge from File -> Method <a href="#example-additional-foo-edge-from-file---method" id="example-additional-foo-edge-from-file---method"></a>

First, navigate into **schema-extender** using `cd schema-extender`.

Create a new file in that directory (e.g., **schemas/foo.json**) with the following contents:

```
{
  "edgeTypes" : [
    {"id" : 9000, "name": "FOO", "comment" : "Foo edge", "keys": []}
  ],

  "nodeTypes" : [
    { "name" : "FILE", "outEdges" : [{"edgeName": "FOO", "inNodes": ["METHOD"]}] }
  ]
}
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

In the terminal, run:

```
./schema-extender.sh
./ocular.sh
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

Finally, open a CPG using `importCode(<path-to-code-directory>)`, and create a **FOO** edge from a file to a method:

```
val file = cpg.file.head
val method = cpg.method.head
file --- "FOO" --> method
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

## Idempotency <a href="#idempotency" id="idempotency"></a>

The schema-enhancer automatically backs up the original jar, which means that you can run the process described above repeatedly.
