Data Source

Data source is the source of data for the project.

What is a data source?

  • A data source is a custom JSON object that can be later referenced in templates to generate dynamic code.
  • It allows users to define entities and their fields, which can be used to generate code based on the data source.

Data Source Key

  • Users can add multiple data sources to a project.
  • A data source key references a data source object.

Entities

  • Multiple entities can be added in a single data source.
  • This entities will be turned into array of objects.

name is a compulsory field in an entitity. So users will be able to select the entity while generating code.

Creating a Data Source

  1. Click the [+] button in the project panel and in the dropdown select the Add Data Source option.
  2. Give the key a relevant name as it will be used to reference the data source in templates.

Key can only contain lowercase letters, numbers, underscores and hyphens

Validator

  • You can add a AJV validator to the data source. This ensures that your data source follows a specific schema.

Example

key: schema

// entity user
{
  "name": "User",
  "fields": [
    {
      "name": "name",
      "type": "string"
    }
  ]
}
  • This can be referenced in the templates like this:
{{ .schema.name }}
// will generate
User
  • If you have multiple Data sources. Example: schema and specs.
// schema
{
  "name": "User",
}
// specs
{
  "name": "Post",
}
  • Can be referenced in the templates like this:
{{ .schema.name }}
// will generate
User

{{ .specs.name }}
// will generate
Post

Example AJV Schema

  • AJV schema is similar to openapi schema.
{
  "type": "object", // type of the schema
  "properties": {
    "name": {
      "type": "string" // type of the property
    },
    "fields": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string"
          }
        },
        "required": ["name", "type"]
      }
    }
  },
  "required": ["name"] // required fields
}

On this page