Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
I need to generate obj-c accessible models and there is a problem in interoperability with some nullable types which cannot be represented in obj-c. Swift5ClientCodegen
does support that but there is a problem if in OpenAPI declaration is missing format
and only specify type
. Then it's generated into Double?
but postProcessModelProperty
function does not trigger x-swift-optional-scalar
to true
. It can definitely be fixed on declaration side but client Codegen should expected it, too.
@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
super.postProcessModelProperty(model, property);
boolean isSwiftScalarType = property.isInteger || property.isLong || property.isFloat
|| property.isDouble || property.isBoolean;
if ((!property.required || property.isNullable) && isSwiftScalarType) {
// Optional scalar types like Int?, Int64?, Float?, Double?, and Bool?
// do not translate to Objective-C. So we want to flag those
// properties in case we want to put special code in the templates
// which provide Objective-C compatibility.
property.vendorExtensions.put("x-swift-optional-scalar", true);
}
}
openapi-generator version
4.3.1
OpenAPI declaration file content or url
"GpsCoordinatesTO": {
"type": "object",
"properties": {
"gpsX": {
"type": "number",
"format": "double"
},
"gpsY": {
"type": "number"
}
},
"title": "GpsCoordinatesTO"
}
-->
Command line used for generation
openapi-generator generate -i swagger.json -g swift5 --additional-properties=library=urlsession,objcCompatible=true -o swift/ --skip-validate-spec
Steps to reproduce
Generate client from declaration which includes snippet above.
Suggest a fix
Update postProcessModelProperty
function to handle only number
because it's generated into Swift
as Double?
which cannot be represented in obj-c.