Hi Everyone,
I'm working on an open source library to generate DTOs and remove the boiler plate code.
You can find it here it's currently under development (no version released yet).
But the main features are already implemented and working (on the main).
It can :
- generate an extension containing DTO nested types; init(from:) initialiser and private conversion closures
- Convert one type to another with the user provided closure.
- Change the DTO property name to fit the data received
Here is a small example of what it looks like :
Code written
@DecodableFromDTO
struct MyData {
@DTOProperty(name: "a_name")
let name: String
@DTOProperty(name: "date_of_birth")
@ConvertDTOType(from: String, to: Date?, convert: { ISO8601DateFormatter().date(from:$0)})
let birthdate: Date?
}
Code generated
extension MyData: DecodableFromDTOProtocol {
public struct DTO: Decodable {
public let a_name: String
public let date_of_birth: String
}
private struct DTOConversionProcessor {
fileprivate static var date_of_birth: (String) -> Date? = {
ISO8601DateFormatter().date(from: $0)
}
}
public init(from dto: DTO) {
self.name = dto.a_name
self.birthdate = DTOConversionProcessor.date_of_birth(dto.date_of_birth)
}
}
So I came here for multiple things :
First to know if anyone is interested by using this project.
Second, to have your feed back on the library, its ease of use, its clarity and its efficiency.
And finally to discuss the best solution to implement the next features : Flattening types and expending types in a way that is not cumbersome.
Thank you in advance.
Cheers