pulumi / pulumi-java

Java support for Pulumi
Apache License 2.0
69 stars 21 forks source link

Avoid reserved names in codegen #1324

Open thomas11 opened 6 months ago

thomas11 commented 6 months ago

Prompted by pulumi/pulumi-azure-native#3106: an addition to the Azure spec introduced an enum with the unfortunate name "string" (for which I'll file an upstream issue as well). In the schema, this translated to

        "azure-native:databasewatcher/v20230901preview:String": {
            "description": "The target collection status.",
            "type": "string",
            "enum": [
                {
                    "name": "Enabled",
                    "description": "Denotes a target that is enabled.",
                    "value": "Enabled"
                },
                {
                    "name": "Disabled",
                    "description": "Denotes a target that is disabled.",
                    "value": "Disabled"
                }
            ]
        },

and in the generated Java, to public enum String.

That doesn't compile:

/home/runner/work/pulumi-azure-native/pulumi-azure-native/sdk/java/src/main/java/com/pulumi/azurenative/databasewatcher/enums/String.java:39: error: toString() in com.pulumi.azurenative.databasewatcher.enums.String cannot override toString() in Enum
        public String toString() {
                      ^
  return type com.pulumi.azurenative.databasewatcher.enums.String is not compatible with java.lang.String
/home/runner/work/pulumi-azure-native/pulumi-azure-native/sdk/java/src/main/java/com/pulumi/azurenative/databasewatcher/enums/String.java:38: error: method does not override or implement a method from a supertype
        @Override
        ^
/home/runner/work/pulumi-azure-native/pulumi-azure-native/sdk/java/src/main/java/com/pulumi/azurenative/databasewatcher/enums/String.java:42: error: incompatible types: java.lang.String cannot be converted to com.pulumi.azurenative.databasewatcher.enums.String
                .toString();

It would be great if the Java codegen could automatically detect the use of reserved names and work around it by modifying the name.