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

feat: set oneOf json schema property for id and string messages #1326

Merged
merged 3 commits into from
Jan 5, 2024

Conversation

louisaspicer
Copy link
Contributor

For ID and String messages, we want to set the json schema to use oneOf so that only one of the filters can be used at a time. Tom and I had a chat about this and agreed that we would only do this for ID and String fields for now and only allowing one filter at a time makes sense for both string and id filters.

Looking for feedback on how best to approach this

Attempting to go from:

"IdQueryInput": {
        "type": "object",
        "properties": {
          "equals": { "type": ["string", "null"] },
          "notEquals": { "type": ["string", "null"] },
          "oneOf": { "type": "array", "items": { "type": "string" } }
        },
        "additionalProperties": false
      }

to:

"IdQueryInput": {
        "type": "object",
        "oneOf": [
          {
            "title": "Equals",
            "properties": {
              "equals": { "type": "string" }
            },
            "required": ["equals"],
            "additionalProperties": false
          },
          {
            "title": "Not equals",
            "properties": {
              "notEquals": { "type": "string" }
            },
            "required": ["notEquals"],
            "additionalProperties": false
          },
          {
            "title": "One of",
            "properties": {
              "oneOf": { "type": "array", "items": { "type": "string" } }
            },
            "required": ["oneOf"],
            "additionalProperties": false
          }
        ],
        "additionalProperties": false
      }

@louisaspicer louisaspicer requested a review from a team December 21, 2023 15:08
}
],
"additionalProperties": false
Copy link
Member

Choose a reason for hiding this comment

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

I think you might not want this additionalProperties field, as it might be conflicting with oneOf.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea that was the issue - Fixed with unevaluatedProperties https://json-schema.org/understanding-json-schema/reference/object#unevaluated-properties
Also had to change the tests to allow multiple errors per field.

Copy link
Contributor

@davenewza davenewza left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

@louisaspicer louisaspicer marked this pull request as draft January 3, 2024 10:36
@louisaspicer
Copy link
Contributor Author

Don't want to merge this yet until we updte the frontend console to handle new format

@louisaspicer louisaspicer marked this pull request as ready for review January 4, 2024 17:48
@louisaspicer louisaspicer merged commit 8682a7e into main Jan 5, 2024
10 checks passed
@louisaspicer louisaspicer deleted the update-string-id-json-schema branch January 5, 2024 10:03
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.

3 participants