openapi-generator
openapi-generator copied to clipboard
[BUG] [swift5] for nullable and required field default nil is not generated
Bug Report Checklist
- [ x] Have you provided a full/minimal spec to reproduce the issue?
- [ ] Have you validated the input using an OpenAPI validator (example)?
- [ x] Have you tested with the latest master to confirm the issue still exists?
- [x ] Have you searched for related issues/PRs?
- [ x] What's the actual output vs expected output?
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When properly is nullable in Swift we'd like to get a setup for default value to nil
to it, like this below
public struct MyStruct: Codable, Hashable {
public var value: Decimal?
public init(value: Decimal? = nil) {
self.value = value
}
}
But when a field in json scheme set as nullable and required then I get such result
public struct MyStruct: Codable, Hashable {
public var value: Decimal?
public init(value: Decimal?) {
self.value = value
}
}
openapi-generator version
openapi-generator-cli-7.9.0-20241004.072436-107.jar
OpenAPI declaration file content or url
"MyStruct": {
"properties": {
"value": {
"anyOf": [
{ "type": "string", "format": "decimal" },
{ "type": "null" }
],
"title": "Value"
},
},
"type": "object",
"required": ["value"],
"title": "MyStruct"
},
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
I fixed it by custom template (just updated existed modelObject.mustache
template), but it would be nice to have it from out the box.
Thank you.