diff --git a/src/shacl2code/lang/jsonschema.py b/src/shacl2code/lang/jsonschema.py index 295dd88d..32b7a503 100644 --- a/src/shacl2code/lang/jsonschema.py +++ b/src/shacl2code/lang/jsonschema.py @@ -29,6 +29,7 @@ def __init__(self, args): "schema_title": args.title, "schema_id": args.id, "allow_elided_lists": args.allow_elided_lists, + "jsf_signature": args.jsf_signature, } @classmethod @@ -42,6 +43,11 @@ def get_arguments(cls, parser): action="store_true", help="Allow lists to be elided if they only contain a single element", ) + parser.add_argument( + "--jsf-signature", + metavar="NAME", + help="Allow JSON Signature Format (JSF) property with name 'NAME'. Recommended name is 'signature'", + ) def get_extra_env(self): return { diff --git a/src/shacl2code/lang/templates/jsonschema.j2 b/src/shacl2code/lang/templates/jsonschema.j2 index a43ff374..594fc477 100644 --- a/src/shacl2code/lang/templates/jsonschema.j2 +++ b/src/shacl2code/lang/templates/jsonschema.j2 @@ -50,12 +50,24 @@ "$ref": "#/$defs/AnyClass", "unevaluatedProperties": false } - } + }{%- if jsf_signature %}, + "{{ jsf_signature }}": { + "$ref": "#/$defs/JSF" + }{%- endif %} }, "required": ["@graph"] }, "else": { - "$ref": "#/$defs/AnyClass" + "allOf": [ + { + "$ref": "#/$defs/AnyClass" + }{%- if jsf_signature %}, + { + "properties": { + "{{ jsf_signature }}": { "$ref": "#/$defs/JSF" } + } + }{%- endif %} + ] }, "unevaluatedProperties": false, @@ -328,6 +340,60 @@ } } ] + }, + "JSFSignature": { + "type": "object", + "properties": { + "algorithm": { "type": "string" }, + "keyId": { "type": "string" }, + "publicKey": { + "type": "object", + "properties": { + "kty": { "type": "string" } + }, + "required": [ "kty" ] + }, + "certificatePath": { + "type": "array", + "items": { "type": "string" }, + "minCount": 1 + }, + "value": { "type": "string" } + }, + "required": [ + "algorithm", + "value" + ], + "additionalProperties": false + }, + "JSF": { + "anyOf": [ + { "$ref": "#/$defs/JSFSignature" }, + { + "type": "object", + "properties": { + "signers": { + "type": "array", + "items": { "$ref": "#/$defs/JSFSignature" }, + "minCount": 1 + } + }, + "required": ["signers"], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "chain": { + "type": "array", + "items": { "$ref": "#/$defs/JSFSignature" }, + "minCount": 1 + } + }, + "required": ["chain"], + "additionalProperties": false + } + ] } } }