Skip to content

Commit 2852d54

Browse files
committed
Allow extra properties
Quick vibe code to close #6
1 parent 6b06a21 commit 2852d54

File tree

3 files changed

+95
-2
lines changed

3 files changed

+95
-2
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ jobs:
1919
uses: actions/checkout@v4
2020

2121
- name: 🛡️ Validate Zenodo Metadata
22-
uses: vsoch/zenodo-validator@main
22+
uses: vsoch/zenodo-validator@main
2323
with:
2424
path: '.zenodo.json'
25+
allowed_extra_properties: 'pub_id' # Optional: allow extra properties
2526
```
2627
2728
@@ -42,6 +43,7 @@ docker run --rm \
4243
-e INPUT_PATH=.zenodo.json \
4344
-e INPUT_SCHEMA_PATH=/schema.json \
4445
-e INPUT_ERROR_FORMAT=text \
46+
-e INPUT_ALLOWED_EXTRA_PROPERTIES=pub_id \
4547
zenodo-validator
4648
```
4749

@@ -60,6 +62,21 @@ And you can also use the image provided: `ghcr.io/vsoch/zenodo-validator`.
6062
| :--- | :--- | :--- |
6163
| `path` 📍 | Where is your `.zenodo.json`? | `.zenodo.json` |
6264
| `error_format` 🎨 | `text`, `json`, or `pretty-json` | `text` |
65+
| `allowed_extra_properties`| Comma-separated list of extra property names to allow (e.g., `pub_id,custom_field`) | `''` (empty) |
66+
67+
### 🔓 Allowing Extra Properties
68+
69+
Some Invenio instances (like [RODARE](https://rodare.hzdr.de)) require additional properties beyond the standard Zenodo schema. You can explicitly allow these properties using the `allowed_extra_properties` input:
70+
71+
```yaml
72+
- name: 🛡️ Validate Zenodo Metadata
73+
uses: vsoch/zenodo-validator@main
74+
with:
75+
path: '.rodare.json'
76+
allowed_extra_properties: 'pub_id'
77+
```
78+
79+
This will allow the specified properties while still validating all other fields against the Zenodo schema. Multiple properties can be specified as a comma-separated list: `'pub_id,custom_field,another_field'`.
6380
6481
---
6582

action.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ inputs:
1313
description: 'Output format (text, json, pretty-json)'
1414
required: false
1515
default: 'text'
16+
allowed_extra_properties:
17+
description: 'Comma-separated list of extra property names to allow (e.g., "pub_id,custom_field")'
18+
required: false
19+
default: ''
1620

1721
runs:
1822
using: 'docker'
@@ -21,3 +25,4 @@ runs:
2125
INPUT_PATH: ${{ inputs.path }}
2226
INPUT_SCHEMA_PATH: ${{ inputs.schema_path }}
2327
INPUT_ERROR_FORMAT: ${{ inputs.error_format }}
28+
INPUT_ALLOWED_EXTRA_PROPERTIES: ${{ inputs.allowed_extra_properties }}

docker/entrypoint.sh

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,81 @@ fi
2222
echo "🔮 Summoning the JSON spirits to check your work..."
2323
echo "📜 Using Schema: $SCHEMA_PATH"
2424
echo "🎨 Output Format: $INPUT_ERROR_FORMAT"
25+
26+
# Handle allowed extra properties
27+
FINAL_SCHEMA_PATH="$SCHEMA_PATH"
28+
if [ -n "$INPUT_ALLOWED_EXTRA_PROPERTIES" ]; then
29+
echo "✨ Allowing extra properties: $INPUT_ALLOWED_EXTRA_PROPERTIES"
30+
FINAL_SCHEMA_PATH="/tmp/modified_schema.json"
31+
32+
# Use Python to modify the schema and add allowed extra properties
33+
if ! SCHEMA_PATH_ESC="$SCHEMA_PATH" \
34+
FINAL_SCHEMA_PATH_ESC="$FINAL_SCHEMA_PATH" \
35+
ALLOWED_PROPS_ESC="$INPUT_ALLOWED_EXTRA_PROPERTIES" \
36+
python3 << 'PYTHON_EOF'
37+
import json
38+
import os
39+
import sys
40+
41+
try:
42+
schema_path = os.environ['SCHEMA_PATH_ESC']
43+
final_schema_path = os.environ['FINAL_SCHEMA_PATH_ESC']
44+
allowed_props_str = os.environ['ALLOWED_PROPS_ESC']
45+
46+
# Read the original schema
47+
with open(schema_path, 'r') as f:
48+
schema = json.load(f)
49+
50+
# Ensure schema has the expected structure
51+
if not isinstance(schema, dict):
52+
print('❌ ERROR: Schema must be a JSON object', file=sys.stderr)
53+
sys.exit(1)
54+
55+
# Parse comma-separated list of allowed properties
56+
allowed_props = [prop.strip() for prop in allowed_props_str.split(',') if prop.strip()]
57+
58+
if not allowed_props:
59+
print('❌ ERROR: No valid property names found in allowed_extra_properties', file=sys.stderr)
60+
sys.exit(1)
61+
62+
# Ensure properties object exists
63+
if 'properties' not in schema:
64+
schema['properties'] = {}
65+
66+
# Add each allowed property to the schema's properties object
67+
# Use empty schema {} which allows any type
68+
for prop in allowed_props:
69+
if prop not in schema['properties']:
70+
schema['properties'][prop] = {}
71+
72+
# Write the modified schema
73+
with open(final_schema_path, 'w') as f:
74+
json.dump(schema, f, indent=2)
75+
76+
print(f'✅ Modified schema written to {final_schema_path}')
77+
except KeyError as e:
78+
print(f'❌ ERROR: Missing environment variable: {e}', file=sys.stderr)
79+
sys.exit(1)
80+
except FileNotFoundError:
81+
print(f'❌ ERROR: Schema file not found: {schema_path}', file=sys.stderr)
82+
sys.exit(1)
83+
except json.JSONDecodeError as e:
84+
print(f'❌ ERROR: Invalid JSON in schema file: {e}', file=sys.stderr)
85+
sys.exit(1)
86+
except Exception as e:
87+
print(f'❌ ERROR: Failed to modify schema: {e}', file=sys.stderr)
88+
sys.exit(1)
89+
PYTHON_EOF
90+
then
91+
echo "❌ Failed to modify schema for extra properties"
92+
exit 1
93+
fi
94+
fi
95+
2596
echo ""
2697

2798
# Run check-jsonschema with the corrected flag: --output-format
28-
if check-jsonschema --schemafile "$SCHEMA_PATH" "$FILE_TO_VALIDATE" --output-format "$INPUT_ERROR_FORMAT"; then
99+
if check-jsonschema --schemafile "$FINAL_SCHEMA_PATH" "$FILE_TO_VALIDATE" --output-format "$INPUT_ERROR_FORMAT"; then
29100
echo ""
30101
echo "🥳 HOORAY! Your .zenodo.json is shiny and valid!"
31102
echo "🏆 You're a hero of Open Science! 🚀✨"

0 commit comments

Comments
 (0)