Skip to content

Commit e40d52d

Browse files
centdixrubenfiszel
andauthored
fix(yaml-validator): update openflow for aiagents (#6895)
* update openflow for aiagents * remove value from required in openflow.json * all --------- Co-authored-by: Ruben Fiszel <[email protected]>
1 parent fa76105 commit e40d52d

14 files changed

+688
-159
lines changed

openflow.openapi.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ components:
199199
enum:
200200
- static
201201
required:
202-
- value
203202
- type
204203

205204
JavascriptTransform:

windmill-yaml-validator/README.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Windmill YAML Validator
2+
3+
A TypeScript-based YAML validator for Windmill flow files. This package validates flow.yaml files against the OpenFlow JSON schema to ensure they conform to the Windmill flow specification.
4+
5+
## Overview
6+
7+
The windmill-yaml-validator provides runtime validation for Windmill flow YAML files. It is currently used in the **Windmill VSCode extension** to show syntax errors and validation issues on `flow.yaml` files in real-time as developers edit them.
8+
9+
## Features
10+
11+
- **Schema-based validation**: Validates against the official OpenFlow JSON schema
12+
- **Detailed error reporting**: Returns comprehensive error information with specific paths to invalid fields
13+
14+
## Installation
15+
16+
```bash
17+
npm install windmill-yaml-validator
18+
```
19+
20+
## Usage
21+
22+
### Basic Validation
23+
24+
```typescript
25+
import { FlowValidator } from "windmill-yaml-validator";
26+
27+
const validator = new FlowValidator();
28+
29+
const yamlContent = `
30+
summary: Test Flow
31+
value:
32+
modules: []
33+
`;
34+
35+
const result = validator.validateFlow(yamlContent);
36+
37+
if (result.errors.length === 0) {
38+
console.log("Flow is valid!");
39+
} else {
40+
console.log("Validation errors:", result.errors);
41+
}
42+
```
43+
44+
### Error Handling
45+
46+
The validator returns detailed error information for invalid flows:
47+
48+
```typescript
49+
const invalidYaml = `
50+
summary: 123 # Should be a string
51+
value:
52+
modules:
53+
- id: step1
54+
value:
55+
type: rawscript
56+
language: invalid_language # Invalid enum value
57+
`;
58+
59+
const result = validator.validateFlow(invalidYaml);
60+
61+
result.errors.forEach((error) => {
62+
console.log(`Error at ${error.instancePath}: ${error.message}`);
63+
// Example output:
64+
// Error at /summary: must be string
65+
// Error at /value/modules/0/value/language: must be equal to one of the allowed values
66+
});
67+
```
68+
69+
## API
70+
71+
### `FlowValidator`
72+
73+
Main validator class that validates Windmill flow YAML files.
74+
75+
#### Constructor
76+
77+
```typescript
78+
new FlowValidator();
79+
```
80+
81+
Creates a new validator instance. The constructor initializes the AJV validator with the OpenFlow schema.
82+
83+
#### Methods
84+
85+
##### `validateFlow(doc: string)`
86+
87+
Validates a flow document against the OpenFlow schema.
88+
89+
**Parameters:**
90+
91+
- `doc` (string): The YAML flow document as a string
92+
93+
**Returns:**
94+
95+
```typescript
96+
{
97+
parsed: YamlParserResult<unknown>; // Parsed YAML with source pointers
98+
errors: ErrorObject[]; // Array of validation errors (empty if valid)
99+
}
100+
```
101+
102+
**Throws:**
103+
104+
- Error if `doc` is not a string
105+
106+
## Development
107+
108+
### Building
109+
110+
```bash
111+
npm run build
112+
```
113+
114+
The build process:
115+
116+
1. Runs `gen_openflow_schema.sh` to generate the OpenFlow JSON schema from `openflow.openapi.yaml`
117+
2. Removes discriminator mappings (not supported by AJV)
118+
3. Compiles TypeScript to JavaScript
119+
120+
### Testing
121+
122+
```bash
123+
npm test
124+
```
125+
126+
Run tests in watch mode:
127+
128+
```bash
129+
npm test:watch
130+
```
131+
132+
### Schema Generation
133+
134+
The validator uses a JSON schema generated from the OpenAPI specification:
135+
136+
```bash
137+
./gen_openflow_schema.sh
138+
```
139+
140+
This script:
141+
142+
- Bundles `openflow.openapi.yaml` into a single JSON schema
143+
- Removes discriminator mappings for AJV compatibility
144+
- Removes the `ToolValue` discriminator entirely (see below)
145+
- Outputs to `src/gen/openflow.json`
146+
147+
#### Why Remove Discriminators?
148+
149+
The OpenFlow schema uses OpenAPI discriminators for efficient type resolution in `oneOf` schemas. However, AJV's discriminator support has limitations:
150+
151+
1. **Discriminator Mappings**: Not fully supported by AJV, so they are removed from all schemas
152+
2. **ToolValue Discriminator**: Completely removed because `FlowModuleTool` uses `allOf` composition, which prevents AJV from finding the discriminator property (`tool_type`) at the expected location
153+
154+
**Impact**: Without discriminators, AJV falls back to standard `oneOf` validation, which:
155+
156+
- Tests each alternative until one matches
157+
- Is slightly slower but still performant for our use case
158+
- Provides the same validation correctness
159+
- Works correctly with complex schema compositions like `allOf`

windmill-yaml-validator/gen_openflow_schema.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ try {
2222
}
2323
2424
removeMapping(schema);
25+
26+
// Remove discriminator entirely from ToolValue as it doesn't work with allOf in FlowModuleTool
27+
if (schema.components?.schemas?.ToolValue?.discriminator) {
28+
delete schema.components.schemas.ToolValue.discriminator;
29+
console.log('Removed discriminator from ToolValue schema');
30+
}
31+
2532
fs.writeFileSync(filePath, JSON.stringify(schema, null, 2));
2633
console.log('Removed discriminator mappings from openflow.json');
2734
} catch (e) {

windmill-yaml-validator/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

windmill-yaml-validator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "windmill-yaml-validator",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "YAML validator for Windmill",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)