Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions .github/workflows/test-meta-schema.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test schemas

on:
push:
paths:
- "**.json"
- ".github/workflows/test.yml"
- "validate.sh"
pull_request:
paths:
- "**.json"
- ".github/workflows/test.yml"
- "validate.sh"

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install check-jsonschema
run: pip install check-jsonschema

- name: Validate JSON Schemas
run: |
./validate.sh
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# schema-spec
# schemas

This repository contains the specification of the Nextflow schema.
This repository contains the schemas used by Nextflow.

## Schema
The following schemas are currently defined:

The `parameters_meta_schema.json` file describes the structure of the `nextflow_schema.json` file.
- `pipeline-input`: Schema for pipeline input specs
- `plugin`: Schema for plugin specs

Each folder contains the schema (`schema.json`) and a `tests` folder with test cases.

## Development

Expand All @@ -27,12 +30,12 @@ pre-commit run --all-files

This is done automatically when committing.

### Testing the meta-schema
### Testing schemas

The meta-schema can be tested against a set of test schemas located in the `test_schemas` directory using docker and the `validate.sh` script.
Schemas can be tested against their test cases using Docker and the `validate-docker.sh` script.

```bash
./validate.sh
./validate-docker.sh
```

It is automatically tested in GitHub Actions via the `test-meta-schema.yml` workflow.
It is automatically tested in GitHub Actions via the `test.yml` workflow.
6 changes: 3 additions & 3 deletions parameters_meta_schema.json → pipeline-input/schema.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://nextflow.io",
"title": "Nextflow Schema Meta-schema",
"description": "Meta-schema to validate Nextflow parameter schema files",
"$id": "https://raw.githubusercontent.com/nextflow-io/schemas/main/pipeline-input/schema.json",
"title": "Nextflow pipeline input schema",
"description": "Schema to validate Nextflow pipeline input specs",
"type": "object",
"properties": {
"$schema": {
Expand Down
File renamed without changes.
116 changes: 116 additions & 0 deletions plugin/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://raw.githubusercontent.com/nextflow-io/schemas/main/plugin/schema.json",
"title": "Nextflow plugin schema",
"description": "Schema for Nextflow plugin specs",
"type": "object",
"properties": {
"definitions": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/$defs/config_scope"
},
{
"$ref": "#/$defs/function"
}
]
}
}
},
"$defs": {
"config_scope": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["ConfigScope"]
},
"spec": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"children": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/$defs/config_scope"
},
{
"$ref": "#/$defs/config_option"
}
]
}
}
}
}
}
},
"config_option": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["ConfigOption"]
},
"spec": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"type": {
"type": "string"
}
}
}
}
},
"function": {
"type": "object",
"properties": {
"type": {
"enum": ["Factory", "Function", "Operator"]
},
"spec": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"returnType": {
"type": "string"
},
"parameters": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"type": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
36 changes: 36 additions & 0 deletions plugin/tests/valid_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"$schema": "https://raw.githubusercontent.com/nextflow-io/schemas/main/plugin/schema.json",
"definitions": [
{
"type": "ConfigScope",
"spec": {
"name": "hello",
"description": "The `hello` scope controls the behavior of the `nf-hello` plugin.",
"children": [
{
"type": "ConfigOption",
"spec": {
"name": "message",
"description": "Message to print to standard output when the plugin is enabled.",
"type": "String"
}
}
]
}
},
{
"type": "Function",
"spec": {
"name": "sayHello",
"description": "Say hello to the given target",
"returnType": "void",
"parameters": [
{
"name": "target",
"type": "String"
}
]
}
}
]
}
26 changes: 26 additions & 0 deletions validate-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Check if Docker is installed
if ! command -v docker &> /dev/null; then
echo -e "\033[31mError: Docker is not installed\033[0m"
exit 1
fi

# Pull the validator image first
echo -e "\033[36mPulling JSON Schema validator...\033[0m"
if ! docker pull python:3-slim; then
echo -e "\033[31mError: Failed to pull validator image\033[0m"
exit 1
fi

echo -e "\033[36mRunning validation for all test schemas...\033[0m"
echo -e "\033[36m----------------------------------------\033[0m"

# Run validation for all test schemas
echo "Starting validation container..."
docker run -it --rm -v $(pwd):/workspace --workdir /workspace python:3-slim bash -c '
echo "Installing JSON Schema validator..."
pip install check-jsonschema > /dev/null

./validate.sh
'
55 changes: 23 additions & 32 deletions validate.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
#!/bin/bash

# Check if Docker is installed
if ! command -v docker &> /dev/null; then
echo -e "\033[31mError: Docker is not installed\033[0m"
exit 1
fi
for folder in pipeline-input plugin ; do
schema="$folder/schema.json"

# Pull the validator image first
echo -e "\033[36mPulling JSON Schema validator...\033[0m"
if ! docker pull python:3-slim; then
echo -e "\033[31mError: Failed to pull validator image\033[0m"
exit 1
fi
echo "Validating $schema ..."
check-jsonschema --schemafile https://json-schema.org/draft/2020-12/schema "$schema"

echo -e "\033[36mRunning validation for all test schemas...\033[0m"
echo -e "\033[36m----------------------------------------\033[0m"

# Run validation for all test schemas
echo "Starting validation container..."
docker run -it --rm -v $(pwd):/workspace --workdir /workspace python:3-slim bash -c '
echo "Installing JSON Schema validator..."
pip install check-jsonschema > /dev/null

echo "Validating meta-schema..."
check-jsonschema --schemafile https://json-schema.org/draft/2020-12/schema parameters_meta_schema.json

echo -e "\nValidating test schemas..."
echo -e "\nValidating test cases..."
failed=0
for schema in test_schemas/*.json; do
echo "Testing $schema:"
if check-jsonschema --schemafile parameters_meta_schema.json "$schema"; then
printf "\033[32m✓ Valid\033[0m\n"
for spec in $folder/tests/*.json ; do
echo "Testing $spec:"

if check-jsonschema --schemafile "$schema" "$spec"; then
# If $spec doesn't start with "invalid*" then it is a success
if [[ $(basename "$spec") != invalid* ]]; then
echo "✓ Valid"
else
failed=1
fi
else
printf "\033[31m✗ Invalid\033[0m\n"
failed=1
if [[ $(basename "$spec") == invalid* ]]; then
echo "✓ Invalid"
else
failed=1
fi
fi
echo
done
exit $failed
'
done

exit $failed
Loading