Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow incomplete configuration in includeIteratorComponentDetail(). #413

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 56 additions & 49 deletions pkg/service/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,108 +362,115 @@
dataOutput.Fields["properties"] = structpb.NewStructValue(&structpb.Struct{Fields: make(map[string]*structpb.Value)})

for k, v := range comp.OutputElements {
var m *structpb.Value

var err error

str := v
if strings.HasPrefix(str, "${") && strings.HasSuffix(str, "}") && strings.Count(str, "${") == 1 {
// TODO
str = str[2:]
str = str[:len(str)-1]
str = strings.ReplaceAll(str, " ", "")

compID := strings.Split(str, ".")[0]
str = str[len(strings.Split(str, ".")[0]):]
path := v
if strings.HasPrefix(path, "${") && strings.HasSuffix(path, "}") && strings.Count(path, "${") == 1 {
// Remove "${" and "}"
path = path[2:]
path = path[:len(path)-1]
path = strings.ReplaceAll(path, " ", "")

// Find upstream component
compID := strings.Split(path, ".")[0]
path = path[len(compID):]

Check warning on line 374 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L365-L374

Added lines #L365 - L374 were not covered by tests
upstreamCompIdx := -1
for compIdx := range comp.Components {
if comp.Components[compIdx].Id == compID {
upstreamCompIdx = compIdx
}
}
if upstreamCompIdx != -1 {
comp := proto.Clone(comp.Components[upstreamCompIdx]).(*pipelinePB.NestedComponent)
nestedComp := comp.Components[upstreamCompIdx]

Check warning on line 382 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L382

Added line #L382 was not covered by tests

var walk *structpb.Value
switch comp.Component.(type) {
switch nestedComp.Component.(type) {

Check warning on line 385 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L385

Added line #L385 was not covered by tests
case *pipelinePB.NestedComponent_ConnectorComponent:
task := comp.GetConnectorComponent().GetTask()
task := nestedComp.GetConnectorComponent().GetTask()
if task == "" {
// Skip schema generation if the task is not set.
continue

Check warning on line 390 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L387-L390

Added lines #L387 - L390 were not covered by tests
}

splits := strings.Split(str, ".")
splits := strings.Split(path, ".")

Check warning on line 393 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L393

Added line #L393 was not covered by tests

if splits[1] == "output" {
walk = structpb.NewStructValue(comp.GetConnectorComponent().GetDefinition().Spec.DataSpecifications[task].Output)
walk = structpb.NewStructValue(nestedComp.GetConnectorComponent().GetDefinition().Spec.DataSpecifications[task].Output)

Check warning on line 396 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L396

Added line #L396 was not covered by tests
} else if splits[1] == "input" {
walk = structpb.NewStructValue(comp.GetConnectorComponent().GetDefinition().Spec.DataSpecifications[task].Input)
walk = structpb.NewStructValue(nestedComp.GetConnectorComponent().GetDefinition().Spec.DataSpecifications[task].Input)

Check warning on line 398 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L398

Added line #L398 was not covered by tests
} else {
return fmt.Errorf("generate OpenAPI spec error")
// Skip schema generation if the configuration is not valid.
continue

Check warning on line 401 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L400-L401

Added lines #L400 - L401 were not covered by tests
}
str = str[len(splits[1])+1:]
path = path[len(splits[1])+1:]

Check warning on line 403 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L403

Added line #L403 was not covered by tests
case *pipelinePB.NestedComponent_OperatorComponent:
task := comp.GetOperatorComponent().GetTask()
splits := strings.Split(str, ".")
task := nestedComp.GetOperatorComponent().GetTask()
if task == "" {
// Skip schema generation if the task is not set.
continue

Check warning on line 408 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L405-L408

Added lines #L405 - L408 were not covered by tests
}
splits := strings.Split(path, ".")

Check warning on line 410 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L410

Added line #L410 was not covered by tests

if splits[1] == "output" {
walk = structpb.NewStructValue(comp.GetOperatorComponent().GetDefinition().Spec.DataSpecifications[task].Output)
walk = structpb.NewStructValue(nestedComp.GetOperatorComponent().GetDefinition().Spec.DataSpecifications[task].Output)

Check warning on line 413 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L413

Added line #L413 was not covered by tests
} else if splits[1] == "input" {
walk = structpb.NewStructValue(comp.GetOperatorComponent().GetDefinition().Spec.DataSpecifications[task].Input)
walk = structpb.NewStructValue(nestedComp.GetOperatorComponent().GetDefinition().Spec.DataSpecifications[task].Input)

Check warning on line 415 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L415

Added line #L415 was not covered by tests
} else {
return fmt.Errorf("generate OpenAPI spec error")
// Skip schema generation if the configuration is not valid.
continue

Check warning on line 418 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L417-L418

Added lines #L417 - L418 were not covered by tests
}
str = str[len(splits[1])+1:]
path = path[len(splits[1])+1:]

Check warning on line 420 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L420

Added line #L420 was not covered by tests
}

success := true

// Traverse the schema of upstream component

Check warning on line 425 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L423-L425

Added lines #L423 - L425 were not covered by tests
for {
if len(str) == 0 {
if len(path) == 0 {

Check warning on line 427 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L427

Added line #L427 was not covered by tests
break
}

splits := strings.Split(str, ".")
splits := strings.Split(path, ".")

Check warning on line 431 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L431

Added line #L431 was not covered by tests
curr := splits[1]

if strings.Contains(curr, "[") && strings.Contains(curr, "]") {
target := strings.Split(curr, "[")[0]
if _, ok := walk.GetStructValue().Fields["properties"]; ok {
if _, ok := walk.GetStructValue().Fields["properties"].GetStructValue().Fields[target]; !ok {
if _, ok := walk.GetStructValue().Fields["properties"].GetStructValue().Fields[target]; ok {
walk = walk.GetStructValue().Fields["properties"].GetStructValue().Fields[target].GetStructValue().Fields["items"]
} else {
success = false

Check warning on line 440 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L437-L440

Added lines #L437 - L440 were not covered by tests
break
}
} else {
success = false

Check warning on line 444 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L444

Added line #L444 was not covered by tests
break
}
walk = walk.GetStructValue().Fields["properties"].GetStructValue().Fields[target].GetStructValue().Fields["items"]
} else {
target := curr

if _, ok := walk.GetStructValue().Fields["properties"]; ok {
if _, ok := walk.GetStructValue().Fields["properties"].GetStructValue().Fields[target]; !ok {
if _, ok := walk.GetStructValue().Fields["properties"].GetStructValue().Fields[target]; ok {
walk = walk.GetStructValue().Fields["properties"].GetStructValue().Fields[target]
} else {
success = false

Check warning on line 454 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L451-L454

Added lines #L451 - L454 were not covered by tests
break
}
} else {
success = false

Check warning on line 458 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L458

Added line #L458 was not covered by tests
break
}

walk = walk.GetStructValue().Fields["properties"].GetStructValue().Fields[target]

}

str = str[len(curr)+1:]
path = path[len(curr)+1:]

Check warning on line 464 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L464

Added line #L464 was not covered by tests
}
if success {
s := &structpb.Struct{Fields: map[string]*structpb.Value{}}
s.Fields["type"] = structpb.NewStringValue("array")
s.Fields["items"] = structpb.NewStructValue(walk.GetStructValue())
dataOutput.Fields["properties"].GetStructValue().Fields[k] = structpb.NewStructValue(s)

Check warning on line 470 in pkg/service/convert.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/convert.go#L466-L470

Added lines #L466 - L470 were not covered by tests
}
m = structpb.NewStructValue(walk.GetStructValue())

} else {
return fmt.Errorf("generate data spec error")
}

}

if err != nil {

} else {
s := &structpb.Struct{Fields: map[string]*structpb.Value{}}
s.Fields["type"] = structpb.NewStringValue("array")
s.Fields["items"] = m
dataOutput.Fields["properties"].GetStructValue().Fields[k] = structpb.NewStructValue(s)

}
}

Expand Down
Loading