Skip to content

Validate multiple YAML document structure using JSON Schema with jsonschema #927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sujaypatil96 opened this issue Mar 16, 2022 · 2 comments

Comments

@sujaypatil96
Copy link

sujaypatil96 commented Mar 16, 2022

Is there something wrong I'm doing when I try to validate the following multi YAML object file using its corresponding JSON Schema with the jsonschema validation tool?

File to be validated: instance.yaml

authors: GOA-UniProt curators
id: GO_REF:0000029
is_obsolete: true
year: 2007
layout: goref
title: OBSOLETE Gene Ontology annotation based on information extracted from curated
  UniProtKB entries
comments:
- Active 2001-2007.
- Method by which GO terms were manually assigned to UniProt KnowledgeBase accessions,
  using either a NAS or TAS evidence code, by applying information extracted from
  the corresponding publicly-available, manually curated UniProtKB entry. Such GO
  annotations were submitted by the GOA-UniProt group from 2001, but this annotation
  practice was discontinued in 2007.
---
authors: GO ontology editors
id: GO_REF:0000078
year: 2013
layout: goref
title: Representation for the transport or vesicle-mediated transport of a chemical
  from and/or to a cell component as biological process in the Gene Ontology
comments:
- 'We have created a standard template for classes describing the transport or vesicle-mediated
  transport of a chemical entity (ChEBI) from and/or to a cellular component as a
  biological process. The underlying equivalence axiom templates are "GO:0006810 and
  ''transports or maintains localization of'' some X [ and ''has_target_start_location''
  some F] [ and ''has_target_end_location'' some T]" (transport) and "GO:0016192 and
  ''transports or maintains localization of'' some X [ and ''has_target_start_location''
  some F] [ and ''has_target_end_location'' some T]" (vesicle-mediated transport),
  where F and T are cellular components and X is a chemical entity (CHEBI:24431).
  The approach to combine GO and ChEBI has been described in the following publication:
  PMID:23895341.'

JSON Schema validation file: project.schema.json

{
    "$schema": "http://json-schema.org/draft-07/schema",
    "$id": "https://example.com/gorefs.schema.json",
    "title": "JSON Schema for validating gorefs.yaml",
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "authors": {
                "type": "string",
                "description": ""
            },
            "id": {
                "type": "string",
                "pattern": "GO_REF:\\d{7}",
                "description": ""
            },
            "is_obsolete": {
                "type":"boolean",
                "description": ""
            },
            "year": {
                "type": "integer",
                "description": ""
            },
            "layout": {
                "type": "string",
                "description": ""
            },
            "title": {
                "type": "string",
                "description": ""
            },
            "comments": {
                "type": "array",
                "items": {
                    "type": "string"
                },
                "description": ""
            }
        }
    }
}

Here is my log:

> jsonschema -i instance.yaml project.schema.json
Failed to parse 'instance.yaml': Expecting value: line 1 column 1 (char 0)
@sujaypatil96
Copy link
Author

Looks like the jsonschema library doesn't support validation of YAML files with JSON Schema through the CLI or the library methods.

Should this become a feature request?

@Julian
Copy link
Member

Julian commented Mar 17, 2022

Hi, have a look at check-jsonschema which will become the official CLI and supports additional things (I believe YAML). #910 and #582 have more details.

Or run the YAML through a simple converter like remarshal, i.e. jsonschema -i <(yaml2json foo.yaml) etc.

@Julian Julian closed this as completed Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants