Skip to content

Commit 12d7c5b

Browse files
authored
Merge pull request #8 from arminhammer/extension-and-container-fix
fix: align container and extension definitions to the spec
2 parents 11c1c5c + 77ac26b commit 12d7c5b

File tree

4 files changed

+87
-9
lines changed

4 files changed

+87
-9
lines changed

core/src/lib.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,74 @@ mod unit_tests {
373373
assert!(script.environment.is_some());
374374
assert_eq!(script.environment.as_ref().unwrap().get("FOO"), Some(&"bar".to_string()));
375375
}
376+
377+
#[test]
378+
fn test_extension_definition_serialization() {
379+
let extension_json = json!({
380+
"document": {
381+
"dsl": "1.0.2",
382+
"namespace": "test",
383+
"name": "sample-workflow",
384+
"version": "0.1.0"
385+
},
386+
"use": {
387+
"extensions": [
388+
{
389+
"mockService": {
390+
"extend": "call",
391+
"when": "($task.with.endpoint != null and ($task.with.endpoint | startswith(\"https://mocked.service.com\"))) or ($task.with.endpoint.uri != null and ($task.with.endpoint.uri | startswith(\"https://mocked.service.com\")))",
392+
"before": [
393+
{
394+
"mockResponse": {
395+
"set": {
396+
"statusCode": 200,
397+
"headers": {
398+
"Content-Type": "application/json"
399+
},
400+
"content": {
401+
"foo": {
402+
"bar": "baz"
403+
}
404+
}
405+
},
406+
"then": "exit"
407+
}
408+
}
409+
]
410+
}
411+
}
412+
]
413+
},
414+
"do": [
415+
{
416+
"callHttp": {
417+
"call": "http",
418+
"with": {
419+
"method": "get",
420+
"endpoint": {
421+
"uri": "https://fake.com/sample"
422+
}
423+
}
424+
}
425+
}
426+
]
427+
});
428+
let result: Result<WorkflowDefinition, _> = serde_json::from_value(extension_json);
429+
match result {
430+
Ok(workflow) => {
431+
// Verify the workflow was deserialized correctly
432+
assert_eq!(workflow.document.namespace, "test");
433+
assert_eq!(workflow.document.name, "sample-workflow");
434+
assert_eq!(workflow.document.version, "0.1.0");
435+
// Verify the use section exists with extensions
436+
assert!(workflow.use_.is_some());
437+
if let Some(use_def) = workflow.use_ {
438+
assert!(use_def.extensions.is_some());
439+
}
440+
}
441+
Err(e) => {
442+
panic!("Failed to deserialize workflow with extension: {}", e);
443+
}
444+
}
445+
}
376446
}

core/src/models/extension.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ pub struct ExtensionDefinition{
1414
#[serde(rename = "when", skip_serializing_if = "Option::is_none")]
1515
pub when: Option<String>,
1616

17-
/// Gets/sets a name/definition map, if any, of the tasks to execute before the extended task
17+
/// Gets/sets a name/definition list, if any, of the tasks to execute before the extended task
1818
#[serde(rename = "before", skip_serializing_if = "Option::is_none")]
19-
pub before: Option<HashMap<String, TaskDefinition>>,
19+
pub before: Option<Vec<HashMap<String, TaskDefinition>>>,
2020

21-
/// Gets/sets a name/definition map, if any, of the tasks to execute after the extended task
21+
/// Gets/sets a name/definition list, if any, of the tasks to execute after the extended task
2222
#[serde(rename = "after", skip_serializing_if = "Option::is_none")]
23-
pub after: Option<HashMap<String, TaskDefinition>>
24-
23+
pub after: Option<Vec<HashMap<String, TaskDefinition>>>
2524
}

core/src/models/task.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,16 +715,25 @@ pub struct ContainerProcessDefinition{
715715
#[serde(rename = "environment", skip_serializing_if = "Option::is_none")]
716716
pub environment: Option<HashMap<String, String>>,
717717

718+
/// Gets/sets the data to pass to the process via stdin, if any
719+
#[serde(rename = "stdin", skip_serializing_if = "Option::is_none")]
720+
pub stdin: Option<String>,
721+
722+
/// Gets/sets a list of arguments, if any, to pass to the container (argv)
723+
#[serde(rename = "arguments", skip_serializing_if = "Option::is_none")]
724+
pub arguments: Option<Vec<String>>,
718725
}
719726
impl ContainerProcessDefinition {
720-
pub fn new(image: &str, name: Option<String>, command: Option<String>, ports: Option<HashMap<u16, u16>>, volumes: Option<HashMap<String, String>>, environment: Option<HashMap<String, String>>) -> Self{
727+
pub fn new(image: &str, name: Option<String>, command: Option<String>, ports: Option<HashMap<u16, u16>>, volumes: Option<HashMap<String, String>>, environment: Option<HashMap<String, String>>, stdin: Option<String>, arguments: Option<Vec<String>>) -> Self{
721728
Self {
722729
image: image.to_string(),
723730
name,
724731
command,
725732
ports,
726733
volumes,
727-
environment
734+
environment,
735+
stdin,
736+
arguments,
728737
}
729738
}
730739
}

core/src/models/workflow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ pub struct ComponentDefinitionCollection{
205205
#[serde(rename = "errors", skip_serializing_if = "Option::is_none")]
206206
pub errors: Option<HashMap<String, ErrorDefinition>>,
207207

208-
/// Gets/sets a name/value mapping of the workflow's extensions, if any
208+
/// Gets/sets a list containing the workflow's extensions, if any
209209
#[serde(rename = "extensions", skip_serializing_if = "Option::is_none")]
210-
pub extensions: Option<HashMap<String, ExtensionDefinition>>,
210+
pub extensions: Option<Vec<HashMap<String, ExtensionDefinition>>>,
211211

212212
/// Gets/sets a name/value mapping of the workflow's reusable functions
213213
#[serde(rename = "functions", skip_serializing_if = "Option::is_none")]

0 commit comments

Comments
 (0)