Skip to content

Commit

Permalink
Remove redundant Equatable conformances in code generation (#214)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
arthurcro authored Aug 21, 2023
1 parent a0333f6 commit 2840e08
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 301 deletions.
2 changes: 1 addition & 1 deletion Sources/_OpenAPIGeneratorCore/FeatureFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/// enabled unconditionally on main and the feature flag removed, and version
/// 0.2 is tagged. (This is for pre-1.0 versioning, would be 1.0 and 2.0 after
/// 1.0 is released.)
public enum FeatureFlag: String, Hashable, Equatable, Codable, CaseIterable {
public enum FeatureFlag: String, Hashable, Codable, CaseIterable {

/// Multiple request and response body content types.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ enum Constants {
/// The types that every struct conforms to.
static let conformances: [String] = [
"Codable",
"Equatable",
"Hashable",
"Sendable",
]
Expand All @@ -154,7 +153,6 @@ enum Constants {
/// The types that every enum conforms to.
static let conformances: [String] = [
"Codable",
"Equatable",
"Hashable",
"Sendable",
"_AutoLosslessStringConvertible",
Expand Down Expand Up @@ -208,7 +206,6 @@ enum Constants {
/// The types that the body conforms to.
static let conformances: [String] = [
"Sendable",
"Equatable",
"Hashable",
]
}
Expand All @@ -225,7 +222,6 @@ enum Constants {
/// The types that the Input type conforms to.
static let conformances: [String] = [
"Sendable",
"Equatable",
"Hashable",
]
}
Expand All @@ -239,7 +235,6 @@ enum Constants {
/// The types that the Output type conforms to.
static let conformances: [String] = [
"Sendable",
"Equatable",
"Hashable",
]

Expand All @@ -249,7 +244,6 @@ enum Constants {
/// The types that the Payload type conforms to.
static let conformances: [String] = [
"Sendable",
"Equatable",
"Hashable",
]

Expand All @@ -272,7 +266,6 @@ enum Constants {
/// The types that the Headers type conforms to.
static let conformances: [String] = [
"Sendable",
"Equatable",
"Hashable",
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//

/// Describes the underlying coding strategy.
enum CodingStrategy: String, Equatable, Hashable, Sendable {
enum CodingStrategy: String, Hashable, Sendable {

/// A strategy using JSONEncoder/JSONDecoder.
case json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class FileBasedReferenceTests: XCTestCase {
}
}

struct ReferenceProject: Hashable, Equatable {
struct ReferenceProject: Hashable {
var name: ReferenceProjectName
var customDirectoryName: String? = nil

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

112 changes: 56 additions & 56 deletions Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift

Large diffs are not rendered by default.

0 comments on commit 2840e08

Please sign in to comment.