Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/temporary-validation-workaround.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@openworkflowspec/diagram-editor": minor
---

Temporary validation workaround before updated specification is published
2 changes: 2 additions & 0 deletions packages/open-workflow-diagram-editor/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

export * from "./workflowSdk";
export * from "./validationErrors";
/* TEMPORARY — remove with the workaround; see the revert checklist in workflowSdk.ts. */
export * from "./specWorkarounds";
export * from "./graph";
export * from "./taskDetails";
export * from "./taskSubType";
Expand Down
60 changes: 60 additions & 0 deletions packages/open-workflow-diagram-editor/src/core/specWorkarounds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2021-Present The Open Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { ValidationError } from "./workflowSdk";

/* TEMPORARY — DELETE FILE WHEN THE SDK IS BUMPED https://github.com/open-workflow-specification/editor/issues/267
The specification has merged validation changes (spec#1169, spec#1175) that are not yet published in `@openworkflowspec/sdk`. Once the spec publishes, the bundled schema will reject workflows that are valid against it, and the editor would show validation errors for them. This module temporarily strips those false errors.
*/

const URI_TEMPLATE_DEF = "/$defs/uriTemplate";
const EMIT_WITH_REQUIRED = "/properties/emit/properties/event/properties/with/required";

/* https://github.com/open-workflow-specification/specification/pull/1169 */
function findRelaxedUriPaths(errors: ValidationError[]): Set<string> {
const paths = new Set<string>();
for (const error of errors) {
if (error.path !== undefined && error.errorType?.includes(URI_TEMPLATE_DEF)) {
Comment thread
lornakelly marked this conversation as resolved.
paths.add(error.path);
}
}
return paths;
}

/* https://github.com/open-workflow-specification/specification/pull/1175 */
function isEmitSourceRequiredError(error: ValidationError): boolean {
return (
error.errorType?.includes(EMIT_WITH_REQUIRED) === true &&
error.object?.["missingProperty"] === "source"
);
}

/*
Removes validation errors the bundled SDK schema raises for workflows that are
valid against the current specification.
Done during `validateWorkflow` so the errors never reach the store.
*/
export function stripSpecAheadOfSdkErrors(errors: ValidationError[]): ValidationError[] {
const relaxedUriPaths = findRelaxedUriPaths(errors);

return errors.filter((error) => {
if (error.path !== undefined && relaxedUriPaths.has(error.path)) {
return false;
}

return !isEmitSourceRequiredError(error);
});
}
10 changes: 8 additions & 2 deletions packages/open-workflow-diagram-editor/src/core/workflowSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { load } from "js-yaml";
import * as sdk from "@openworkflowspec/sdk";
import { fixNodesConnections } from "./graph";
import { stripSpecAheadOfSdkErrors } from "./specWorkarounds";

/**
* Sanitizes an object by removing dangerous prototype pollution keys
Expand Down Expand Up @@ -238,9 +239,14 @@ export function validateWorkflow(model: sdk.Specification.Workflow): SdkError[]
const message = err instanceof Error ? err.message : String(err);
const parsedErrors = dedupeValidationErrors(parseValidationErrorMessage(message));

// If parsing succeeded and returned errors, use them
/* If parsing succeeded and returned errors, use them.
*
* TEMPORARY — TO REVERT WHEN THE SDK IS BUMPED (see core/specWorkarounds.ts):
* Replace `stripSpecAheadOfSdkErrors(...)` with `return parsedErrors;` again.
*/
if (parsedErrors.length > 0) {
return parsedErrors;
//return parsedErrors;
return stripSpecAheadOfSdkErrors(parsedErrors);
}
Comment thread
lornakelly marked this conversation as resolved.

// Otherwise, return the original error as-is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ do:
call: openapi
with:
document:
endpoint: http://myorg.io/ordersservices.json
endpoint: openapi/ordersservices.json
operationId: produceReport
- emitEvent:
emit:
Expand All @@ -78,6 +78,13 @@ do:
items:
- breed: dalmatian
quantity: 101
- emitCompletion:
emit:
event:
with:
type: com.petstore.readings.completed.v1
data:
roomId: \${ .roomid }
timeout:
after:
hours: 1`;
Expand Down Expand Up @@ -107,3 +114,52 @@ export const Component: Story = {
content: workflowExample,
},
};

/* The two stories below each isolate ONE piece of spec syntax the editor must accept,
* and both must render clean (no error badge).
*/

const relativeUriEndpointExample = `document:
dsl: '1.0.3'
namespace: examples
name: relative-uri-endpoint
version: '0.1.0'
do:
- generateReport:
call: openapi
with:
document:
endpoint: openapi/ordersservices.json
operationId: produceReport`;

const emitWithoutSourceExample = `document:
dsl: '1.0.3'
namespace: examples
name: emit-without-source
version: '0.1.0'
do:
- emitCompletion:
emit:
event:
with:
type: com.petstore.readings.completed.v1
data:
roomId: \${ .roomid }`;

/* A URI is an RFC 3986 URI-reference, so a relative one is valid and must not error. */
export const RelativeUriEndpoint: Story = {
args: {
isReadOnly: true,
locale: "en",
content: relativeUriEndpointExample,
},
};

/* `source` is optional when emitting (runtimes generate it from the workflow) — so omitting it must not error. */
export const EmitWithoutSource: Story = {
args: {
isReadOnly: true,
locale: "en",
content: emitWithoutSourceExample,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ test("diagram editor renders correctly", async ({ page }) => {

// Check total nodes
const nodes = page.locator('[data-testid^="rf__node-"]');
await expect(nodes).toHaveCount(9);
await expect(nodes).toHaveCount(10);

// Check total edge
const edges = page.locator('[data-testid^="rf__edge-"]');
await expect(edges).toHaveCount(7);
await expect(edges).toHaveCount(8);
});
Loading