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

Update tests to support corrected JSON Schema Generation PR #380

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

aj-stein-nist
Copy link
Collaborator

@aj-stein-nist aj-stein-nist commented Jun 8, 2023

Committer Notes

This PR amends existing tests and creates new ones to expand JSON Schema generation coverage given root cause analysis and review provided by community member @kylelaker in #360.

Specifically, json-schema-gen/json-value_flag_constrained-open_metaschema.xml and the related test in json-schema-gen.xspec will fail if run against current develop code (before merging #360) and will pass once run against the #360 branch (against the original commit as specific in most current PR feedback; I have not included that code to make both PRs mergeable).

As-is, the test will fail with current develop as the integration test will actually return this output, which is incorrect.

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://csrc.nist.gov/ns/metaschema-tests/0.1/json-value_flag_constrained-open-schema.json",
  "$comment": "JSON value testing mini metaschema: JSON Schema",
  "type": "object",
  "definitions": {
    "json-value_flag_constrained-open-json-value_flag_constrained-open:root": {
      "title": "Root",
      "description": "Root root root.",
      "$id": "#assembly_json-value_flag_constrained-open_root",
      "type": "object",
      "properties": {
        "constrained-open": {
          "$ref": "#field_json-value_flag_constrained-open_constrained-open"
        }
      },
      "additionalProperties": false
    },
    "json-value_flag_constrained-open-json-value_flag_constrained-open:constrained-open": {
      "title": "Constrained open",
      "description": "Because allow-other is 'yes' no enumeration can be given in the JSON Schema.",
      "$id": "#field_json-value_flag_constrained-open_constrained-open",
      "type": "object",
      "properties": {
        "some": {
          "title": "Some Flag",
          "description": "Some flag some flag some flag.",
          "allOf": [
            {
              "$ref": "#/definitions/StringDatatype"
            },
            {
              "enum": [
                "one",
                "two",
                "three",
                "four"
              ]
            }
          ]
        },
        "token-value": {
          "$ref": "#/definitions/TokenDatatype"
        }
      },
      "required": [
        "token-value"
      ],
      "additionalProperties": false
    },
    "StringDatatype": {
      "description": "A non-empty string with leading and trailing whitespace disallowed. Whitespace is: U+9, U+10, U+32 or [ \n\t]+",
      "type": "string",
      "pattern": "^\\S(.*\\S)?$"
    },
    "TokenDatatype": {
      "description": "A non-colonized name as defined by XML Schema Part 2: Datatypes Second Edition. https://www.w3.org/TR/xmlschema11-2/#NCName.",
      "type": "string",
      "pattern": "^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$"
    }
  },
  "properties": {
    "root": {
      "$ref": "#assembly_json-value_flag_constrained-open_root"
    }
  },
  "required": [
    "root"
  ],
  "additionalProperties": false,
  "maxProperties": 1
}

The correct output expected is like the target:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://csrc.nist.gov/ns/metaschema-tests/0.1/json-value_flag_constrained-open-schema.json",
  "$comment": "JSON value testing mini metaschema: JSON Schema",
  "type": "object",
  "definitions": {
    "json-value_flag_constrained-open-json-value_flag_constrained-open:root": {
      "title": "Root",
      "description": "Root root root.",
      "$id": "#assembly_json-value_flag_constrained-open_root",
      "type": "object",
      "properties": {
        "constrained-open": {
          "$ref": "#field_json-value_flag_constrained-open_constrained-open"
        }
      },
      "additionalProperties": false
    },
    "json-value_flag_constrained-open-json-value_flag_constrained-open:constrained-open": {
      "title": "Constrained open",
      "description": "Because allow-other is 'yes' no enumeration can be given in the JSON Schema.",
      "$id": "#field_json-value_flag_constrained-open_constrained-open",
      "type": "object",
      "properties": {
        "some": {
          "title": "Some Flag",
          "description": "Some flag some flag some flag.",
          "anyOf": [
            {
              "$ref": "#/definitions/StringDatatype"
            },
            {
              "enum": [
                "one",
                "two",
                "three",
                "four"
              ]
            }
          ]
        },
        "token-value": {
          "$ref": "#/definitions/TokenDatatype"
        }
      },
      "required": [
        "token-value"
      ],
      "additionalProperties": false
    },
    "StringDatatype": {
      "description": "A non-empty string with leading and trailing whitespace disallowed. Whitespace is: U+9, U+10, U+32 or [ \n\t]+",
      "type": "string",
      "pattern": "^\\S(.*\\S)?$"
    },
    "TokenDatatype": {
      "description": "A non-colonized name as defined by XML Schema Part 2: Datatypes Second Edition. https://www.w3.org/TR/xmlschema11-2/#NCName.",
      "type": "string",
      "pattern": "^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$"
    }
  },
  "properties": {
    "root": {
      "$ref": "#assembly_json-value_flag_constrained-open_root"
    }
  },
  "required": [
    "root"
  ],
  "additionalProperties": false,
  "maxProperties": 1
}

