question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data Resource JSON schema definition for `schema` seems to contradict specification

See original GitHub issue

Overview

Problem description

Caution: there’s a lot of different uses of “schema” coming, so bear with me…

In the JSON schema definition file for a resource, data-resource.json, the formal definition for a schema property of a Resource is:

"schema": {
  "propertyOrder": 40,
  "title": "Schema",
  "description": "A schema for this resource.",
  "type": "object"
},

This allows only JSON-objects as schema definitions, essentially JSON-Strings. It disallows URLs or file paths.

This seemingly contradicts the human-readable specification of a schema property:

The value for the schema property on a resource MUST be an object representing the schema OR a string that identifies the location of the schema.

(Emphasis mine).

Proposed fix

I believe the section should read:

"oneOf": [
    {
      "title": "Schema path",
      "description": "A fully qualified URL, or a POSIX file path..",
      "type": "string"
    },
    {
      "title": "Schema as JSON",
      "description": "A schema encoded as a JSON object",
      "type": "object"
    }
]

I am no specialist for JSON schema, but if I change it, the Java implementation works with schema properties that are URLs and file paths.

How to reproduce

Reproduce the buggy behavior

  • Head to https://www.jsonschemavalidator.net/

  • copy the JSON content from https://frictionlessdata.io/schemas/data-resource.json into the “Schema” field on the left

  • Copy into “Input JSON” on the right the following JSON:

     {
      "name": "test",
      "schema": "https://raw.githubusercontent.com/frictionlessdata/datapackage-java/master/src/test/resources/fixtures/schema/population_schema.json",
      "path": "https://raw.githubusercontent.com/frictionlessdata/datapackage-java/master/src/test/resources/fixtures/data/cities.csv"
     }
    

Result: validation will fail with the following error:

Found 1 error(s) Message: Invalid type. Expected Object but got String. Schema path: #/properties/schema/type

Reproduce the proposed fix

  • Insert the proposed fix into the schema JSON
  • Run validation against the same JSON snippet

Result: no validation error will be shown.

Fix to YAML source

Created a pull request, please check and if working, merge

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lwinfreecommented, Oct 31, 2019

Thanks @iSnow! @rufuspollock + @pwalsh what do you think?

0reactions
krassowskicommented, Jun 17, 2021

Does the path need to be to a JSON file with schema, or schema in a yaml file is good too?

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Media Type for Describing JSON Documents - JSON Schema
JSON Schema is a JSON media type for defining the structure of JSON data. JSON Schema is intended to define validation, documentation, hyperlink...
Read more >
A Media Type for Describing JSON Documents - JSON Schema
JSON Schema is a JSON media type for defining the structure of JSON data. JSON Schema is intended to define validation, documentation, hyperlink ......
Read more >
JSON Schema | The home of JSON Schema
JSON Schema is a declarative language that allows you to annotate and validate JSON documents. JSON Schema enables the confident and reliable use...
Read more >
Structuring a complex schema — Understanding JSON ...
The identifier for the embedded schema is the value of $id resolved against the Base URI of the schema it appears in. A...
Read more >
draft-bhutton-json-schema-00 - IETF Datatracker
JSON Schema is intended to define validation, documentation, hyperlink navigation, and interaction control of JSON data. This specification ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found