Skip to content
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

Implement x-inOrder subschema for in order or sequential processing #2403

Open
coderextreme opened this issue Mar 31, 2024 · 3 comments
Open

Comments

@coderextreme
Copy link

coderextreme commented Mar 31, 2024

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.

@coderextreme
Copy link
Author

coderextreme commented Apr 1, 2024

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                                                                                                                                                                                  },```

@jasoniangreen
Copy link
Collaborator

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.

@coderextreme
Copy link
Author

coderextreme commented Apr 4, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants