OpenAPITools / OpenAPITools/openapi-generator
[BUG][APEX] Enum values can conflict with keywords as Apex is case-insensitive
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
-
[YES ] Have you provided a full/minimal spec to reproduce the issue?
-
[YES] Have you validated the input using an OpenAPI validator (example)?
-
[YES] What's the version of OpenAPI Generator used?
-
[Yes ] Have you search for related issues/PRs?
-
[ YES] What's the actual output vs expected output?
-
[Optional] Bounty to sponsor the fix (example)
Description
take example of a API specifications for CUFX 4.1.
A part of this specs is as below:
"billStatus": {
"description": " [AHR] omit ",
"enum": [
"Due",
"OverDue",
"Cancelled",
"Suspended",
"Paid",
"Void",
"Dispute",
"PaymentFailed"
],
"type": "string"
The value 'Void' will conflict with keyword 'void'. The generated output is as below:
public enum BillStatusEnum {
DUE,
OVERDUE,
CANCELLED,
SUSPENDED,
PAID,
VOID,
DISPUTE,
PAYMENTFAILED
}
This issue is continuing from Swagger 2.0 as I tried with that first and then now with OAS3.0.
Also, the maximum enums one can define is 100. This creates the problem in the enums for say Countries.
openapi-generator version
OAS 3.0 (Git Clone at 25d39c36340b570a8243a3f9f36bd93aec653f06)
OpenAPI declaration file content or url
I am trying to generate client coe for below .
https://app.swaggerhub.com/apis/dlacroix01/CUFX/4.1
Command line used for generation
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ~/Downloads/swagger-client-generated-2/swagger.json -g apex -o ./ClientsApex/CUFX4.1/
Steps to reproduce
After code is generated, try to deploy the code on salesforce org.
Related issues/PRs
Suggest a fix
There can be multiple approaches.
- I created class which has constant strings for the enum. The problem is with JSON serialize/deserialize.
- using globalpicklist/valueset as these will be useful. However the type-checking cant be performed, as we wouldnt be saving any objects.
Also there are governor limits [https://help.salesforce.com/articleView?id=fields_creating_global_picklists.htm&type=5]
We may have to brainstorm here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CUFX 4.1 OpenAPI specification and reproduce generation using the listed openapi-generator-cli command with the Apex generator. Inspect the generated BillStatusEnum and test deployment to a Salesforce org, including JSON serialization and deserialization. Done means enum values such as Void no longer conflict with Apex keywords while preserving the original API values; the issue also raises a separate limit concern about enums with more than 100 values.
Written by the indexing model from the issue text.
Assessment
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100