OpenAPITools / OpenAPITools/openapi-generator
[BUG][APEX] generated models duplicate property map for each transformed property
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Schemas, requests, or responses, with two or more properties defined which are transformed this_id -> thisId cause APEX models generated to be invalid. For each transformed property the resulting class will have n x private static final Map<String, String> propertyMappings and public Map<String, String> getPropertyMappings() defined
openapi-generator version
7.17.0
OpenAPI declaration file content or url
{
"openapi": "3.0.3",
"info": {
"title": "test API",
"version": "65.0"
},
"paths": {
},
"components": {
"schemas": {
"RecordDetails": {
"type": "object",
"title": "RecordDetails",
"properties": {
"record_id": {
"type": "integer",
"title": "Record Id",
"description": "Record identifier"
},
"name": {
"type": "string",
"title": "Name",
"description": "Record name"
},
"other_id": {
"type": "integer",
"title": "Other Id",
"description": "Other identifier"
}
},
"required": [],
"additionalProperties": false
}
}
}
}
Results
/*
* test API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 65.0
*
*
* NOTE: This class is auto generated by the OAS code generator program.
* https://github.com/OpenAPITools/openapi-generator
* Do not edit the class manually.
*/
/**
* OASRecordDetails
*/
public class OASRecordDetails {
/**
* Record identifier
* @return recordId
*/
public Integer recordId { get; set; }
/**
* Record name
* @return name
*/
public String name { get; set; }
/**
* Other identifier
* @return otherId
*/
public Integer otherId { get; set; }
private static final Map<String, String> propertyMappings = new Map<String, String>{
'record_id' => 'recordId',
'other_id' => 'otherId'
};
public Map<String, String> getPropertyMappings() {
return propertyMappings;
}
private static final Map<String, String> propertyMappings = new Map<String, String>{
'record_id' => 'recordId',
'other_id' => 'otherId'
};
public Map<String, String> getPropertyMappings() {
return propertyMappings;
}
public static OASRecordDetails getExample() {
OASRecordDetails recordDetails = new OASRecordDetails();
recordDetails.recordId = 0;
recordDetails.name = '';
recordDetails.otherId = 0;
return recordDetails;
}
public Boolean equals(Object obj) {
if (obj instanceof OASRecordDetails) {
OASRecordDetails recordDetails = (OASRecordDetails) obj;
return this.recordId == recordDetails.recordId
&& this.name == recordDetails.name
&& this.otherId == recordDetails.otherId;
}
return false;
}
public Integer hashCode() {
Integer hashCode = 43;
hashCode = (17 * hashCode) + (recordId == null ? 0 : System.hashCode(recordId));
hashCode = (17 * hashCode) + (name == null ? 0 : System.hashCode(name));
hashCode = (17 * hashCode) + (otherId == null ? 0 : System.hashCode(otherId));
return hashCode;
}
}
Expected
/*
* test API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 65.0
*
*
* NOTE: This class is auto generated by the OAS code generator program.
* https://github.com/OpenAPITools/openapi-generator
* Do not edit the class manually.
*/
/**
* OASRecordDetails
*/
public class OASRecordDetails {
/**
* Record identifier
* @return recordId
*/
public Integer recordId { get; set; }
/**
* Record name
* @return name
*/
public String name { get; set; }
/**
* Other identifier
* @return otherId
*/
public Integer otherId { get; set; }
private static final Map<String, String> propertyMappings = new Map<String, String>{
'record_id' => 'recordId',
'other_id' => 'otherId'
};
public Map<String, String> getPropertyMappings() {
return propertyMappings;
}
public static OASRecordDetails getExample() {
OASRecordDetails recordDetails = new OASRecordDetails();
recordDetails.recordId = 0;
recordDetails.name = '';
recordDetails.otherId = 0;
return recordDetails;
}
public Boolean equals(Object obj) {
if (obj instanceof OASRecordDetails) {
OASRecordDetails recordDetails = (OASRecordDetails) obj;
return this.recordId == recordDetails.recordId
&& this.name == recordDetails.name
&& this.otherId == recordDetails.otherId;
}
return false;
}
public Integer hashCode() {
Integer hashCode = 43;
hashCode = (17 * hashCode) + (recordId == null ? 0 : System.hashCode(recordId));
hashCode = (17 * hashCode) + (name == null ? 0 : System.hashCode(name));
hashCode = (17 * hashCode) + (otherId == null ? 0 : System.hashCode(otherId));
return hashCode;
}
}
Generation Details
yarn openapi-generator-cli generate -g apex -o output/test -i
Steps to reproduce
- create openapi.json with the provided spec
- Run yarn openapi-generator-cli generate -g apex -o output/test -i {yourpathtofile}
Related issues/PRs
Suggest a fix
I believe the logic in the ApexCodegen is causing duplicate maps,
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 in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractApexCodegen.java around line 440, then reproduce with the supplied OpenAPI declaration and the yarn openapi-generator-cli command. Done means the generated Apex model contains one propertyMappings map and one getPropertyMappings method, even when multiple properties are transformed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100