Skip to content

fix: Call AsyncAPI showing required fields as optional - #551

Open
handreyrc wants to merge 3 commits into
open-workflow-specification:feature/node-editingfrom
handreyrc:fix-call-asyncapi-document
Open

handreyrc wants to merge 3 commits into
open-workflow-specification:feature/node-editingfrom
handreyrc:fix-call-asyncapi-document

Conversation

@handreyrc

Copy link
Copy Markdown
Contributor

Closes #538

This PR fixes required oneOf combinations and its combination scenarios.

The form builder drops multi-key required combinations when a property has a oneOf whose entries only contain required (no properties, type or $ref), it treats it as "validation-only".
It then handles only one shape:

  • Every entry names exactly one key (singleKeyPerCandidate, e.g. MCP transport: [http] | [stdio]): it builds a variant picker.
  • Anything else: nothing is done with the combinations. It falls through to the plain-object branch, which works out the children's required flags from resolved.required only. That array doesn't exist on with, so every child gets required: false.

The AsyncAPI entries have 3 keys each, so they hit the second case.

  • with kind=object required=true
    • with.document required=false ← should be true
    • with.channel required=false
    • with.operation required=false
    • with.server required=false
    • with.protocol required=false
    • with.message required=false
    • with.subscription required=false
    • with.authentication required=false

The fix is to break down the oneOf combinations into three groups:

  • In every combination (document): this is effectively required. Taking the intersection of the combinations' required lists and merging it into the child required set would fix the reported bug. It's a small, general change, and it leaves the MCP single-key case alone because there the intersection is empty.
  • Mutually exclusive alternatives (operation vs channel, message vs subscription): these can't simply be marked required.
    • model them as variant pickers ("Operation / Channel", "Message / Subscription"), as is done for MCP transport.
  • In no combination (server, protocol, authentication): these stay optional.

Changes

  • schemaToFormFields.ts
    • Added requiredKeys(schema): intersects the required lists across all required-only candidates — keys present in every combination are effectively always required. Merged into the child required set so the plain-object branch picks them up. The single-key MCP case is unaffected.
    • Added isRequiredOnlyCandidate and requiredList helpers (extracted from existing inline predicates).
    • Added buildCombinationVariants: when candidates have more than one key each, builds one OneOfVariant per combination. Keys shared across all combinations are required in every variant; identifying keys are required only in their own variant and hidden in the others. Variant label is the join of its identifying keys' display names (e.g. "Operation + Message").
    • Added buildOneOfField helper used at all three one-of construction sites.
    • Added capitalize helper, extracted from an existing inline expression.
    • requiredSet default now calls requiredKeys instead of reading schema.required directly — fix applies uniformly to ordered-map items, event-filter items and plain-object children.
    • Renamed OneOfVariant.requiredKey → identifyingKeys: string[] to support multi-key identifying sets.
  • activeFormView.ts
    • buildActiveFormView now iterates variant.identifyingKeys (falling back to [variant.presenceKey]) when tracking active vs other variant keys, so presence tracking works for combination variants.

How to test

Open Storybook → Examples → Call AsyncAPI Publish in edit mode.

1. Required marker and no remove ✕

  • document must show a required marker and have no remove ✕.

2. Variant switcher — Operation + Message ↔ Channel + Subscription

  1. Switch from Operation + Message to Channel + Subscription: message keeps its value, operation disappears and an empty channel field appears.
  2. Apply and confirm operation is gone from the YAML.
  3. Switch back before Apply: the earlier values must be restored.

3. Optional fields stay optional

  • server, protocol and authentication are in no combination — they must remain optional with a remove ✕.

@handreyrc handreyrc self-assigned this Nov 19, 2026
@netlify

netlify Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for openworkflow-editor ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit ba79910
🔍 Latest deploy log https://app.netlify.com/projects/openworkflow-editor/deploys/6b0071638af3330abad58369
😎 Deploy Preview https://deploy-preview-551--openworkflow-editor.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@handreyrc
handreyrc requested a balanced review from Copilot November 19, 2026 23:24
@changeset-bot

changeset-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ba79910

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@openworkflowspec/diagram-editor Patch
@openworkflowspec/core Patch
@openworkflowspec/i18n Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Variant generation can hide valid fields and remove values during switching, while Apply can reset the selected variant when multiple partial matches are compatible.

2 open issues
What changed in this PR

This PR updates the diagram editor’s schema-driven forms to show required AsyncAPI fields and offer selectors for required-field combinations.

Changes:

  • Derives shared required keys and builds variants for multi-key combinations.
  • Updates active-form validation to track multiple identifying keys per variant.
  • Adds combination coverage, expands AsyncAPI fixtures, and records a patch changeset.
File Description
packages/​open-workflow-diagram-editor/​tests/​side-panel/​forms/​validation/​activeFormView.test.ts Tests multiple identifying keys and presence-key fallback.
packages/​open-workflow-diagram-editor/​tests/​fixtures/​taskValidation.ts Adds AsyncAPI combinations and updates expected validation paths.
packages/​open-workflow-diagram-editor/​tests/​core/​schemaToFormFields.test.ts Tests combination variants, matching, and shared required fields.
packages/​open-workflow-diagram-editor/​src/​side-panel/​forms/​validation/​activeFormView.ts Tracks each variant’s identifying keys for validation.
packages/​open-workflow-diagram-editor/​src/​core/​schemaToFormFields.ts Adds shared-required-key inference and combination variant generation.
.changeset/​fix-asyncapi-combinations.md Records the diagram editor patch release.

Review effort: Balanced

Signed-off-by: Handrey Cunha <handrey.cunha@gmail.com>
Signed-off-by: Handrey Cunha <handrey.cunha@gmail.com>
Signed-off-by: Handrey Cunha <handrey.cunha@gmail.com>
@handreyrc
handreyrc force-pushed the fix-call-asyncapi-document branch from 9e1f11d to ba79910 Compare November 20, 2026 16:12
@handreyrc

Copy link
Copy Markdown
Contributor Author

Rebased! Ready for review.

@lornakelly lornakelly left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

This branch has not been deployed

No deployments
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