Skip to content

Commit 6e0f18c

Browse files
authored
[297]Remove implicit mapping when an explicit is present in the spec (#298)
* [297]Remove implicit mapping when an explicit is present in the spec * changelog
1 parent a6fd379 commit 6e0f18c

File tree

3 files changed

+2
-4
lines changed

3 files changed

+2
-4
lines changed

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
### Fixed
1111
- Fixed compilation with Xcode 13 #282 @sroebert
12+
- Fixed duplicated switch cases when using explicit mappings in oneOf discriminator #297 @JanC
1213

1314
### Changed
1415
- Improved `CodeFormatter` efficiency #272 @zntfdr

‎Sources/SwagGenKit/CodeFormatter.swift

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ public class CodeFormatter {
213213
for (key, value) in discriminatorMapping {
214214
// TODO: could reference another spec
215215
let reference = Reference<Schema>(value)
216+
mapping.removeValue(forKey: reference.name)
216217
mapping[key] = getReferenceContext(reference)
217218
}
218219
}

‎Specs/TestSpec/generated/Swift/Sources/Models/SingleAnimal.swift

-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ public enum SingleAnimal: Codable, Equatable {
1313
let container = try decoder.container(keyedBy: StringCodingKey.self)
1414
let discriminator: String = try container.decode("type")
1515
switch discriminator {
16-
case "Cat":
17-
self = .cat(try Cat(from: decoder))
18-
case "Dog":
19-
self = .dog(try Dog(from: decoder))
2016
case "cat":
2117
self = .cat(try Cat(from: decoder))
2218
case "dog":

0 commit comments

Comments
 (0)