Skip to content

[BUG APEX] Code Generation in OAS.cls #7500

@henryh-force

Description

@henryh-force

openapi-generator/modules/openapi-generator/src/main/resources/apex/OAS.cls

If you send a response that contains anything in addition to "application/json" nothing is returned.

Set the toReturnValue to validate for more than just application/json e.g. UTF-8 within the Content Type.

@testvisible
protected virtual Object toReturnValue(String body, Type returnType, String contentType) {
Original ---> if (contentType == 'application/json') {
Desired ---> if (contentType.contains('application/json')) {
Object o = returnType.newInstance();
if (o instanceof MappedProperties) {
Map<String, String> propertyMappings = ((MappedProperties) o).getPropertyMappings();
for (String baseName : propertyMappings.keySet()) {
body = body.replaceAll('"' + baseName + '"\s*:',
'"' + propertyMappings.get(baseName) + '":');
}
}
JsonParser parser = Json.createParser(body);
parser.nextToken();
return parser.readValueAs(returnType);
}
return body;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions