Skip to content

JSON Data Resources recipe conflicts with Data Resource schema #1146

@rmx90210

Description

@rmx90210

What Data Package version are you using?

v2

Describe the Issue

The JSON Data Resources recipe states:

The Data Resource schema property MUST follow the JSON Schema specification

However, the Data Resource validation schema unconditionally requires a fields property when a schema object is present:

"schema": {
  "title": "Table Schema",
  "type": ["string", "object"],
  "required": ["fields"],
  "properties": {
    "$schema": {
      "default": "https://datapackage.org/profiles/1.0/tableschema.json"
    },
    "fields": {
      "type": "array",
      "minItems": 1
    }
  }
}

The fields property is a Table Schema concept and does not exist in JSON Schema. This means it's impossible to follow the JSON Data Resources recipe and pass validation against the Data Resource schema at the same time.

I noticed that the inner $schema property uses "default" (not "const" or "enum"), which suggests Table Schema is intended to be the default schema format, not the only one. But the hard "required": ["fields"] constraint makes it the only format that validates.

Steps to Reproduce

  1. Create a datapackage.json with "$schema": "https://datapackage.org/profiles/2.0/datapackage.json"
  2. Add a resource following the JSON Data Resources recipe, with a schema property containing a valid JSON Schema object (no fields property)
  3. Validate the file (e.g. VS Code's built-in JSON schema validation, or any JSON Schema validator)
  4. You should see Missing property "fields"

Expected Behavior

Resources using JSON Schema (per the JSON Data Resources recipe) should validate without requiring a fields property.

Current Workaround

There is no clean workaround. Removing the profile property from resources does not help — the required: ["fields"] constraint is on the schema object itself, not conditional on profile. The only way to suppress the error is to remove the top-level $schema reference from datapackage.json, which disables all editor validation.

Suggested Fix

Update the Data Resource validation schema so that fields is only required when the schema is a Table Schema (e.g. using if/then based on the inner $schema value, or by making fields optional and relying on the Table Schema profile to enforce it).

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions