Skip to content

Commit b62bcc7

Browse files
fix
1 parent e4fe06e commit b62bcc7

File tree

15 files changed

+180
-171
lines changed

15 files changed

+180
-171
lines changed

arazzo/components.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ type componentKey struct {
4141
// Validate validates the Components object.
4242
func (c *Components) Validate(ctx context.Context, opts ...validation.Option) []error {
4343
errs := []error{}
44+
core := c.GetCore()
4445

4546
for key, input := range c.Inputs.All() {
4647
if !componentNameRegex.MatchString(key) {
47-
errs = append(errs, validation.NewMapKeyError(fmt.Sprintf("input key must be a valid key [%s]: %s", componentNameRegex.String(), key), c.GetCore(), c.GetCore().Inputs, key))
48+
errs = append(errs, validation.NewMapKeyError(fmt.Sprintf("input key must be a valid key [%s]: %s", componentNameRegex.String(), key), core, core.Inputs, key))
4849
}
4950

5051
if input.IsLeft() {
@@ -56,7 +57,7 @@ func (c *Components) Validate(ctx context.Context, opts ...validation.Option) []
5657

5758
for key, parameter := range c.Parameters.All() {
5859
if !componentNameRegex.MatchString(key) {
59-
errs = append(errs, validation.NewMapKeyError(fmt.Sprintf("parameter key must be a valid key [%s]: %s", componentNameRegex.String(), key), c.GetCore(), c.GetCore().Parameters, key))
60+
errs = append(errs, validation.NewMapKeyError(fmt.Sprintf("parameter key must be a valid key [%s]: %s", componentNameRegex.String(), key), core, core.Parameters, key))
6061
}
6162

6263
paramOps := append(opts, validation.WithContextObject(&componentKey{name: key}))
@@ -66,7 +67,7 @@ func (c *Components) Validate(ctx context.Context, opts ...validation.Option) []
6667

6768
for key, successAction := range c.SuccessActions.All() {
6869
if !componentNameRegex.MatchString(key) {
69-
errs = append(errs, validation.NewMapKeyError(fmt.Sprintf("successAction key must be a valid key [%s]: %s", componentNameRegex.String(), key), c.GetCore(), c.GetCore().SuccessActions, key))
70+
errs = append(errs, validation.NewMapKeyError(fmt.Sprintf("successAction key must be a valid key [%s]: %s", componentNameRegex.String(), key), core, core.SuccessActions, key))
7071
}
7172

7273
successActionOps := append(opts, validation.WithContextObject(&componentKey{name: key}))
@@ -76,15 +77,15 @@ func (c *Components) Validate(ctx context.Context, opts ...validation.Option) []
7677

7778
for key, failureAction := range c.FailureActions.All() {
7879
if !componentNameRegex.MatchString(key) {
79-
errs = append(errs, validation.NewMapKeyError(fmt.Sprintf("failureAction key must be a valid key [%s]: %s", componentNameRegex.String(), key), c.GetCore(), c.GetCore().FailureActions, key))
80+
errs = append(errs, validation.NewMapKeyError(fmt.Sprintf("failureAction key must be a valid key [%s]: %s", componentNameRegex.String(), key), core, core.FailureActions, key))
8081
}
8182

8283
failureActionOps := append(opts, validation.WithContextObject(&componentKey{name: key}))
8384

8485
errs = append(errs, failureAction.Validate(ctx, failureActionOps...)...)
8586
}
8687

87-
c.Valid = len(errs) == 0 && c.GetCore().GetValid()
88+
c.Valid = len(errs) == 0 && core.GetValid()
8889

8990
return errs
9091
}

arazzo/criterion/criterion.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,25 @@ type CriterionExpressionType struct {
5252
// Validate will validate the criterion expression type object against the Arazzo specification.
5353
func (c *CriterionExpressionType) Validate(opts ...validation.Option) []error {
5454
errs := []error{}
55+
core := c.GetCore()
5556

5657
switch c.Type {
5758
case CriterionTypeJsonPath:
5859
switch c.Version {
5960
case CriterionTypeVersionDraftGoesnerDispatchJsonPath00:
6061
default:
61-
errs = append(errs, validation.NewValueError(fmt.Sprintf("version must be one of [%s]", strings.Join([]string{string(CriterionTypeVersionDraftGoesnerDispatchJsonPath00)}, ", ")), c.GetCore(), c.GetCore().Type))
62+
errs = append(errs, validation.NewValueError(fmt.Sprintf("version must be one of [%s]", strings.Join([]string{string(CriterionTypeVersionDraftGoesnerDispatchJsonPath00)}, ", ")), core, core.Version))
6263
}
6364
case CriterionTypeXPath:
6465
switch c.Version {
6566
case CriterionTypeVersionXPath30:
6667
case CriterionTypeVersionXPath20:
6768
case CriterionTypeVersionXPath10:
6869
default:
69-
errs = append(errs, validation.NewValueError(fmt.Sprintf("version must be one of [%s]", strings.Join([]string{string(CriterionTypeVersionXPath30), string(CriterionTypeVersionXPath20), string(CriterionTypeVersionXPath10)}, ", ")), c.GetCore(), c.GetCore().Type))
70+
errs = append(errs, validation.NewValueError(fmt.Sprintf("version must be one of [%s]", strings.Join([]string{string(CriterionTypeVersionXPath30), string(CriterionTypeVersionXPath20), string(CriterionTypeVersionXPath10)}, ", ")), core, core.Version))
7071
}
7172
default:
72-
errs = append(errs, validation.NewValueError(fmt.Sprintf("type must be one of [%s]", strings.Join([]string{string(CriterionTypeJsonPath), string(CriterionTypeXPath)}, ", ")), c.GetCore(), c.GetCore().Type))
73+
errs = append(errs, validation.NewValueError(fmt.Sprintf("type must be one of [%s]", strings.Join([]string{string(CriterionTypeJsonPath), string(CriterionTypeXPath)}, ", ")), core, core.Type))
7374
}
7475

7576
if len(errs) == 0 {
@@ -186,9 +187,10 @@ func (c *Criterion) GetCondition() (*Condition, error) {
186187
// Validate will validate the criterion object against the Arazzo specification.
187188
func (c *Criterion) Validate(opts ...validation.Option) []error {
188189
errs := []error{}
190+
core := c.GetCore()
189191

190192
if c.Condition == "" {
191-
errs = append(errs, validation.NewValueError("condition is required", c.GetCore(), c.GetCore().Condition))
193+
errs = append(errs, validation.NewValueError("condition is required", core, core.Condition))
192194
}
193195

194196
if c.Type.Type != nil {
@@ -198,19 +200,19 @@ func (c *Criterion) Validate(opts ...validation.Option) []error {
198200
case CriterionTypeJsonPath:
199201
case CriterionTypeXPath:
200202
default:
201-
errs = append(errs, validation.NewValueError(fmt.Sprintf("type must be one of [%s]", strings.Join([]string{string(CriterionTypeSimple), string(CriterionTypeRegex), string(CriterionTypeJsonPath), string(CriterionTypeXPath)}, ", ")), c.GetCore(), c.GetCore().Type))
203+
errs = append(errs, validation.NewValueError(fmt.Sprintf("type must be one of [%s]", strings.Join([]string{string(CriterionTypeSimple), string(CriterionTypeRegex), string(CriterionTypeJsonPath), string(CriterionTypeXPath)}, ", ")), core, core.Type))
202204
}
203205
} else if c.Type.ExpressionType != nil {
204206
errs = append(errs, c.Type.ExpressionType.Validate(opts...)...)
205207
}
206208

207209
if c.Type.IsTypeProvided() && c.Context == nil {
208-
errs = append(errs, validation.NewValueError("context is required, if type is set", c.GetCore(), c.GetCore().Context))
210+
errs = append(errs, validation.NewValueError("context is required, if type is set", core, core.Context))
209211
}
210212

211213
if c.Context != nil {
212214
if err := c.Context.Validate(true); err != nil {
213-
errs = append(errs, validation.NewValueError(err.Error(), c.GetCore(), c.GetCore().Context))
215+
errs = append(errs, validation.NewValueError(err.Error(), core, core.Context))
214216
}
215217
}
216218

@@ -225,26 +227,27 @@ func (c *Criterion) Validate(opts ...validation.Option) []error {
225227

226228
func (c *Criterion) validateCondition(opts ...validation.Option) []error {
227229
errs := []error{}
230+
core := c.GetCore()
228231

229-
conditionLine := c.GetCore().Condition.GetValueNodeOrRoot(c.GetCore().RootNode).Line
230-
conditionColumn := c.GetCore().Condition.GetValueNodeOrRoot(c.GetCore().RootNode).Column
232+
conditionLine := core.Condition.GetValueNodeOrRoot(core.RootNode).Line
233+
conditionColumn := core.Condition.GetValueNodeOrRoot(core.RootNode).Column
231234

232235
switch c.Type.GetType() {
233236
case CriterionTypeSimple:
234237
cond, err := newCondition(c.Condition)
235238
if err != nil && c.Context == nil {
236-
errs = append(errs, validation.NewValueError(err.Error(), c.GetCore(), c.GetCore().Condition))
239+
errs = append(errs, validation.NewValueError(err.Error(), core, core.Condition))
237240
} else if cond != nil {
238241
errs = append(errs, cond.Validate(conditionLine, conditionColumn, opts...)...)
239242
}
240243
case CriterionTypeRegex:
241244
_, err := regexp.Compile(c.Condition)
242245
if err != nil {
243-
errs = append(errs, validation.NewValueError(fmt.Errorf("invalid regex expression: %w", err).Error(), c.GetCore(), c.GetCore().Condition))
246+
errs = append(errs, validation.NewValueError(fmt.Errorf("invalid regex expression: %w", err).Error(), core, core.Condition))
244247
}
245248
case CriterionTypeJsonPath:
246249
if _, err := jsonpath.NewPath(c.Condition); err != nil {
247-
errs = append(errs, validation.NewValueError(fmt.Errorf("invalid jsonpath expression: %w", err).Error(), c.GetCore(), c.GetCore().Condition))
250+
errs = append(errs, validation.NewValueError(fmt.Errorf("invalid jsonpath expression: %w", err).Error(), core, core.Condition))
248251
}
249252
case CriterionTypeXPath:
250253
// TODO validate xpath

arazzo/failureaction.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,76 +67,77 @@ func (f *FailureAction) Validate(ctx context.Context, opts ...validation.Option)
6767
}
6868

6969
errs := []error{}
70+
core := f.GetCore()
7071

71-
if f.GetCore().Name.Present && f.Name == "" {
72-
errs = append(errs, validation.NewValueError("name is required", f.GetCore(), f.GetCore().Name))
72+
if core.Name.Present && f.Name == "" {
73+
errs = append(errs, validation.NewValueError("name is required", core, core.Name))
7374
}
7475

7576
switch f.Type {
7677
case FailureActionTypeEnd:
7778
if f.WorkflowID != nil {
78-
errs = append(errs, validation.NewValueError("workflowId is not allowed when type: end is specified", f.GetCore(), f.GetCore().WorkflowID))
79+
errs = append(errs, validation.NewValueError("workflowId is not allowed when type: end is specified", core, core.WorkflowID))
7980
}
8081
if f.StepID != nil {
81-
errs = append(errs, validation.NewValueError("stepId is not allowed when type: end is specified", f.GetCore(), f.GetCore().StepID))
82+
errs = append(errs, validation.NewValueError("stepId is not allowed when type: end is specified", core, core.StepID))
8283
}
8384
if f.RetryAfter != nil {
84-
errs = append(errs, validation.NewValueError("retryAfter is not allowed when type: end is specified", f.GetCore(), f.GetCore().RetryAfter))
85+
errs = append(errs, validation.NewValueError("retryAfter is not allowed when type: end is specified", core, core.RetryAfter))
8586
}
8687
if f.RetryLimit != nil {
87-
errs = append(errs, validation.NewValueError("retryLimit is not allowed when type: end is specified", f.GetCore(), f.GetCore().RetryLimit))
88+
errs = append(errs, validation.NewValueError("retryLimit is not allowed when type: end is specified", core, core.RetryLimit))
8889
}
8990
case FailureActionTypeGoto:
9091
errs = append(errs, validationActionWorkflowIDAndStepID(ctx, validationActionWorkflowStepIDParams{
9192
parentType: "failureAction",
9293
workflowID: f.WorkflowID,
93-
workflowIDLine: f.GetCore().WorkflowID.GetKeyNodeOrRoot(f.GetCore().RootNode).Line,
94-
workflowIDColumn: f.GetCore().WorkflowID.GetKeyNodeOrRoot(f.GetCore().RootNode).Column,
94+
workflowIDLine: core.WorkflowID.GetKeyNodeOrRoot(core.RootNode).Line,
95+
workflowIDColumn: core.WorkflowID.GetKeyNodeOrRoot(core.RootNode).Column,
9596
stepID: f.StepID,
96-
stepIDLine: f.GetCore().StepID.GetKeyNodeOrRoot(f.GetCore().RootNode).Line,
97-
stepIDColumn: f.GetCore().StepID.GetKeyNodeOrRoot(f.GetCore().RootNode).Column,
97+
stepIDLine: core.StepID.GetKeyNodeOrRoot(core.RootNode).Line,
98+
stepIDColumn: core.StepID.GetKeyNodeOrRoot(core.RootNode).Column,
9899
arazzo: a,
99100
workflow: validation.GetContextObject[Workflow](o),
100101
required: true,
101102
}, opts...)...)
102103
if f.RetryAfter != nil {
103-
errs = append(errs, validation.NewValueError("retryAfter is not allowed when type: goto is specified", f.GetCore(), f.GetCore().RetryAfter))
104+
errs = append(errs, validation.NewValueError("retryAfter is not allowed when type: goto is specified", core, core.RetryAfter))
104105
}
105106
if f.RetryLimit != nil {
106-
errs = append(errs, validation.NewValueError("retryLimit is not allowed when type: goto is specified", f.GetCore(), f.GetCore().RetryLimit))
107+
errs = append(errs, validation.NewValueError("retryLimit is not allowed when type: goto is specified", core, core.RetryLimit))
107108
}
108109
case FailureActionTypeRetry:
109110
errs = append(errs, validationActionWorkflowIDAndStepID(ctx, validationActionWorkflowStepIDParams{
110111
parentType: "failureAction",
111112
workflowID: f.WorkflowID,
112-
workflowIDLine: f.GetCore().WorkflowID.GetKeyNodeOrRoot(f.GetCore().RootNode).Line,
113-
workflowIDColumn: f.GetCore().WorkflowID.GetKeyNodeOrRoot(f.GetCore().RootNode).Column,
113+
workflowIDLine: core.WorkflowID.GetKeyNodeOrRoot(core.RootNode).Line,
114+
workflowIDColumn: core.WorkflowID.GetKeyNodeOrRoot(core.RootNode).Column,
114115
stepID: f.StepID,
115-
stepIDLine: f.GetCore().StepID.GetKeyNodeOrRoot(f.GetCore().RootNode).Line,
116-
stepIDColumn: f.GetCore().StepID.GetKeyNodeOrRoot(f.GetCore().RootNode).Column,
116+
stepIDLine: core.StepID.GetKeyNodeOrRoot(core.RootNode).Line,
117+
stepIDColumn: core.StepID.GetKeyNodeOrRoot(core.RootNode).Column,
117118
arazzo: a,
118119
workflow: validation.GetContextObject[Workflow](o),
119120
required: false,
120121
}, opts...)...)
121122
if f.RetryAfter != nil {
122123
if *f.RetryAfter < 0 {
123-
errs = append(errs, validation.NewValueError("retryAfter must be greater than or equal to 0", f.GetCore(), f.GetCore().RetryAfter))
124+
errs = append(errs, validation.NewValueError("retryAfter must be greater than or equal to 0", core, core.RetryAfter))
124125
}
125126
}
126127
if f.RetryLimit != nil {
127128
if *f.RetryLimit < 0 {
128-
errs = append(errs, validation.NewValueError("retryLimit must be greater than or equal to 0", f.GetCore(), f.GetCore().RetryLimit))
129+
errs = append(errs, validation.NewValueError("retryLimit must be greater than or equal to 0", core, core.RetryLimit))
129130
}
130131
}
131132
default:
132-
errs = append(errs, validation.NewValueError(fmt.Sprintf("type must be one of [%s]", strings.Join([]string{string(FailureActionTypeEnd), string(FailureActionTypeGoto), string(FailureActionTypeRetry)}, ", ")), f.GetCore(), f.GetCore().Type))
133+
errs = append(errs, validation.NewValueError(fmt.Sprintf("type must be one of [%s]", strings.Join([]string{string(FailureActionTypeEnd), string(FailureActionTypeGoto), string(FailureActionTypeRetry)}, ", ")), core, core.Type))
133134
}
134135

135136
for _, criterion := range f.Criteria {
136137
errs = append(errs, criterion.Validate(opts...)...)
137138
}
138139

139-
f.Valid = len(errs) == 0 && f.GetCore().GetValid()
140+
f.Valid = len(errs) == 0 && core.GetValid()
140141

141142
return errs
142143
}

arazzo/info.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@ var _ interfaces.Model[core.Info] = (*Info)(nil)
3131
// Validate will validate the Info object against the Arazzo Specification.
3232
func (i *Info) Validate(ctx context.Context, opts ...validation.Option) []error {
3333
errs := []error{}
34+
core := i.GetCore()
3435

35-
if i.GetCore().Title.Present && i.Title == "" {
36-
errs = append(errs, validation.NewValueError("title is required", i.GetCore(), i.GetCore().Title))
36+
if core.Title.Present && i.Title == "" {
37+
errs = append(errs, validation.NewValueError("title is required", core, core.Title))
3738
}
3839

39-
if i.GetCore().Version.Present && i.Version == "" {
40-
errs = append(errs, validation.NewValueError("version is required", i.GetCore(), i.GetCore().Version))
40+
if core.Version.Present && i.Version == "" {
41+
errs = append(errs, validation.NewValueError("version is required", core, core.Version))
4142
}
4243

43-
i.Valid = len(errs) == 0 && i.GetCore().GetValid()
44+
i.Valid = len(errs) == 0 && core.GetValid()
4445

4546
return errs
4647
}

arazzo/parameter.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ func (p *Parameter) Validate(ctx context.Context, opts ...validation.Option) []e
5252

5353
w := validation.GetContextObject[Workflow](o)
5454
s := validation.GetContextObject[Step](o)
55+
core := p.GetCore()
5556

56-
if p.GetCore().Name.Present && p.Name == "" {
57-
errs = append(errs, validation.NewValueError("name is required", p.GetCore(), p.GetCore().Name))
57+
if core.Name.Present && p.Name == "" {
58+
errs = append(errs, validation.NewValueError("name is required", core, core.Name))
5859
}
5960

6061
in := In("")
@@ -70,30 +71,30 @@ func (p *Parameter) Validate(ctx context.Context, opts ...validation.Option) []e
7071
default:
7172
if p.In == nil || in == "" {
7273
if w == nil && s != nil && s.WorkflowID == nil {
73-
errs = append(errs, validation.NewValueError("in is required within a step when workflowId is not set", p.GetCore(), p.GetCore().In))
74+
errs = append(errs, validation.NewValueError("in is required within a step when workflowId is not set", core, core.In))
7475
}
7576
}
7677

7778
if in != "" {
78-
errs = append(errs, validation.NewValueError(fmt.Sprintf("in must be one of [%s] but was %s", strings.Join([]string{string(InPath), string(InQuery), string(InHeader), string(InCookie)}, ", "), in), p.GetCore(), p.GetCore().In))
79+
errs = append(errs, validation.NewValueError(fmt.Sprintf("in must be one of [%s] but was %s", strings.Join([]string{string(InPath), string(InQuery), string(InHeader), string(InCookie)}, ", "), in), core, core.In))
7980
}
8081
}
8182

82-
if p.GetCore().Value.Present && p.Value == nil {
83-
errs = append(errs, validation.NewValueError("value is required", p.GetCore(), p.GetCore().Value))
83+
if core.Value.Present && p.Value == nil {
84+
errs = append(errs, validation.NewValueError("value is required", core, core.Value))
8485
} else if p.Value != nil {
8586
_, expression, err := GetValueOrExpressionValue(p.Value)
8687
if err != nil {
87-
errs = append(errs, validation.NewValueError(err.Error(), p.GetCore(), p.GetCore().Value))
88+
errs = append(errs, validation.NewValueError(err.Error(), core, core.Value))
8889
}
8990
if expression != nil {
9091
if err := expression.Validate(true); err != nil {
91-
errs = append(errs, validation.NewValueError(err.Error(), p.GetCore(), p.GetCore().Value))
92+
errs = append(errs, validation.NewValueError(err.Error(), core, core.Value))
9293
}
9394
}
9495
}
9596

96-
p.Valid = len(errs) == 0 && p.GetCore().GetValid()
97+
p.Valid = len(errs) == 0 && core.GetValid()
9798

9899
return errs
99100
}

arazzo/payloadreplacement.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,31 @@ var _ interfaces.Model[core.PayloadReplacement] = (*PayloadReplacement)(nil)
2828
// Validate will validate the payload replacement object against the Arazzo specification.
2929
func (p *PayloadReplacement) Validate(ctx context.Context, opts ...validation.Option) []error {
3030
errs := []error{}
31+
core := p.GetCore()
3132

32-
if p.GetCore().Target.Present && p.Target == "" {
33-
errs = append(errs, validation.NewValueError("target is required", p.GetCore(), p.GetCore().Target))
33+
if core.Target.Present && p.Target == "" {
34+
errs = append(errs, validation.NewValueError("target is required", core, core.Target))
3435
}
3536

3637
if err := p.Target.Validate(); err != nil {
37-
errs = append(errs, validation.NewValueError(err.Error(), p.GetCore(), p.GetCore().Target))
38+
errs = append(errs, validation.NewValueError(err.Error(), core, core.Target))
3839
}
3940

40-
if p.GetCore().Value.Present && p.Value == nil {
41-
errs = append(errs, validation.NewValueError("value is required", p.GetCore(), p.GetCore().Value))
41+
if core.Value.Present && p.Value == nil {
42+
errs = append(errs, validation.NewValueError("value is required", core, core.Value))
4243
} else if p.Value != nil {
4344
_, expression, err := GetValueOrExpressionValue(p.Value)
4445
if err != nil {
45-
errs = append(errs, validation.NewValueError(err.Error(), p.GetCore(), p.GetCore().Value))
46+
errs = append(errs, validation.NewValueError(err.Error(), core, core.Value))
4647
}
4748
if expression != nil {
4849
if err := expression.Validate(true); err != nil {
49-
errs = append(errs, validation.NewValueError(err.Error(), p.GetCore(), p.GetCore().Value))
50+
errs = append(errs, validation.NewValueError(err.Error(), core, core.Value))
5051
}
5152
}
5253
}
5354

54-
p.Valid = len(errs) == 0 && p.GetCore().GetValid()
55+
p.Valid = len(errs) == 0 && core.GetValid()
5556

5657
return errs
5758
}

0 commit comments

Comments
 (0)