pulumi / pulumi/pulumi-java

Avoid reserved names in codegen

Open
#1,324 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/codegen kind/enhancement
Dominant language
Java
Stars
85
Forks
26
Avg merge
11h 49m
Merged PRs (30d)
22

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the Java codegen that produces sdk/java/src/main/java/com/pulumi/azurenative/databasewatcher/enums/String.java and its enum-name handling. Verify the generated output avoids reserved names and compiles without the shown override errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.