swift-openapi-generator icon indicating copy to clipboard operation
swift-openapi-generator copied to clipboard

Add ability to attach protocols to generated models

Open armintelker opened this issue 1 year ago • 9 comments

Motivation

We need all of our models generated by swift-openapi-generator to comply with protocols like Equatableor Identifiable to work with our overlaying architecture. Manually extending each generated model to conform to these protocols is insufficient and cumbersome, especially as the number of models increases.

Proposed solution

Add a feature to the swift-openapi-generator that allows specifying which protocols the generated models should conform to. This could be implemented as a configuration option in the generator, enabling automated protocol conformance during the model generation process.

Alternatives considered

The current workaround is manually extending each generated model, like so:

extension ModelA: Equatable {}
extension ModelB: Equatable {}
extension ModelC: Equatable {}
extension ModelD: Equatable, Identifyable {
    var id: Int 
    //...
}

However, this approach is not scalable and becomes unwieldy as the number of models grows.

Additional information

If there is already an existing feature to achieve this, i apologize for the oversight and kindly request guidance to the relevant documentation. I could not find any reference to such a feature in the current documentation.

References:

Identifiable Documentation Equatable Documentation Thank you for considering this request.

armintelker avatar May 17 '24 11:05 armintelker