The additional flag tests do not include the same number of tests because, as this developer fatefully learned last week after some unfortunate trial and error, allowed-values for flag elements do not have an explicit @target attribute in their syntax. Only fields can have an explicit @target and for good reason.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you squashed any non-relevant commits and commit messages? [instructions]
  • Do all automated CI/CD checks pass?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you included examples of how to use your new feature(s)?
  • Have you updated all website](https://pages.nist.gov/metaschema) and readme documentation affected by the changes you made? Changes to the website can be made in the website/content directory of your branch.

@aj-stein-nist aj-stein-nist added bug Something isn't working XSLT Implementation Issue relates to the XSLT implementation of Metaschema. Tech Debt labels Jun 8, 2023
@aj-stein-nist aj-stein-nist self-assigned this Jun 8, 2023
@aj-stein-nist aj-stein-nist changed the base branch from main to develop June 8, 2023 19:52
@aj-stein-nist aj-stein-nist marked this pull request as ready for review June 10, 2023 04:32
@aj-stein-nist aj-stein-nist force-pushed the all-of-any-of-tests branch 9 times, most recently from 5c4317a to da250ae Compare June 15, 2023 00:10
aj-stein-nist and others added 2 commits June 14, 2023 20:30
Previously in usnistgov#360, @kylelaker reported a needed
improvement to fix a regression for usnistgov/OSCAL#1773. While I had
been completing testing in usnistgov#360 and properly expanding test coverage to
address how we handle enumerations based on allow-other and target
attributes for field and flag elements in Metaschema (both act similarly
but subtly different with more scenarios for field), I observed my test data
instances needed further correction in a way that cannot be address in the
PR by Kyle. This merges the changes from the commit reffed by the URL
below, adds my enhancement, tests, and all examples that helped me
uncover missing code.

usnistgov@6fb8a74

Co-authored-by: Kyle Laker <[email protected]>
@aj-stein-nist
Copy link
Collaborator Author

aj-stein-nist commented Jun 15, 2023

@JustKuzya and @wendellpiez I had to enhance some of the tests and noticed the "sort of" and "narrow" cases for field enumerations (not flags) regressed back to not working correctly. I also included test data. I can walk everyone through this but for review it would be good to do the following.

  1. Run test-suite/metaschema-xspec/json-schema-gen/json-schema-gen.xspec first by opening it in Oxygen to run the detected scenario. (Ensure the transforms now generate the target JSON Schema as desired)
  2. Ensure any example JSON file with PASS in the name is valid and any with FAIL in the name correctly throw validation errors when configuring the similarly named target schema with Oxygen's validation menu.

I will soon create a wiki entry.

@aj-stein-nist
Copy link
Collaborator Author

@wendellpiez Dave asked in today's call that we get your review before we merge this. Do we need to talk on Monday and walk through it together or you can review it without me?

@wendellpiez
Copy link
Collaborator

wendellpiez commented Jun 26, 2023

Let's talk, pretty much at your convenience. Thanks!

Main question being not the PR but the corresponding patch in the new repo https://github.com/usnistgov/metaschema-xslt.

@JustKuzya
Copy link
Collaborator

JustKuzya commented Jun 26, 2023 via email

@aj-stein-nist
Copy link
Collaborator Author

Can we follow up after or precede the daily status meeting? DC

@JustKuzya we can catch up but it seems I have a meeting after standup so perhaps we can find another time?

@JustKuzya
Copy link
Collaborator

JustKuzya commented Jun 26, 2023 via email

Copy link
Collaborator

@wendellpiez wendellpiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, Kyle and AJ both/especially

Copy link
Collaborator

@david-waltermire david-waltermire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks to @aj-stein-nist and reviewers.

@david-waltermire david-waltermire merged commit 13cde79 into usnistgov:develop Jun 26, 2023
Copy link
Collaborator

@JustKuzya JustKuzya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes seem to work.

  • I would have prefered the WIKI (or additional Readme with tests) to have more clarification on the tests purpose, workflows tested, and expected results for each test we add.
  • Also, would be nice to separate Manual testing WIKI and Automated/Terminal testing WIKI/Readme guidance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Tech Debt XSLT Implementation Issue relates to the XSLT implementation of Metaschema.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants