Skip to content

Commit

Permalink
Merge pull request #2 from speakeasy-api/improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanSpeakEasy authored Oct 30, 2024
2 parents 77166e4 + 4b404ff commit 03a52fd
Show file tree
Hide file tree
Showing 29 changed files with 439 additions and 148 deletions.
9 changes: 8 additions & 1 deletion arazzo/arazzo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// package arazzo provides an API for working with Arazzo documents including reading, creating, mutating, walking and validating them.
// Package arazzo provides an API for working with Arazzo documents including reading, creating, mutating, walking and validating them.
//
// 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.
package arazzo
Expand Down Expand Up @@ -35,6 +35,9 @@ type Arazzo struct {
// Extensions provides a list of extensions to the Arazzo document.
Extensions *extensions.Extensions

// Valid indicates whether this model passed validation.
Valid bool

core core.Arazzo
}

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

if len(errs) == 0 {
a.Valid = true
}

return errs
}
49 changes: 34 additions & 15 deletions arazzo/arazzo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ var testArazzoInstance = &arazzo.Arazzo{
Line: 6,
Column: 11,
})),
Valid: true,
},
SourceDescriptions: []arazzo.SourceDescription{
SourceDescriptions: []*arazzo.SourceDescription{
{
Name: "openapi",
URL: "https://openapi.com",
Expand All @@ -54,38 +55,44 @@ var testArazzoInstance = &arazzo.Arazzo{
Line: 11,
Column: 13,
})),
Valid: true,
},
},
Workflows: []arazzo.Workflow{
Workflows: []*arazzo.Workflow{
{
WorkflowID: "workflow1",
Summary: pointer.From("A summary"),
Description: pointer.From("A description"),
Parameters: []arazzo.ReusableParameter{
Parameters: []*arazzo.ReusableParameter{
{
Object: &arazzo.Parameter{
Name: "parameter1",
In: pointer.From(arazzo.InQuery),
Value: &yaml.Node{Value: "123", Kind: yaml.ScalarNode, Tag: "!!str", Line: 19, Column: 16, Style: yaml.DoubleQuotedStyle},
Valid: true,
},
Valid: true,
},
},
Inputs: oas31.NewJSONSchemaFromSchema(&oas31.Schema{
Type: oas31.NewTypeFromString("object"),
Properties: sequencedmap.New(sequencedmap.NewElem("input1", oas31.NewJSONSchemaFromSchema(&oas31.Schema{
Type: oas31.NewTypeFromString("string"),
Type: oas31.NewTypeFromString("string"),
Valid: true,
}))),
Required: []string{"input1"},
Valid: true,
}),
Steps: []arazzo.Step{
Steps: []*arazzo.Step{
{
StepID: "step1",
Description: pointer.From("A description"),
OperationID: pointer.From[expression.Expression]("operation1"),
Parameters: []arazzo.ReusableParameter{
Parameters: []*arazzo.ReusableParameter{
{
Reference: pointer.From[expression.Expression]("$components.parameters.userId"),
Value: &yaml.Node{Value: "456", Kind: yaml.ScalarNode, Tag: "!!str", Style: yaml.DoubleQuotedStyle, Line: 33, Column: 20},
Valid: true,
},
},
RequestBody: &arazzo.RequestBody{
Expand Down Expand Up @@ -122,52 +129,62 @@ var testArazzoInstance = &arazzo.Arazzo{
Column: 34,
},
}, Kind: yaml.MappingNode, Tag: "!!map", Style: yaml.FlowStyle, Line: 36, Column: 20},
Replacements: []arazzo.PayloadReplacement{
Replacements: []*arazzo.PayloadReplacement{
{
Target: jsonpointer.JSONPointer("/b"),
Value: &yaml.Node{Value: "3", Kind: yaml.ScalarNode, Tag: "!!int", Line: 39, Column: 22},
Valid: true,
},
},
Valid: true,
},
SuccessCriteria: []criterion.Criterion{{Condition: "$statusCode == 200", Type: criterion.CriterionTypeUnion{}}},
OnSuccess: []arazzo.ReusableSuccessAction{
SuccessCriteria: []*criterion.Criterion{{Condition: "$statusCode == 200", Type: criterion.CriterionTypeUnion{}, Valid: true}},
OnSuccess: []*arazzo.ReusableSuccessAction{
{
Reference: pointer.From[expression.Expression]("$components.successActions.success"),
Valid: true,
},
},
OnFailure: []arazzo.ReusableFailureAction{
OnFailure: []*arazzo.ReusableFailureAction{
{
Reference: pointer.From[expression.Expression]("$components.failureActions.failure"),
Valid: true,
},
},
Outputs: sequencedmap.New(sequencedmap.NewElem[string, expression.Expression]("name", "$response.body#/name")),
Valid: true,
},
},
Outputs: sequencedmap.New(sequencedmap.NewElem[string, expression.Expression]("name", "$steps.step1.outputs.name")),
Valid: true,
},
},
Components: &arazzo.Components{
Parameters: sequencedmap.New(sequencedmap.NewElem("userId", arazzo.Parameter{
Parameters: sequencedmap.New(sequencedmap.NewElem("userId", &arazzo.Parameter{
Name: "userId",
In: pointer.From(arazzo.InQuery),
Value: &yaml.Node{Value: "123", Kind: yaml.ScalarNode, Tag: "!!str"},
Valid: true,
})),
SuccessActions: sequencedmap.New(sequencedmap.NewElem("success", arazzo.SuccessAction{
SuccessActions: sequencedmap.New(sequencedmap.NewElem("success", &arazzo.SuccessAction{
Name: "success",
Type: arazzo.SuccessActionTypeEnd,
Criteria: []criterion.Criterion{{Context: pointer.From(expression.Expression("$statusCode")), Condition: "$statusCode == 200", Type: criterion.CriterionTypeUnion{
Type: pointer.From(criterion.CriterionTypeSimple),
}}},
Valid: true,
})),
FailureActions: sequencedmap.New(sequencedmap.NewElem("failure", arazzo.FailureAction{
FailureActions: sequencedmap.New(sequencedmap.NewElem("failure", &arazzo.FailureAction{
Name: "failure",
Type: arazzo.FailureActionTypeRetry,
RetryAfter: pointer.From(10.0),
RetryLimit: pointer.From(3),
Criteria: []criterion.Criterion{{Condition: "$statusCode == 500", Type: criterion.CriterionTypeUnion{
Type: pointer.From(criterion.CriterionTypeSimple),
}}},
Valid: true,
})),
Valid: true,
},
Extensions: extensions.New(extensions.NewElem("x-test", &yaml.Node{
Value: "some-value",
Expand All @@ -176,6 +193,7 @@ var testArazzoInstance = &arazzo.Arazzo{
Line: 72,
Column: 9,
})),
Valid: true,
}

func TestArazzo_Unmarshal_Success(t *testing.T) {
Expand Down Expand Up @@ -247,8 +265,9 @@ sourceDescriptions:
Info: arazzo.Info{
Title: "My Workflow",
Version: "",
Valid: true,
},
SourceDescriptions: []arazzo.SourceDescription{
SourceDescriptions: []*arazzo.SourceDescription{
{
Name: "openapi",
Type: "openapis",
Expand Down Expand Up @@ -406,7 +425,7 @@ workflows: []
a.Extensions = extensions.New()
a.Info.Summary = nil
a.Info.Extensions = extensions.New()
a.SourceDescriptions = []arazzo.SourceDescription{}
a.SourceDescriptions = []*arazzo.SourceDescription{}

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

Expand Down
13 changes: 10 additions & 3 deletions arazzo/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ type Components struct {
// Inputs provides a list of reusable JSON Schemas that can be referenced from inputs and other JSON Schemas.
Inputs *sequencedmap.Map[string, oas31.JSONSchema]
// Parameters provides a list of reusable parameters that can be referenced from workflows and steps.
Parameters *sequencedmap.Map[string, Parameter]
Parameters *sequencedmap.Map[string, *Parameter]
// SuccessActions provides a list of reusable success actions that can be referenced from workflows and steps.
SuccessActions *sequencedmap.Map[string, SuccessAction]
SuccessActions *sequencedmap.Map[string, *SuccessAction]
// FailureActions provides a list of reusable failure actions that can be referenced from workflows and steps.
FailureActions *sequencedmap.Map[string, FailureAction]
FailureActions *sequencedmap.Map[string, *FailureAction]
// Extensions provides a list of extensions to the Components object.
Extensions *extensions.Extensions

// Valid indicates whether this model passed validation.
Valid bool

core core.Components
}

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

if len(errs) == 0 {
c.Valid = true
}

return errs
}
12 changes: 6 additions & 6 deletions arazzo/core/arazzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
)

type Arazzo struct {
Arazzo marshaller.Node[string] `key:"arazzo"`
Info marshaller.Node[Info] `key:"info"`
SourceDescriptions marshaller.Node[[]SourceDescription] `key:"sourceDescriptions" required:"true"`
Workflows marshaller.Node[[]Workflow] `key:"workflows" required:"true"`
Components marshaller.Node[*Components] `key:"components"`
Extensions core.Extensions `key:"extensions"`
Arazzo marshaller.Node[string] `key:"arazzo"`
Info marshaller.Node[Info] `key:"info"`
SourceDescriptions marshaller.Node[[]*SourceDescription] `key:"sourceDescriptions" required:"true"`
Workflows marshaller.Node[[]*Workflow] `key:"workflows" required:"true"`
Components marshaller.Node[*Components] `key:"components"`
Extensions core.Extensions `key:"extensions"`

RootNode *yaml.Node
Config *yml.Config
Expand Down
6 changes: 3 additions & 3 deletions arazzo/core/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (

type Components struct {
Inputs marshaller.Node[*sequencedmap.Map[string, core.JSONSchema]] `key:"inputs"`
Parameters marshaller.Node[*sequencedmap.Map[string, Parameter]] `key:"parameters"`
SuccessActions marshaller.Node[*sequencedmap.Map[string, SuccessAction]] `key:"successActions"`
FailureActions marshaller.Node[*sequencedmap.Map[string, FailureAction]] `key:"failureActions"`
Parameters marshaller.Node[*sequencedmap.Map[string, *Parameter]] `key:"parameters"`
SuccessActions marshaller.Node[*sequencedmap.Map[string, *SuccessAction]] `key:"successActions"`
FailureActions marshaller.Node[*sequencedmap.Map[string, *FailureAction]] `key:"failureActions"`
Extensions coreExtensions.Extensions `key:"extensions"`

RootNode *yaml.Node
Expand Down
16 changes: 8 additions & 8 deletions arazzo/core/failureaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
)

type FailureAction struct {
Name marshaller.Node[string] `key:"name"`
Type marshaller.Node[string] `key:"type"`
WorkflowID marshaller.Node[*Expression] `key:"workflowId"`
StepID marshaller.Node[*string] `key:"stepId"`
RetryAfter marshaller.Node[*float64] `key:"retryAfter"`
RetryLimit marshaller.Node[*int] `key:"retryLimit"`
Criteria marshaller.Node[[]Criterion] `key:"criteria"`
Extensions core.Extensions `key:"extensions"`
Name marshaller.Node[string] `key:"name"`
Type marshaller.Node[string] `key:"type"`
WorkflowID marshaller.Node[*Expression] `key:"workflowId"`
StepID marshaller.Node[*string] `key:"stepId"`
RetryAfter marshaller.Node[*float64] `key:"retryAfter"`
RetryLimit marshaller.Node[*int] `key:"retryLimit"`
Criteria marshaller.Node[[]*Criterion] `key:"criteria"`
Extensions core.Extensions `key:"extensions"`

RootNode *yaml.Node
}
Expand Down
8 changes: 4 additions & 4 deletions arazzo/core/requestbody.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
)

type RequestBody struct {
ContentType marshaller.Node[*string] `key:"contentType"`
Payload marshaller.Node[ValueOrExpression] `key:"payload"`
Replacements marshaller.Node[[]PayloadReplacement] `key:"replacements"`
Extensions core.Extensions `key:"extensions"`
ContentType marshaller.Node[*string] `key:"contentType"`
Payload marshaller.Node[ValueOrExpression] `key:"payload"`
Replacements marshaller.Node[[]*PayloadReplacement] `key:"replacements"`
Extensions core.Extensions `key:"extensions"`

RootNode *yaml.Node
}
Expand Down
24 changes: 12 additions & 12 deletions arazzo/core/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import (
)

type Step struct {
StepID marshaller.Node[string] `key:"stepId"`
Description marshaller.Node[*string] `key:"description"`
OperationID marshaller.Node[*Expression] `key:"operationId"`
OperationPath marshaller.Node[*string] `key:"operationPath"`
WorkflowID marshaller.Node[*Expression] `key:"workflowId"`
Parameters marshaller.Node[[]Reusable[Parameter]] `key:"parameters"`
RequestBody marshaller.Node[*RequestBody] `key:"requestBody"`
SuccessCriteria marshaller.Node[[]Criterion] `key:"successCriteria"`
OnSuccess marshaller.Node[[]Reusable[SuccessAction]] `key:"onSuccess"`
OnFailure marshaller.Node[[]Reusable[FailureAction]] `key:"onFailure"`
Outputs marshaller.Node[Outputs] `key:"outputs"`
Extensions core.Extensions `key:"extensions"`
StepID marshaller.Node[string] `key:"stepId"`
Description marshaller.Node[*string] `key:"description"`
OperationID marshaller.Node[*Expression] `key:"operationId"`
OperationPath marshaller.Node[*string] `key:"operationPath"`
WorkflowID marshaller.Node[*Expression] `key:"workflowId"`
Parameters marshaller.Node[[]*Reusable[Parameter]] `key:"parameters"`
RequestBody marshaller.Node[*RequestBody] `key:"requestBody"`
SuccessCriteria marshaller.Node[[]*Criterion] `key:"successCriteria"`
OnSuccess marshaller.Node[[]*Reusable[SuccessAction]] `key:"onSuccess"`
OnFailure marshaller.Node[[]*Reusable[FailureAction]] `key:"onFailure"`
Outputs marshaller.Node[Outputs] `key:"outputs"`
Extensions core.Extensions `key:"extensions"`

RootNode *yaml.Node
}
Expand Down
12 changes: 6 additions & 6 deletions arazzo/core/successaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
)

type SuccessAction struct {
Name marshaller.Node[string] `key:"name"`
Type marshaller.Node[string] `key:"type"`
WorkflowID marshaller.Node[*Expression] `key:"workflowId"`
StepID marshaller.Node[*string] `key:"stepId"`
Criteria marshaller.Node[[]Criterion] `key:"criteria"`
Extensions core.Extensions `key:"extensions"`
Name marshaller.Node[string] `key:"name"`
Type marshaller.Node[string] `key:"type"`
WorkflowID marshaller.Node[*Expression] `key:"workflowId"`
StepID marshaller.Node[*string] `key:"stepId"`
Criteria marshaller.Node[[]*Criterion] `key:"criteria"`
Extensions core.Extensions `key:"extensions"`

RootNode *yaml.Node
}
Expand Down
22 changes: 11 additions & 11 deletions arazzo/core/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import (
)

type Workflow struct {
WorkflowID marshaller.Node[string] `key:"workflowId"`
Summary marshaller.Node[*string] `key:"summary"`
Description marshaller.Node[*string] `key:"description"`
Parameters marshaller.Node[[]Reusable[Parameter]] `key:"parameters"`
Inputs marshaller.Node[core.JSONSchema] `key:"inputs"`
DependsOn marshaller.Node[[]Expression] `key:"dependsOn"`
Steps marshaller.Node[[]Step] `key:"steps" required:"true"`
SuccessActions marshaller.Node[[]Reusable[SuccessAction]] `key:"successActions"`
FailureActions marshaller.Node[[]Reusable[FailureAction]] `key:"failureActions"`
Outputs marshaller.Node[Outputs] `key:"outputs"`
Extensions coreExtensions.Extensions `key:"extensions"`
WorkflowID marshaller.Node[string] `key:"workflowId"`
Summary marshaller.Node[*string] `key:"summary"`
Description marshaller.Node[*string] `key:"description"`
Parameters marshaller.Node[[]*Reusable[Parameter]] `key:"parameters"`
Inputs marshaller.Node[core.JSONSchema] `key:"inputs"`
DependsOn marshaller.Node[[]Expression] `key:"dependsOn"`
Steps marshaller.Node[[]*Step] `key:"steps" required:"true"`
SuccessActions marshaller.Node[[]*Reusable[SuccessAction]] `key:"successActions"`
FailureActions marshaller.Node[[]*Reusable[FailureAction]] `key:"failureActions"`
Outputs marshaller.Node[Outputs] `key:"outputs"`
Extensions coreExtensions.Extensions `key:"extensions"`

RootNode *yaml.Node
}
Expand Down
Loading

0 comments on commit 03a52fd

Please sign in to comment.