Skip to content

Commit 03a52fd

Browse files
Merge pull request #2 from speakeasy-api/improvements
2 parents 77166e4 + 4b404ff commit 03a52fd

29 files changed

+439
-148
lines changed

arazzo/arazzo.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// package arazzo provides an API for working with Arazzo documents including reading, creating, mutating, walking and validating them.
1+
// Package arazzo provides an API for working with Arazzo documents including reading, creating, mutating, walking and validating them.
22
//
33
// The Arazzo Specification is a mechanism for orchestrating API calls, defining their sequences and dependencies, to achieve specific outcomes when working with API descriptions like OpenAPI.
44
package arazzo
@@ -35,6 +35,9 @@ type Arazzo struct {
3535
// Extensions provides a list of extensions to the Arazzo document.
3636
Extensions *extensions.Extensions
3737

38+
// Valid indicates whether this model passed validation.
39+
Valid bool
40+
3841
core core.Arazzo
3942
}
4043

@@ -183,5 +186,9 @@ func (a *Arazzo) Validate(ctx context.Context, opts ...validation.Option) []erro
183186
errs = append(errs, a.Components.Validate(ctx, opts...)...)
184187
}
185188

189+
if len(errs) == 0 {
190+
a.Valid = true
191+
}
192+
186193
return errs
187194
}

