Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
fix: tuple endpoint return invalid error
Browse files Browse the repository at this point in the history
  • Loading branch information
aiwantaozi authored and alexcodelf committed Nov 17, 2023
1 parent af772a7 commit f94d57d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
22 changes: 18 additions & 4 deletions pkg/apis/resource/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,20 @@ func (h Handler) getEndpointsFromOutput(ctx context.Context, id object.ID) ([]Ac
Name: v.Name,
})
case v.Schema.Type == openapi3.TypeArray:
if v.Schema.Items == nil || v.Schema.Items.Value == nil ||
v.Schema.Items.Value.Type != openapi3.TypeString {
// For list and set: all elements are the same type.
return nil, invalidTypeErr
if v.Schema.Items != nil && v.Schema.Items.Value != nil {
// Array.
if v.Schema.Items.Value.Type != "" && v.Schema.Items.Value.Type != openapi3.TypeString {
return nil, invalidTypeErr
}

// Tuple.
if len(v.Schema.Items.Value.OneOf) != 0 {
for _, sv := range v.Schema.Items.Value.OneOf {
if sv.Value != nil && sv.Value.Type != openapi3.TypeString {
return nil, invalidTypeErr
}
}
}
}

eps, _, err := property.GetSlice[string](v.Value)
Expand All @@ -319,6 +329,10 @@ func (h Handler) getEndpointsFromOutput(ctx context.Context, id object.ID) ([]Ac
return nil, err
}

if len(eps) == 0 {
continue
}

endpoints = append(endpoints, AccessEndpoint{
Endpoints: eps,
Name: v.Name,
Expand Down
18 changes: 10 additions & 8 deletions pkg/terraform/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,17 @@ func ParseStateOutput(revision *model.ResourceRevision) ([]types.OutputValue, er
val = []byte(`"<sensitive>"`)
}

s := translator.SchemaOfType(
o.Type,
n,
nil,
"",
o.Sensitive, count)

outputs = append(outputs, types.OutputValue{
Name: strings.TrimPrefix(n, sn+"_"), // Name format is serviceName_outputName.
Value: val,
Schema: translator.SchemaOfType(
o.Type,
n,
nil,
"",
o.Sensitive, count),
Name: strings.TrimPrefix(n, sn+"_"), // Name format is serviceName_outputName.
Value: val,
Schema: s,
})

count++
Expand Down

0 comments on commit f94d57d

Please sign in to comment.