Skip to content

Commit 2840e08

Browse files
authored
Remove redundant Equatable conformances in code generation (#214)
### Motivation Fixes #210. ### Modifications With this PR. we are removing the explicit `Equatable` conformance when a type already conforms to `Hashable` in generated code. ### Result Generated types now conforms explicitly to `Hashable` but not to `Equatable`. ```diff - public struct Generated: Equatable, Hashable { } + public sutrct Generated: Hashable { } ``` ### Test Plan I have updated the reference ressources used by tests to check generated code.
1 parent a0333f6 commit 2840e08

File tree

7 files changed

+292
-301
lines changed

7 files changed

+292
-301
lines changed

Sources/_OpenAPIGeneratorCore/FeatureFlags.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/// enabled unconditionally on main and the feature flag removed, and version
2626
/// 0.2 is tagged. (This is for pre-1.0 versioning, would be 1.0 and 2.0 after
2727
/// 1.0 is released.)
28-
public enum FeatureFlag: String, Hashable, Equatable, Codable, CaseIterable {
28+
public enum FeatureFlag: String, Hashable, Codable, CaseIterable {
2929

3030
/// Multiple request and response body content types.
3131
///

Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/Constants.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ enum Constants {
127127
/// The types that every struct conforms to.
128128
static let conformances: [String] = [
129129
"Codable",
130-
"Equatable",
131130
"Hashable",
132131
"Sendable",
133132
]
@@ -154,7 +153,6 @@ enum Constants {
154153
/// The types that every enum conforms to.
155154
static let conformances: [String] = [
156155
"Codable",
157-
"Equatable",
158156
"Hashable",
159157
"Sendable",
160158
"_AutoLosslessStringConvertible",
@@ -208,7 +206,6 @@ enum Constants {
208206
/// The types that the body conforms to.
209207
static let conformances: [String] = [
210208
"Sendable",
211-
"Equatable",
212209
"Hashable",
213210
]
214211
}
@@ -225,7 +222,6 @@ enum Constants {
225222
/// The types that the Input type conforms to.
226223
static let conformances: [String] = [
227224
"Sendable",
228-
"Equatable",
229225
"Hashable",
230226
]
231227
}
@@ -239,7 +235,6 @@ enum Constants {
239235
/// The types that the Output type conforms to.
240236
static let conformances: [String] = [
241237
"Sendable",
242-
"Equatable",
243238
"Hashable",
244239
]
245240

@@ -249,7 +244,6 @@ enum Constants {
249244
/// The types that the Payload type conforms to.
250245
static let conformances: [String] = [
251246
"Sendable",
252-
"Equatable",
253247
"Hashable",
254248
]
255249

@@ -272,7 +266,6 @@ enum Constants {
272266
/// The types that the Headers type conforms to.
273267
static let conformances: [String] = [
274268
"Sendable",
275-
"Equatable",
276269
"Hashable",
277270
]
278271
}

Sources/_OpenAPIGeneratorCore/Translator/Content/CodingStrategy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
/// Describes the underlying coding strategy.
16-
enum CodingStrategy: String, Equatable, Hashable, Sendable {
16+
enum CodingStrategy: String, Hashable, Sendable {
1717

1818
/// A strategy using JSONEncoder/JSONDecoder.
1919
case json

Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class FileBasedReferenceTests: XCTestCase {
146146
}
147147
}
148148

149-
struct ReferenceProject: Hashable, Equatable {
149+
struct ReferenceProject: Hashable {
150150
var name: ReferenceProjectName
151151
var customDirectoryName: String? = nil
152152

Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Types.swift

Lines changed: 117 additions & 118 deletions
Large diffs are not rendered by default.

Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore_FF_MultipleContentTypes/Types.swift

Lines changed: 116 additions & 117 deletions
Large diffs are not rendered by default.

Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift

Lines changed: 56 additions & 56 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)