arazzo/arazzo_test.go

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ var testArazzoInstance = &arazzo.Arazzo{
4141
Line: 6,
4242
Column: 11,
4343
})),
44+
Valid: true,
4445
},
45-
SourceDescriptions: []arazzo.SourceDescription{
46+
SourceDescriptions: []*arazzo.SourceDescription{
4647
{
4748
Name: "openapi",
4849
URL: "https://openapi.com",
@@ -54,38 +55,44 @@ var testArazzoInstance = &arazzo.Arazzo{
5455
Line: 11,
5556
Column: 13,
5657
})),
58+
Valid: true,
5759
},
5860
},
59-
Workflows: []arazzo.Workflow{
61+
Workflows: []*arazzo.Workflow{
6062
{
6163
WorkflowID: "workflow1",
6264
Summary: pointer.From("A summary"),
6365
Description: pointer.From("A description"),
64-
Parameters: []arazzo.ReusableParameter{
66+
Parameters: []*arazzo.ReusableParameter{
6567
{
6668
Object: &arazzo.Parameter{
6769
Name: "parameter1",
6870
In: pointer.From(arazzo.InQuery),
6971
Value: &yaml.Node{Value: "123", Kind: yaml.ScalarNode, Tag: "!!str", Line: 19, Column: 16, Style: yaml.DoubleQuotedStyle},
72+
Valid: true,
7073
},
74+
Valid: true,
7175
},
7276
},
7377
Inputs: oas31.NewJSONSchemaFromSchema(&oas31.Schema{
7478
Type: oas31.NewTypeFromString("object"),
7579
Properties: sequencedmap.New(sequencedmap.NewElem("input1", oas31.NewJSONSchemaFromSchema(&oas31.Schema{
76-
Type: oas31.NewTypeFromString("string"),
80+
Type: oas31.NewTypeFromString("string"),
81+
Valid: true,
7782
}))),
7883
Required: []string{"input1"},
84+
Valid: true,
7985
}),
80-
Steps: []arazzo.Step{
86+
Steps: []*arazzo.Step{
8187
{
8288
StepID: "step1",
8389
Description: pointer.From("A description"),
8490
OperationID: pointer.From[expression.Expression]("operation1"),
85-
Parameters: []arazzo.ReusableParameter{
91+
Parameters: []*arazzo.ReusableParameter{
8692
{
8793
Reference: pointer.From[expression.Expression]("$components.parameters.userId"),
8894
Value: &yaml.Node{Value: "456", Kind: yaml.ScalarNode, Tag: "!!str", Style: yaml.DoubleQuotedStyle, Line: 33, Column: 20},
95+
Valid: true,
8996
},
9097
},
9198
RequestBody: &arazzo.RequestBody{
@@ -122,52 +129,62 @@ var testArazzoInstance = &arazzo.Arazzo{
122129
Column: 34,
123130
},
124131
}, Kind: yaml.MappingNode, Tag: "!!map", Style: yaml.FlowStyle, Line: 36, Column: 20},
125-
Replacements: []arazzo.PayloadReplacement{
132+
Replacements: []*arazzo.PayloadReplacement{
126133
{
127134
Target: jsonpointer.JSONPointer("/b"),
128135
Value: &yaml.Node{Value: "3", Kind: yaml.ScalarNode, Tag: "!!int", Line: 39, Column: 22},
136+
Valid: true,
129137
},
130138
},
139+
Valid: true,
131140
},
132-
SuccessCriteria: []criterion.Criterion{{Condition: "$statusCode == 200", Type: criterion.CriterionTypeUnion{}}},
133-
OnSuccess: []arazzo.ReusableSuccessAction{
141+
SuccessCriteria: []*criterion.Criterion{{Condition: "$statusCode == 200", Type: criterion.CriterionTypeUnion{}, Valid: true}},
142+
OnSuccess: []*arazzo.ReusableSuccessAction{
134143
{
135144
Reference: pointer.From[expression.Expression]("$components.successActions.success"),
145+
Valid: true,
136146
},
137147
},
138-
OnFailure: []arazzo.ReusableFailureAction{
148+
OnFailure: []*arazzo.ReusableFailureAction{
139149
{
140150
Reference: pointer.From[expression.Expression]("$components.failureActions.failure"),
151+
Valid: true,
141152
},
142153
},
143154
Outputs: sequencedmap.New(sequencedmap.NewElem[string, expression.Expression]("name", "$response.body#/name")),
155+
Valid: true,
144156
},
145157
},
146158
Outputs: sequencedmap.New(sequencedmap.NewElem[string, expression.Expression]("name", "$steps.step1.outputs.name")),
159+
Valid: true,
147160
},
148161
},
149162
Components: &arazzo.Components{
150-
Parameters: sequencedmap.New(sequencedmap.NewElem("userId", arazzo.Parameter{
163+
Parameters: sequencedmap.New(sequencedmap.NewElem("userId", &arazzo.Parameter{
151164
Name: "userId",
152165
In: pointer.From(arazzo.InQuery),
153166
Value: &yaml.Node{Value: "123", Kind: yaml.ScalarNode, Tag: "!!str"},
167+
Valid: true,
154168
})),
155-
SuccessActions: sequencedmap.New(sequencedmap.NewElem("success", arazzo.SuccessAction{
169+
SuccessActions: sequencedmap.New(sequencedmap.NewElem("success", &arazzo.SuccessAction{
156170
Name: "success",
157171
Type: arazzo.SuccessActionTypeEnd,
158172
Criteria: []criterion.Criterion{{Context: pointer.From(expression.Expression("$statusCode")), Condition: "$statusCode == 200", Type: criterion.CriterionTypeUnion{
159173
Type: pointer.From(criterion.CriterionTypeSimple),
160174
}}},
175+
Valid: true,
161176
})),
162-
FailureActions: sequencedmap.New(sequencedmap.NewElem("failure", arazzo.FailureAction{
177+
FailureActions: sequencedmap.New(sequencedmap.NewElem("failure", &arazzo.FailureAction{
163178
Name: "failure",
164179
Type: arazzo.FailureActionTypeRetry,
165180
RetryAfter: pointer.From(10.0),
166181
RetryLimit: pointer.From(3),
167182
Criteria: []criterion.Criterion{{Condition: "$statusCode == 500", Type: criterion.CriterionTypeUnion{
168183
Type: pointer.From(criterion.CriterionTypeSimple),
169184
}}},
185+
Valid: true,
170186
})),
187+
Valid: true,
171188
},
172189
Extensions: extensions.New(extensions.NewElem("x-test", &yaml.Node{
173190
Value: "some-value",
@@ -176,6 +193,7 @@ var testArazzoInstance = &arazzo.Arazzo{
176193
Line: 72,
177194
Column: 9,
178195
})),
196+
Valid: true,
179197
}
180198

181199
func TestArazzo_Unmarshal_Success(t *testing.T) {
@@ -247,8 +265,9 @@ sourceDescriptions:
247265
Info: arazzo.Info{
248266
Title: "My Workflow",
249267
Version: "",
268+
Valid: true,
250269
},
251-
SourceDescriptions: []arazzo.SourceDescription{
270+
SourceDescriptions: []*arazzo.SourceDescription{
252271
{
253272
Name: "openapi",
254273
Type: "openapis",
@@ -406,7 +425,7 @@ workflows: []
406425
a.Extensions = extensions.New()
407426
a.Info.Summary = nil
408427
a.Info.Extensions = extensions.New()
409-
a.SourceDescriptions = []arazzo.SourceDescription{}
428+
a.SourceDescriptions = []*arazzo.SourceDescription{}
410429

411430
outBuf := bytes.NewBuffer([]byte{})
412431

arazzo/components.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ type Components struct {
1717
// Inputs provides a list of reusable JSON Schemas that can be referenced from inputs and other JSON Schemas.
1818
Inputs *sequencedmap.Map[string, oas31.JSONSchema]
1919
// Parameters provides a list of reusable parameters that can be referenced from workflows and steps.
20-
Parameters *sequencedmap.Map[string, Parameter]
20+
Parameters *sequencedmap.Map[string, *Parameter]
2121
// SuccessActions provides a list of reusable success actions that can be referenced from workflows and steps.
22-
SuccessActions *sequencedmap.Map[string, SuccessAction]
22+
SuccessActions *sequencedmap.Map[string, *SuccessAction]
2323
// FailureActions provides a list of reusable failure actions that can be referenced from workflows and steps.
24-
FailureActions *sequencedmap.Map[string, FailureAction]
24+
FailureActions *sequencedmap.Map[string, *FailureAction]
2525
// Extensions provides a list of extensions to the Components object.
2626
Extensions *extensions.Extensions
2727

28+
// Valid indicates whether this model passed validation.
29+
Valid bool
30+
2831
core core.Components
2932
}
3033

@@ -104,5 +107,9 @@ func (c *Components) Validate(ctx context.Context, opts ...validation.Option) []
104107
errs = append(errs, failureAction.Validate(ctx, failureActionOps...)...)
105108
}
106109

110+
if len(errs) == 0 {
111+
c.Valid = true
112+
}
113+
107114
return errs
108115
}

arazzo/core/arazzo.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import (
1313
)
1414

1515
type Arazzo struct {
16-
Arazzo marshaller.Node[string] `key:"arazzo"`
17-
Info marshaller.Node[Info] `key:"info"`
18-
SourceDescriptions marshaller.Node[[]SourceDescription] `key:"sourceDescriptions" required:"true"`
19-
Workflows marshaller.Node[[]Workflow] `key:"workflows" required:"true"`
20-
Components marshaller.Node[*Components] `key:"components"`
21-
Extensions core.Extensions `key:"extensions"`
16+
Arazzo marshaller.Node[string] `key:"arazzo"`
17+
Info marshaller.Node[Info] `key:"info"`
18+
SourceDescriptions marshaller.Node[[]*SourceDescription] `key:"sourceDescriptions" required:"true"`
19+
Workflows marshaller.Node[[]*Workflow] `key:"workflows" required:"true"`
20+
Components marshaller.Node[*Components] `key:"components"`
21+
Extensions core.Extensions `key:"extensions"`
2222

2323
RootNode *yaml.Node
2424
Config *yml.Config

arazzo/core/components.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212

1313
type Components struct {
1414
Inputs marshaller.Node[*sequencedmap.Map[string, core.JSONSchema]] `key:"inputs"`
15-
Parameters marshaller.Node[*sequencedmap.Map[string, Parameter]] `key:"parameters"`
16-
SuccessActions marshaller.Node[*sequencedmap.Map[string, SuccessAction]] `key:"successActions"`
17-
FailureActions marshaller.Node[*sequencedmap.Map[string, FailureAction]] `key:"failureActions"`
15+
Parameters marshaller.Node[*sequencedmap.Map[string, *Parameter]] `key:"parameters"`
16+
SuccessActions marshaller.Node[*sequencedmap.Map[string, *SuccessAction]] `key:"successActions"`
17+
FailureActions marshaller.Node[*sequencedmap.Map[string, *FailureAction]] `key:"failureActions"`
1818
Extensions coreExtensions.Extensions `key:"extensions"`
1919

2020
RootNode *yaml.Node

arazzo/core/failureaction.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99
)
1010

1111
type FailureAction struct {
12-
Name marshaller.Node[string] `key:"name"`
13-
Type marshaller.Node[string] `key:"type"`
14-
WorkflowID marshaller.Node[*Expression] `key:"workflowId"`
15-
StepID marshaller.Node[*string] `key:"stepId"`
16-
RetryAfter marshaller.Node[*float64] `key:"retryAfter"`
17-
RetryLimit marshaller.Node[*int] `key:"retryLimit"`
18-
Criteria marshaller.Node[[]Criterion] `key:"criteria"`
19-
Extensions core.Extensions `key:"extensions"`
12+
Name marshaller.Node[string] `key:"name"`
13+
Type marshaller.Node[string] `key:"type"`
14+
WorkflowID marshaller.Node[*Expression] `key:"workflowId"`
15+
StepID marshaller.Node[*string] `key:"stepId"`
16+
RetryAfter marshaller.Node[*float64] `key:"retryAfter"`
17+
RetryLimit marshaller.Node[*int] `key:"retryLimit"`
18+
Criteria marshaller.Node[[]*Criterion] `key:"criteria"`
19+
Extensions core.Extensions `key:"extensions"`
2020

2121
RootNode *yaml.Node
2222
}

arazzo/core/requestbody.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
)
1010

1111
type RequestBody struct {
12-
ContentType marshaller.Node[*string] `key:"contentType"`
13-
Payload marshaller.Node[ValueOrExpression] `key:"payload"`
14-
Replacements marshaller.Node[[]PayloadReplacement] `key:"replacements"`
15-
Extensions core.Extensions `key:"extensions"`
12+
ContentType marshaller.Node[*string] `key:"contentType"`
13+
Payload marshaller.Node[ValueOrExpression] `key:"payload"`
14+
Replacements marshaller.Node[[]*PayloadReplacement] `key:"replacements"`
15+
Extensions core.Extensions `key:"extensions"`
1616

1717
RootNode *yaml.Node
1818
}

arazzo/core/step.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ import (
99
)
1010

1111
type Step struct {
12-
StepID marshaller.Node[string] `key:"stepId"`
13-
Description marshaller.Node[*string] `key:"description"`
14-
OperationID marshaller.Node[*Expression] `key:"operationId"`
15-
OperationPath marshaller.Node[*string] `key:"operationPath"`
16-
WorkflowID marshaller.Node[*Expression] `key:"workflowId"`
17-
Parameters marshaller.Node[[]Reusable[Parameter]] `key:"parameters"`
18-
RequestBody marshaller.Node[*RequestBody] `key:"requestBody"`
19-
SuccessCriteria marshaller.Node[[]Criterion] `key:"successCriteria"`
20-
OnSuccess marshaller.Node[[]Reusable[SuccessAction]] `key:"onSuccess"`
21-
OnFailure marshaller.Node[[]Reusable[FailureAction]] `key:"onFailure"`
22-
Outputs marshaller.Node[Outputs] `key:"outputs"`
23-
Extensions core.Extensions `key:"extensions"`
12+
StepID marshaller.Node[string] `key:"stepId"`
13+
Description marshaller.Node[*string] `key:"description"`
14+
OperationID marshaller.Node[*Expression] `key:"operationId"`
15+
OperationPath marshaller.Node[*string] `key:"operationPath"`
16+
WorkflowID marshaller.Node[*Expression] `key:"workflowId"`
17+
Parameters marshaller.Node[[]*Reusable[Parameter]] `key:"parameters"`
18+
RequestBody marshaller.Node[*RequestBody] `key:"requestBody"`
19+
SuccessCriteria marshaller.Node[[]*Criterion] `key:"successCriteria"`
20+
OnSuccess marshaller.Node[[]*Reusable[SuccessAction]] `key:"onSuccess"`
21+
OnFailure marshaller.Node[[]*Reusable[FailureAction]] `key:"onFailure"`
22+
Outputs marshaller.Node[Outputs] `key:"outputs"`
23+
Extensions core.Extensions `key:"extensions"`
2424

2525
RootNode *yaml.Node
2626
}

arazzo/core/successaction.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import (
99
)
1010

1111
type SuccessAction struct {
12-
Name marshaller.Node[string] `key:"name"`
13-
Type marshaller.Node[string] `key:"type"`
14-
WorkflowID marshaller.Node[*Expression] `key:"workflowId"`
15-
StepID marshaller.Node[*string] `key:"stepId"`
16-
Criteria marshaller.Node[[]Criterion] `key:"criteria"`
17-
Extensions core.Extensions `key:"extensions"`
12+
Name marshaller.Node[string] `key:"name"`
13+
Type marshaller.Node[string] `key:"type"`
14+
WorkflowID marshaller.Node[*Expression] `key:"workflowId"`
15+
StepID marshaller.Node[*string] `key:"stepId"`
16+
Criteria marshaller.Node[[]*Criterion] `key:"criteria"`
17+
Extensions core.Extensions `key:"extensions"`
1818

1919
RootNode *yaml.Node
2020
}

arazzo/core/workflow.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import (
1010
)
1111

1212
type Workflow struct {
13-
WorkflowID marshaller.Node[string] `key:"workflowId"`
14-
Summary marshaller.Node[*string] `key:"summary"`
15-
Description marshaller.Node[*string] `key:"description"`
16-
Parameters marshaller.Node[[]Reusable[Parameter]] `key:"parameters"`
17-
Inputs marshaller.Node[core.JSONSchema] `key:"inputs"`
18-
DependsOn marshaller.Node[[]Expression] `key:"dependsOn"`
19-
Steps marshaller.Node[[]Step] `key:"steps" required:"true"`
20-
SuccessActions marshaller.Node[[]Reusable[SuccessAction]] `key:"successActions"`
21-
FailureActions marshaller.Node[[]Reusable[FailureAction]] `key:"failureActions"`
22-
Outputs marshaller.Node[Outputs] `key:"outputs"`
23-
Extensions coreExtensions.Extensions `key:"extensions"`
13+
WorkflowID marshaller.Node[string] `key:"workflowId"`
14+
Summary marshaller.Node[*string] `key:"summary"`
15+
Description marshaller.Node[*string] `key:"description"`
16+
Parameters marshaller.Node[[]*Reusable[Parameter]] `key:"parameters"`
17+
Inputs marshaller.Node[core.JSONSchema] `key:"inputs"`
18+
DependsOn marshaller.Node[[]Expression] `key:"dependsOn"`
19+
Steps marshaller.Node[[]*Step] `key:"steps" required:"true"`
20+
SuccessActions marshaller.Node[[]*Reusable[SuccessAction]] `key:"successActions"`
21+
FailureActions marshaller.Node[[]*Reusable[FailureAction]] `key:"failureActions"`
22+
Outputs marshaller.Node[Outputs] `key:"outputs"`
23+
Extensions coreExtensions.Extensions `key:"extensions"`
2424

2525
RootNode *yaml.Node
2626
}

0 commit comments

Comments
 (0)