ajv
ajv copied to clipboard
Implement x-inOrder subschema for in order or sequential processing
What problem do you want to solve?
I want to solve the problem of serializing JSON data to XML, and the XML will comply with sequencing specified in XML schema. In other words, I want to throw out JSON with a JSON schema where properties or subschemas do not match a certain ordering.
I would like to add an ‘x-inOrder’ subschema that applies to properties and subschemas, such that I will have a source of information for serializing properties to XML elements, similar to head element and body element ordering in HTML.
What do you think is the correct solution to problem?
Implement something like allOf, anyOf, oneOf, but do sequential processing on it.
Will you be able to implement it?
I might need help understanding Ajv, but I am fairly competent at JavaScript. I’m a long time Ajv user, and I’ve had a tiny bit of time looking at source to make it work on my platform.
I realize I can save this information elsewhere. But I have collaborator that relies on JSON schema.
I would like to make the x-orderOf property a subschema, but here's an initial approach:
"head": {
"x-orderOf": {
"type": "object",
"properties": {
"@component": {
"$comment": "x-orderOf-StatementContentModel",
"minOccurs": "0",
"maxOccurs": "unbounded"
},
"@unit": {
"$comment": "x-orderOf-StatementContentModel",
"minOccurs": "0",
"maxOccurs": "unbounded"
},
"@meta": {
"$comment": "x-orderOf-StatementContentModel",
"minOccurs": "0",
"maxOccurs": "unbounded"
}
}
},
"type": "object",
"properties": {
"-children": {
"$ref": "#/$defs/-childStatements"
},
"@class": { "$comment": "SFString inputOutput", "type": "string" }, "component": { "$ref": "#/$defs/component" }, "@id": { "$comment": "SFString inputOutput", "type": "string" }, "meta": { "$ref": "#/$defs/meta" }, "@style": { "$comment": "SFString inputOutput", "type": "string" }, "unit": { "$ref": "#/$defs/unit" } }, "additionalProperties": false },```
Hi @coderextreme, thanks for your interest in AJV. I am not sure I completely understand the problem yet, but I wonder, have you looked into the custom keyword feature?
I believe you should be able to achieve what you need without any changes to AJV itself. I once wrote a simple form generation function that used custom keywords and the recursive behaviour of AJV to create forms out of custom defined schemas so it should be possible.
I've bookmarked the page. I'm not sure what we can do for validators besides Ajv.
Thanks!
On Wed, Apr 3, 2024 at 5:20 PM Jason Ian Green @.***> wrote:
Hi @coderextreme https://github.com/coderextreme, thanks for your interest in AJV. I am not sure I completely understand the problem yet, but I wonder, have you looked into the custom keyword https://ajv.js.org/keywords.html#define-keyword-with-code-generation-function feature?
I believe you should be able to achieve what you need without any changes to AJV itself. I once wrote a simple form generation function that used custom keywords and the recursive behaviour of AJV to create forms out of custom defined schemas so it should be possible.
— Reply to this email directly, view it on GitHub https://github.com/ajv-validator/ajv/issues/2403#issuecomment-2035701797, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFMJ53R6SLCGJ2J2YA5G33Y3R6CDAVCNFSM6AAAAABFQV222OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZVG4YDCNZZG4 . You are receiving this because you were mentioned.Message ID: @.***>