data-api-builder icon indicating copy to clipboard operation
data-api-builder copied to clipboard

🥕[Bug]: JSON Schema: Inaccurate Required/Not-Required constraints

Open JerryNixon opened this issue 1 year ago • 1 comments

Discrepancies exist between the official Data API Builder documentation and the JSON schema regarding the required status of certain properties. The documentation is correct and highlights where the schema needs to be adjusted.

Required Properties NOT Required in Schema

  1. data-source.options.database (for cosmosdb_nosql)

    • Docs: Required when database-type is cosmosdb_nosql.
    • Schema: Not marked as required.
  2. data-source.options.schema (for cosmosdb_nosql)

    • Docs: Required when database-type is cosmosdb_nosql.
    • Schema: Not marked as required.
  3. entities.<entity>.source.key-fields

    • Docs: Required only when type is view.
    • Schema: Not conditionally marked as required.
  4. entities.<entity>.permissions

    • Docs: Required for defining access controls for the entity.
    • Schema: Not marked as required.

Not-Required Properties REQUIRED in Schema

  1. runtime.rest.enabled

    • Docs: Optional; defaults to true.
    • Schema: Marked as required.
  2. runtime.graphql.enabled

    • Docs: Optional; defaults to true.
    • Schema: Marked as required.

Suggested Fix

  1. For cosmosdb_nosql Configuration:
{
  "if": {
    "properties": { "database-type": { "const": "cosmosdb_nosql" } }
  },
  "then": {
    "properties": {
      "options": {
        "required": ["database", "schema"]
      }
    }
  }
}
  1. For Entity Definitions:
{
  "patternProperties": {
    "^[a-zA-Z0-9_-]+$": {
      "properties": {
        "source": {
          "properties": {
            "type": { "type": "string" },
            "key-fields": { "type": "array" }
          },
          "required": ["type"],
          "allOf": [
            {
              "if": {
                "properties": { "type": { "const": "view" } }
              },
              "then": { "required": ["key-fields"] }
            }
          ]
        },
        "permissions": { "type": "array" }
      },
      "required": ["source", "permissions"]
    }
  }
}
  1. For Runtime Configuration:
{
  "properties": {
    "runtime": {
      "properties": {
        "rest": {
          "properties": {
            "enabled": { "type": "boolean", "default": true }
          }
        },
        "graphql": {
          "properties": {
            "enabled": { "type": "boolean", "default": true }
          }
        }
      }
    }
  }
}

JerryNixon avatar Jan 13 '25 21:01 JerryNixon

I think dab validate should dynamically be driven from the schema.

JerryNixon avatar Feb 11 '25 23:02 JerryNixon