Skip to content

Commit

Permalink
Exposing step output schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Janos Bonic committed Apr 11, 2023
1 parent bdb3ac9 commit 0523db3
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 96 deletions.
206 changes: 110 additions & 96 deletions schema/schema_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1014,107 +1014,116 @@ var scopeScopeSchema = NewScopeSchema(
scopeObject,
basicObjects...,
)
var stepOutputSchemaObject = NewStructMappedObjectSchema[*StepOutputSchema](
"StepOutput",
map[string]*PropertySchema{
"display": displayProperty,
"error": NewPropertySchema(
NewBoolSchema(),
NewDisplayValue(
PointerTo("Error"),
PointerTo("If set to true, this output will be treated as an error output."),
nil,
),
false,
nil,
nil,
nil,
PointerTo("false"),
nil,
),
"schema": NewPropertySchema(
NewRefSchema(
"Scope",
nil,
),
NewDisplayValue(
PointerTo("Schema"),
PointerTo("Data schema for this particular output."),
nil,
),
true,
nil,
nil,
nil,
nil,
nil,
),
},
)
var stepSchemaObject = NewStructMappedObjectSchema[*StepSchema](
"Step",
map[string]*PropertySchema{
"display": displayProperty,
"id": NewPropertySchema(
idType,
NewDisplayValue(
PointerTo("ID"),
PointerTo("Machine identifier for this step."),
nil,
),
true,
nil,
nil,
nil,
nil,
nil,
),
"input": NewPropertySchema(
NewRefSchema(
"Scope",
nil,
),
NewDisplayValue(
PointerTo("Input"),
PointerTo("Input data schema."),
nil,
),
true,
nil,
nil,
nil,
nil,
nil,
),
"outputs": NewPropertySchema(
NewMapSchema(
idType,
NewRefSchema(
"StepOutput",
nil,
),
nil,
nil,
),
NewDisplayValue(
PointerTo("Input"),
PointerTo("Input data schema."),
nil,
),
true,
nil,
nil,
nil,
nil,
nil,
),
},
)
var stepOutputSchema = NewScopeSchema(
stepOutputSchemaObject,
append(
basicObjects,
scopeObject,
)...,
)
var schemaSchema = NewScopeSchema(
schemaObject,
append(
basicObjects,
scopeObject,
NewStructMappedObjectSchema[*StepOutputSchema](
"StepOutput",
map[string]*PropertySchema{
"display": displayProperty,
"error": NewPropertySchema(
NewBoolSchema(),
NewDisplayValue(
PointerTo("Error"),
PointerTo("If set to true, this output will be treated as an error output."),
nil,
),
false,
nil,
nil,
nil,
PointerTo("false"),
nil,
),
"schema": NewPropertySchema(
NewRefSchema(
"Scope",
nil,
),
NewDisplayValue(
PointerTo("Schema"),
PointerTo("Data schema for this particular output."),
nil,
),
true,
nil,
nil,
nil,
nil,
nil,
),
},
),
NewStructMappedObjectSchema[*StepSchema](
"Step",
map[string]*PropertySchema{
"display": displayProperty,
"id": NewPropertySchema(
idType,
NewDisplayValue(
PointerTo("ID"),
PointerTo("Machine identifier for this step."),
nil,
),
true,
nil,
nil,
nil,
nil,
nil,
),
"input": NewPropertySchema(
NewRefSchema(
"Scope",
nil,
),
NewDisplayValue(
PointerTo("Input"),
PointerTo("Input data schema."),
nil,
),
true,
nil,
nil,
nil,
nil,
nil,
),
"outputs": NewPropertySchema(
NewMapSchema(
idType,
NewRefSchema(
"StepOutput",
nil,
),
nil,
nil,
),
NewDisplayValue(
PointerTo("Input"),
PointerTo("Input data schema."),
nil,
),
true,
nil,
nil,
nil,
nil,
nil,
),
},
),
stepOutputSchemaObject,
stepSchemaObject,
)...,
)

Expand All @@ -1123,6 +1132,11 @@ func DescribeScope() *ScopeSchema {
return scopeScopeSchema
}

// DescribeStepOutput returns a scope that describes a step output.
func DescribeStepOutput() *ScopeSchema {
return stepOutputSchema
}

// DescribeSchema returns a scope that describes a plugin schema.
func DescribeSchema() *ScopeSchema {
return schemaSchema
Expand Down
34 changes: 34 additions & 0 deletions schema/schema_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,37 @@ func TestSchemaUnserializationSuperScoped(t *testing.T) {
nameType := unserializedData.StepsValue["hello-world"].InputValue.Objects()["InputParams"].Properties()["name"].Type().(*schema.OneOfSchema[string])
assertEqual(t, nameType.Types()["fullname"].TypeID(), schema.TypeIDScope)
}

func TestStepOutputSchema(t *testing.T) {
stepOutputSchema := schema.DescribeStepOutput()
unserializedStepOutput, err := stepOutputSchema.Unserialize(map[string]any{
"schema": map[string]any{
"root": "A",
"objects": map[string]any{
"A": map[string]any{
"id": "A",
"properties": map[string]any{
"foo": map[string]any{
"type": map[string]any{
"type_id": "string",
},
"required": true,
},
},
},
},
},
})
if err != nil {
t.Fatalf("%v", err)
}
unserializedStepOutputOutput, err := unserializedStepOutput.(*schema.StepOutputSchema).Unserialize(map[string]any{
"foo": "bar",
})
if err != nil {
t.Fatalf("%v", err)
}
if unserializedStepOutputOutput.(map[string]any)["foo"] != "bar" {
t.Fatalf("Incorrect unserialized output: %s", unserializedStepOutputOutput.(map[any]any)["foo"])
}
}

0 comments on commit 0523db3

Please sign in to comment.