-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Labels
area/codegenAffects quality or correctness of generated codeAffects quality or correctness of generated codeawaiting-upstreamThe issue cannot be resolved without action in another repository (may be owned by Pulumi).The issue cannot be resolved without action in another repository (may be owned by Pulumi).kind/bugSome behavior is incorrect or out of specSome behavior is incorrect or out of spec
Milestone
Description
I am using a crd which has property names with - in it and the crd2pulumi failed with
panic: invalid Go source code:
crds/srlinux/v1alpha1/pulumiTypes.go
: 269:7: expected ';', found '-' (and 10 more errors)
goroutine 1 [running]:
github.com/pulumi/pulumi/pkg/v3/codegen/go.GeneratePackage.func1(0xc0001198f0, 0x24, 0xc000a88000, 0x497e4)
/home/runner/go/pkg/mod/github.com/pulumi/pulumi/pkg/v3@v3.0.0/codegen/go/gen.go:2151 +0x46e
github.com/pulumi/pulumi/pkg/v3/codegen/go.GeneratePackage(0x1df1de5, 0xa, 0xc000532280, 0x2, 0xc000026508, 0x1)
/home/runner/go/pkg/mod/github.com/pulumi/pulumi/pkg/v3@v3.0.0/codegen/go/gen.go:2272 +0x1b33
github.com/pulumi/crd2pulumi/gen.(*PackageGenerator).genGoFiles(0xc0002a5a90, 0x1de94c9, 0x4, 0xc0002163b0, 0x1, 0x1)
/home/runner/work/crd2pulumi/crd2pulumi/gen/golang.go:55 +0x345
github.com/pulumi/crd2pulumi/gen.(*PackageGenerator).genGo(0xc0002a5a90, 0xc00039b4a8, 0x7, 0x1de94c9, 0x4, 0x1, 0xc0002163f0)
/home/runner/work/crd2pulumi/crd2pulumi/gen/golang.go:32 +0x45
github.com/pulumi/crd2pulumi/gen.Generate(0x0, 0x0, 0x0, 0xc00011a7d0, 0x1de94c9, 0x4, 0x1de94c9, 0x4, 0x1de94c9, 0x4, ...)
/home/runner/work/crd2pulumi/crd2pulumi/gen/generate.go:73 +0x20c
github.com/pulumi/crd2pulumi/cmd.Execute.func2(0xc00047d080, 0xc000716240, 0x1, 0x3)
/home/runner/work/crd2pulumi/crd2pulumi/cmd/root.go:157 +0x271
github.com/spf13/cobra.(*Command).execute(0xc00047d080, 0xc00003a090, 0x3, 0x3, 0xc00047d080, 0xc00003a090)
/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:846 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0xc00047d080, 0xc00013ff00, 0x1, 0x1)
/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
github.com/pulumi/crd2pulumi/cmd.Execute(0xc00007a748, 0x263f000)
/home/runner/work/crd2pulumi/crd2pulumi/cmd/root.go:189 +0x666
main.main()
input file:
spec:
description: SrlInterfaceSpec struct
properties:
interface:
items:
description: Interface struct
properties:
admin-state:
default: enable
enum:
- disable
- enable
type: string
I changed the code as per below and this solves it for me.
// AddType converts the given OpenAPI `schema` to a ObjectTypeSpec and adds it
// to the `types` map under the given `name`. Recursively converts and adds all
// nested schemas as well.
func AddType(schema map[string]interface{}, name string, types map[string]pschema.ComplexTypeSpec) {
properties, foundProperties, _ := unstruct.NestedMap(schema, "properties")
description, _, _ := unstruct.NestedString(schema, "description")
schemaType, _, _ := unstruct.NestedString(schema, "type")
required, _, _ := unstruct.NestedStringSlice(schema, "required")
propertySpecs := map[string]pschema.PropertySpec{}
for propertyName := range properties {
propertyName = strcase.UpperCamelCase(propertyName)
propertySchema, _, _ := unstruct.NestedMap(properties, propertyName)
propertyDescription, _, _ := unstruct.NestedString(propertySchema, "description")
defaultValue, _, _ := unstruct.NestedFieldNoCopy(propertySchema, "default")
propertySpecs[propertyName] = pschema.PropertySpec{
TypeSpec: GetTypeSpec(propertySchema, name+strings.Title(propertyName), types),
Description: propertyDescription,
Default: defaultValue,
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/codegenAffects quality or correctness of generated codeAffects quality or correctness of generated codeawaiting-upstreamThe issue cannot be resolved without action in another repository (may be owned by Pulumi).The issue cannot be resolved without action in another repository (may be owned by Pulumi).kind/bugSome behavior is incorrect or out of specSome behavior is incorrect or out of spec