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(27215): Add validation for Edge entities (topics, topic filters and tags) #644

Merged
merged 8 commits into from
Nov 25, 2024

Conversation

vanch3d
Copy link
Contributor

@vanch3d vanch3d commented Nov 13, 2024

See https://hivemq.kanbanize.com/ctrl_board/57/cards/27215/details/

The PR adds custom format validation for JSONSchema-based validation and any RJSF-based UI widget used to edit the nme of the tree Edge entities.

The validation is based on adding a custom format to the property of a JSONSchema object that must be validated against the syntax rules:

  • MQTT topics, identified by mqtt-topic
  • MQTT topic filters, identified by mqtt-topic-filter
  • Device Tags, identified by mqtt-tag
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "topic": {
      "title": "An MQTT Topic",
      "type": "string",
      "format": "mqtt-topic"
    },
    "tag": {
      "title": "The name of the tag",
      "type": "string",
      "format": "mqtt-tag"
    }
  }
}

The validation rules are ports of the rules from the HiveMQ Community Edition, see https://github.com/hivemq/hivemq-community-edition/blob/eb7c194bd68bdec822c23f34c5ff6aa6751ae0fa/src/main/java/com/hivemq/util/Topics.java

The integration with RJSF-based forms is complete as long as the format is properly defined in the JSONSchema; every existing widget such as text input, auto-complete select, will apply the relevant rules to the item.

The user feedback is greatly improved by delivering case-by-case error messages, rather than the regular expression or the tautological message must match format "mqtt-tag"

Adding the custom formats also removes the warning triggered on the dev console

unknown format "mqtt-tag" ignored in schema at path "#/properties/items/items/properties/tag" 

Out-of-scope

  • If the custom format is not added to a property that requires validation, the string is expected to be of any kind and no validation will apply (see "Tag name of the Destination" in the screenshots below"). Reviewing the JSONSchema of the various config elements will need to be done in separate tickets.

Before

screenshot-localhost_3000-2024_11_13-18_17_55

screenshot-localhost_3000-2024_11_13-18_17_04 (1)

screenshot-localhost_3000-2024_11_13-18_19_02

After

screenshot-localhost_3000-2024_11_13-18_19_41

screenshot-localhost_3000-2024_11_13-18_20_06

screenshot-localhost_3000-2024_11_13-18_20_41

@vanch3d vanch3d self-assigned this Nov 13, 2024
@cla-bot cla-bot bot added the cla-signed label Nov 13, 2024
@vanch3d vanch3d marked this pull request as ready for review November 14, 2024 12:12
@vanch3d vanch3d requested review from h2xd and sfrehse November 14, 2024 12:12
@vanch3d vanch3d force-pushed the feat/27215/validation-topics branch 3 times, most recently from 1b0ca3f to dc0634e Compare November 20, 2024 08:20
Copy link
Contributor

@oli-hivemq oli-hivemq left a comment

Choose a reason for hiding this comment

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

LGTM 🦣

Copy link
Contributor

@h2xd h2xd left a comment

Choose a reason for hiding this comment

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

LGTM! 🐊

Added couple of suggestions

@vanch3d vanch3d force-pushed the feat/27215/validation-topics branch from fdc2bc8 to 8f2707f Compare November 25, 2024 11:05
@vanch3d vanch3d merged commit c35a0d7 into master Nov 25, 2024
9 checks passed
@vanch3d vanch3d deleted the feat/27215/validation-topics branch November 25, 2024 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants