Skip to content

Commit 0d2eff5

Browse files
committed
bring the implementation to 1.0.3 spec
1 parent 12d7c5b commit 0d2eff5

File tree

14 files changed

+554
-50
lines changed

14 files changed

+554
-50
lines changed

builders/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ mod unit_tests {
272272
.entries
273273
.iter()
274274
.any(|entry| entry.get(&call_task_name.to_string()).map_or(false, |task| {
275-
if let TaskDefinition::Call(call_task) = task {
275+
if let TaskDefinition::Call(CallTaskDefinition::Function(call_task)) = task {
276276
call_task.call == call_function_name && call_task.with == Some(call_task_with.clone())
277277
} else {
278278
false
@@ -282,6 +282,7 @@ mod unit_tests {
282282
call_task_name,
283283
call_function_name,
284284
call_task_with);
285+
285286
assert!(
286287
workflow.do_
287288
.entries

builders/src/services/task.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -257,23 +257,27 @@ impl CalltaskDefinitionBuilder {
257257

258258
/// Initializes a new CallTaskDefinitionBuilder
259259
pub fn new(function: &str) -> Self{
260-
Self { task: CallTaskDefinition::new(function, None, None) }
260+
Self { task: CallTaskDefinition::new_function(function, None, None) }
261261
}
262262

263263
/// Adds a new argument to call the function with
264264
pub fn with(&mut self, name: &str, value: Value) -> &mut Self{
265-
if self.task.with.is_none(){
266-
self.task.with = Some(HashMap::new());
267-
}
268-
if let Some(with) = &mut self.task.with {
269-
with.insert(name.to_string(), value);
265+
if let CallTaskDefinition::Function(ref mut task) = self.task{
266+
if task.with.is_none(){
267+
task.with = Some(HashMap::new());
268+
}
269+
if let Some(with) = &mut task.with {
270+
with.insert(name.to_string(), value);
271+
}
270272
}
271273
self
272274
}
273275

274276
/// Sets the arguments to call the function with
275277
pub fn with_arguments(&mut self, arguments: HashMap<String, Value>) -> &mut Self{
276-
self.task.with = Some(arguments);
278+
if let CallTaskDefinition::Function(ref mut task) = self.task{
279+
task.with = Some(arguments);
280+
}
277281
self
278282
}
279283

@@ -282,13 +286,13 @@ impl TaskDefinitionBuilderBase for CalltaskDefinitionBuilder{
282286

283287
/// Configures the task to build to run only if the specified condition matches
284288
fn if_(&mut self, condition: &str) -> &mut Self{
285-
self.task.common.if_ = Some(condition.to_string());
289+
self.task.common_mut().if_ = Some(condition.to_string());
286290
self
287291
}
288292

289293
/// Sets the task's timeout
290294
fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{
291-
self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string()));
295+
self.task.common_mut().timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string()));
292296
self
293297
}
294298

@@ -298,7 +302,7 @@ impl TaskDefinitionBuilderBase for CalltaskDefinitionBuilder{
298302
let mut builder = TimeoutDefinitionBuilder::new();
299303
setup(&mut builder);
300304
let timeout = builder.build();
301-
self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout));
305+
self.task.common_mut().timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout));
302306
self
303307
}
304308

@@ -307,7 +311,7 @@ impl TaskDefinitionBuilderBase for CalltaskDefinitionBuilder{
307311
where F: FnOnce(&mut InputDataModelDefinitionBuilder){
308312
let mut builder = InputDataModelDefinitionBuilder::new();
309313
setup(&mut builder);
310-
self.task.common.input = Some(builder.build());
314+
self.task.common_mut().input = Some(builder.build());
311315
self
312316
}
313317

@@ -316,7 +320,7 @@ impl TaskDefinitionBuilderBase for CalltaskDefinitionBuilder{
316320
where F: FnOnce(&mut OutputDataModelDefinitionBuilder){
317321
let mut builder = OutputDataModelDefinitionBuilder::new();
318322
setup(&mut builder);
319-
self.task.common.output = Some(builder.build());
323+
self.task.common_mut().output = Some(builder.build());
320324
self
321325
}
322326

@@ -325,16 +329,17 @@ impl TaskDefinitionBuilderBase for CalltaskDefinitionBuilder{
325329
where F: FnOnce(&mut OutputDataModelDefinitionBuilder){
326330
let mut builder = OutputDataModelDefinitionBuilder::new();
327331
setup(&mut builder);
328-
self.task.common.export = Some(builder.build());
332+
self.task.common_mut().export = Some(builder.build());
329333
self
330334
}
331335

332336
/// Configures the task to build to then execute the specified flow directive
333337
fn then(&mut self, directive: &str) -> &mut Self{
334-
self.task.common.then = Some(directive.to_string());
338+
self.task.common_mut().then = Some(directive.to_string());
335339
self
336340
}
337341

342+
338343
/// Builds the configures CallTaskDefinition
339344
fn build(self) -> TaskDefinition{
340345
TaskDefinition::Call(self.task)

core/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ mod unit_tests {
77
use crate::models::workflow::*;
88
use crate::models::task::*;
99
use crate::models::map::*;
10+
use crate::models::resource::*;
11+
use crate::models::retry::*;
12+
use crate::models::authentication::*;
1013
use serde_json::json;
1114

1215
#[test]
@@ -16,9 +19,11 @@ mod unit_tests {
1619
let version = "1.0.0";
1720
let title = Some("fake-title".to_string());
1821
let summary = Some("fake-summary".to_string());
19-
let document = WorkflowDefinitionMetadata::new(namespace, name, version, title.clone(), summary.clone(), None);
20-
let mut call_task = CallTaskDefinition::new("http", None, Some(true));
21-
call_task.common.then = Some("continue".to_string());
22+
let document = WorkflowDefinitionMetadata::new(namespace, name, version, title.clone(), summary.clone(), None, None);
23+
let mut call_task = CallTaskDefinition::new_function("http", None, Some(true));
24+
if let CallTaskDefinition::Function(ref mut f) = call_task {
25+
f.common.then = Some("continue".to_string());
26+
}
2227
let do_task = DoTaskDefinition::new(Map::from(vec![("set".to_string(), TaskDefinition::Wait(WaitTaskDefinition::new(OneOfDurationOrIso8601Expression::Duration(Duration::from_milliseconds(200)))))]));
2328
let mut workflow = WorkflowDefinition::new(document);
2429
workflow.do_ = Map::new();
@@ -209,7 +214,7 @@ mod unit_tests {
209214
let mut do_tasks = Map::new();
210215
do_tasks.add(
211216
"task1".to_string(),
212-
TaskDefinition::Call(CallTaskDefinition::new("someFunction", None, None)),
217+
TaskDefinition::Call(CallTaskDefinition::new_function("someFunction", None, None)),
213218
);
214219

215220
let for_task = ForTaskDefinition::new(for_loop, do_tasks, None);
@@ -384,8 +389,7 @@ mod unit_tests {
384389
"version": "0.1.0"
385390
},
386391
"use": {
387-
"extensions": [
388-
{
392+
"extensions": {
389393
"mockService": {
390394
"extend": "call",
391395
"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\")))",
@@ -409,8 +413,8 @@ mod unit_tests {
409413
]
410414
}
411415
}
412-
]
413416
},
417+
414418
"do": [
415419
{
416420
"callHttp": {

core/src/models/authentication.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,14 @@ impl AuthenticationSchemeDefinition for OpenIDConnectSchemeDefinition{
364364
fn scheme(&self) -> &str {
365365
AuthenticationScheme::OIDC
366366
}
367+
}
368+
369+
/// Represents an authentication policy definition or a reference to one
370+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
371+
#[serde(untagged)]
372+
pub enum OneOfAuthenticationPolicyDefinitionOrReference {
373+
/// Inline authentication policy definition
374+
Definition(AuthenticationPolicyDefinition),
375+
/// Reference to an authentication policy
376+
Reference(String),
367377
}

core/src/models/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ use serde_json::Value;
55
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
66
pub struct ErrorDefinition{
77

8+
/// Gets/sets the name of the error to use, if any
9+
#[serde(rename = "use", skip_serializing_if = "Option::is_none")]
10+
pub use_: Option<String>,
11+
812
/// Gets/sets an uri that reference the type of the described error
913
#[serde(rename = "type")]
1014
pub type_: String,
1115

16+
1217
/// Gets/sets a short, human-readable summary of the error type.It SHOULD NOT change from occurrence to occurrence of the error, except for purposes of localization
1318
#[serde(rename = "title")]
1419
pub title: String,
@@ -31,6 +36,7 @@ impl ErrorDefinition{
3136
/// Initializes a new ErrorDefinition
3237
pub fn new(type_: &str, title: &str, status: Value, detail: Option<String>, instance: Option<String>) -> Self{
3338
Self {
39+
use_: None,
3440
type_: type_.to_string(),
3541
title: title.to_string(),
3642
status,

core/src/models/event.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ use std::collections::HashMap;
66
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
77
pub struct EventConsumptionStrategyDefinition{
88

9+
/// Gets/sets the name of the defined strategy to use, if any
10+
#[serde(rename = "use", skip_serializing_if = "Option::is_none")]
11+
pub use_: Option<String>,
12+
913
/// Gets/sets a list containing all the events that must be consumed, if any
14+
1015
#[serde(rename = "all", skip_serializing_if = "Option::is_none")]
1116
pub all: Option<Vec<EventFilterDefinition>>,
1217

core/src/models/input.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ use crate::models::schema::*;
66
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
77
pub struct InputDataModelDefinition{
88

9+
/// Gets/sets the name of the input data model to use, if any
10+
#[serde(rename = "use", skip_serializing_if = "Option::is_none")]
11+
pub use_: Option<String>,
12+
913
/// Gets/sets the schema, if any, that defines and describes the input data of a workflow or task
1014
#[serde(rename = "schema", skip_serializing_if = "Option::is_none")]
1115
pub schema : Option<SchemaDefinition>,

core/src/models/output.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ use crate::models::schema::*;
66
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
77
pub struct OutputDataModelDefinition{
88

9-
/// Gets/sets the schema, if any, that defines and describes the output data of a workflow or task
9+
/// Gets/sets the name of the output data model to use, if any
10+
#[serde(rename = "use", skip_serializing_if = "Option::is_none")]
11+
pub use_: Option<String>,
12+
13+
/// Gets/sets the schema, if any, that defines and describes the output data of a workflow or task
1014
#[serde(rename = "schema", skip_serializing_if = "Option::is_none")]
1115
pub schema: Option<SchemaDefinition>,
1216

13-
/// Gets/sets a runtime expression, if any, used to output specific data to the scope data
17+
/// Gets/sets a runtime expression, if any, used to output specific data to the scope data
1418
#[serde(rename = "as", skip_serializing_if = "Option::is_none")]
1519
pub as_: Option<Value>
1620

core/src/models/resource.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ use crate::models::authentication::*;
55
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
66
pub struct ExternalResourceDefinition{
77

8+
/// Gets/sets the name of the external resource to use, if any
9+
#[serde(rename = "use", skip_serializing_if = "Option::is_none")]
10+
pub use_: Option<String>,
11+
812
/// Gets/sets the external resource's name, if any
913
#[serde(rename = "name", skip_serializing_if = "Option::is_none")]
1014
pub name: Option<String>,
@@ -15,6 +19,7 @@ pub struct ExternalResourceDefinition{
1519

1620
}
1721

22+
1823
/// Represents the definition of an endpoint
1924
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
2025
pub struct EndpointDefinition{

core/src/models/retry.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ use crate::models::duration::*;
55
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
66
pub struct RetryPolicyDefinition{
77

8+
/// Gets/sets the name of the retry policy to use, if any
9+
#[serde(rename = "use", skip_serializing_if = "Option::is_none")]
10+
pub use_: Option<String>,
11+
812
/// Gets/sets a runtime expression used to determine whether or not to retry running the task, in a given context
913
#[serde(rename = "when", skip_serializing_if = "Option::is_none")]
1014
pub when: Option<String>,
1115

16+
1217
/// Gets/sets a runtime expression used to determine whether or not to retry running the task, in a given context
1318
#[serde(rename = "exceptWhen", skip_serializing_if = "Option::is_none")]
1419
pub except_when: Option<String>,

0 commit comments

Comments
 (0)