Skip to content

Support merging types with multiple regex validations (allOf).#1008

Open
inickles wants to merge 1 commit intomainfrom
inickles/merge
Open

Support merging types with multiple regex validations (allOf).#1008
inickles wants to merge 1 commit intomainfrom
inickles/merge

Conversation

@inickles
Copy link
Copy Markdown

@inickles inickles commented May 1, 2026

I tried running Typify on a schema that had an allOf declaration:

    "EmailAddressDatatype": {
      "description": "An email address string formatted according to RFC 6531.",
      "allOf": [
        {
          "$ref": "#/definitions/StringDatatype"
        },
        {
          "type": "string",
          "format": "email",
          "pattern": "^.+@.+$"
        }
      ]
    },

but this resulted in an error: Message: not implemented: merging distinct patterns is impractical

This PR handles the case of multiple regex validation patterns by chaining them with lookaheads.

Consider the test code in this PR at typify-impl/tests/all_of.json:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "TriplePattern": {
            "allOf": [
                {
                    "type": "string",
                    "pattern": "^[a-z].+$",
                    "format": "custom-id"
                },
                { "type": "string", "pattern": "^.{4,8}$" },
                { "type": "string", "pattern": ".+[a-z]$" }
            ]
        }
    }
}

Regex validation for this will now result in:

::regress::Regex::new("(?=^[a-z].+$)(?=^.{4,8}$)(?=.+[a-z]$)")

This adds a new test all_of in typify-test/src/main.rs that verifies this functionality works as expected. It uses that all_of.json, which is also used for an integration test in testify-impl.

Fun fact, the original schema I was trying to process was the NIST OSCAL schema at https://github.com/usnistgov/OSCAL/releases/download/v1.2.2/oscal_catalog_schema.json. I am able to successfully run Typify on that schema with this PR. The pattern for that EmailAddressDatatype type results in:

::regress::Regex::new("(?=^\\S(.*\\S)?$)(?=^.+@.+$)")

@inickles inickles requested a review from ahl May 1, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant