Skip to content

Implementing your own suppliers

Esta Nagy edited this page Jul 1, 2020 · 3 revisions

Suppliers are really like magic: seemingly they can create things from thin air but there is always a parameter behind this neat trick.

To implement a new supplier, you just need to spend a few minutes on doing the following simple steps:

  1. Create a class for your supplier implementing the Supplier interface
  2. Create a constructor using only the supported parameter types as parameters
  3. Annotate your constructor with @NamedSupplier
  4. Annotate all of your constructor parameters as defined here
  5. Implement the get() method defined by the interface.
  6. Register your supplier using FunctionRegistry#registerSupplierClass(Class)
  7. Make sure to add your supplier to the #/definitions/supplierTypes/definitions node of our JSON Schema
    1. Add a new definition similarly to the examples already in there
    2. Register the type supplier to the definition of the anySupplier definition by
      1. Adding the name to the enum containing all the names
      2. Adding a new object to the list similar to this:
          {
            "if": {
              "properties": {
                "name": {
                  "const": "staticString"
                }
              }
            },
            "then": {
              "$ref": "#/definitions/supplierTypes/definitions/supplierStaticString"
            }
          }
  8. ...and we are done, you can go play with your new supplier!