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

Dashed properties generate invalid Node & Dotnet SDKs #15874

Open
blampe opened this issue Apr 8, 2024 · 0 comments · May be fixed by #16197
Open

Dashed properties generate invalid Node & Dotnet SDKs #15874

blampe opened this issue Apr 8, 2024 · 0 comments · May be fixed by #16197
Labels
area/codegen SDK-gen, program-gen, convert kind/bug Some behavior is incorrect or out of spec language/dotnet language/javascript

Comments

@blampe
Copy link
Contributor

blampe commented Apr 8, 2024

What happened?

crd2pulumi often generates property names that include dashes, since these are valid in k8s. These aren't sanitized in generated SDKs for Node and Dotnet. (Possibly also Java, although gradle built successfully for me on the repro below.)

#11049 previously fixed this for Go and Python.

Example

Example schema:

{
  "name": "repro",
  "version": "0.1.0",
  "meta": {
    "moduleFormat": "(.*)"
  },
  "types": {
    "repro:index:Dashed": {
      "properties": {
        "with-dash": {
          "type": "string"
        }
      },
      "type": "object"
    }
  },
  "provider": {
    "properties": {
      "dashed": {
        "$ref": "#/types/repro:index:Dashed"
      }
    }
  },
  "resources": {
    "repro:index:Repro": {
      "properties": {
        "dashed": {
          "$ref": "#/types/repro:index:Dashed"
        }
      }
    }
  }
}
pulumi package gen-sdk schema.json -o out
// *** WARNING: this file was generated by pulumi. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Pulumi.Serialization;

namespace Pulumi.Repro.Outputs
{

    [OutputType]
    public sealed class Dashed
    {
        public readonly string? With-dash;

        [OutputConstructor]
        private Dashed(string? with-dash)
        {
            With-dash = with-dash;
        }
    }
}
~/src/test/crdtest/out/dotnet
❯ dotnet build
/Users/bryce/src/test/crdtest/out/dotnet/Outputs/Dashed.cs(16,37): error CS1003: Syntax error, ',' expected [/Users/bryce/src/test/crdtest/out/dotnet/Pulumi.Repro.csproj]
/Users/bryce/src/test/crdtest/out/dotnet/Outputs/Dashed.cs(16,38): error CS1002: ; expected [/Users/bryce/src/test/crdtest/out/dotnet/Pulumi.Repro.csproj]
/Users/bryce/src/test/crdtest/out/dotnet/Outputs/Dashed.cs(16,42): error CS1519: Invalid token ';' in class, record, struct, or interface member declaration [/Users/bryce/src/test/crdtest/out/dotnet/Pulumi.Repro.csproj]
/Users/bryce/src/test/crdtest/out/dotnet/Outputs/Dashed.cs(19,36): error CS1003: Syntax error, ',' expected [/Users/bryce/src/test/crdtest/out/dotnet/Pulumi.Repro.csproj]
/Users/bryce/src/test/crdtest/out/dotnet/Outputs/Dashed.cs(19,37): error CS1003: Syntax error, ',' expected [/Users/bryce/src/test/crdtest/out/dotnet/Pulumi.Repro.csproj]
/Users/bryce/src/test/crdtest/out/dotnet/Outputs/Dashed.cs(19,41): error CS1001: Identifier expected [/Users/bryce/src/test/crdtest/out/dotnet/Pulumi.Repro.csproj]
// *** WARNING: this file was generated by pulumi-language-nodejs. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

import * as pulumi from "@pulumi/pulumi";
import * as inputs from "../types/input";
import * as outputs from "../types/output";

export interface Dashed {
    with-dash?: string;
}
~/src/test/crdtest/out/nodejs                                                                                                                                                                                                               10:50:40
❯ yarn install && yarn run tsc
...
$ /Users/bryce/src/test/crdtest/out/nodejs/node_modules/.bin/tsc
types/output.ts:9:5 - error TS1131: Property or signature expected.

9     with-dash?: string;
      ~~~~

types/output.ts:9:9 - error TS1005: '(' expected.

9     with-dash?: string;
          ~

types/output.ts:9:15 - error TS1109: Expression expected.

9     with-dash?: string;
                ~

types/output.ts:9:23 - error TS1005: ')' expected.

9     with-dash?: string;
                        ~

types/output.ts:10:1 - error TS1128: Declaration or statement expected.

10 }
   ~


Found 5 errors in the same file, starting at: types/output.ts:9

Output of pulumi about

❯ pulumi about
CLI
Version      3.111.1
Go Version   go1.22.1
Go Compiler  gc

Host
OS       darwin
Version  14.1
Arch     arm64

Additional context

Refs pulumi/crd2pulumi#43

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@blampe blampe added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Apr 8, 2024
@Frassle Frassle added language/javascript language/dotnet area/codegen SDK-gen, program-gen, convert and removed needs-triage Needs attention from the triage team labels Apr 8, 2024
@blampe blampe linked a pull request May 14, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codegen SDK-gen, program-gen, convert kind/bug Some behavior is incorrect or out of spec language/dotnet language/javascript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants