From 6e0f18cbf304facea436e159a07ab737480f8162 Mon Sep 17 00:00:00 2001 From: Jan Chaloupecky Date: Thu, 31 Mar 2022 07:32:38 +0200 Subject: [PATCH] [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 --- CHANGELOG.md | 1 + Sources/SwagGenKit/CodeFormatter.swift | 1 + .../generated/Swift/Sources/Models/SingleAnimal.swift | 4 ---- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4110d052..b286663b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Fixed - Fixed compilation with Xcode 13 #282 @sroebert +- Fixed duplicated switch cases when using explicit mappings in oneOf discriminator #297 @JanC ### Changed - Improved `CodeFormatter` efficiency #272 @zntfdr diff --git a/Sources/SwagGenKit/CodeFormatter.swift b/Sources/SwagGenKit/CodeFormatter.swift index 27ee7d82a..141d04b91 100644 --- a/Sources/SwagGenKit/CodeFormatter.swift +++ b/Sources/SwagGenKit/CodeFormatter.swift @@ -213,6 +213,7 @@ public class CodeFormatter { for (key, value) in discriminatorMapping { // TODO: could reference another spec let reference = Reference(value) + mapping.removeValue(forKey: reference.name) mapping[key] = getReferenceContext(reference) } } diff --git a/Specs/TestSpec/generated/Swift/Sources/Models/SingleAnimal.swift b/Specs/TestSpec/generated/Swift/Sources/Models/SingleAnimal.swift index 739e20773..40df6913d 100644 --- a/Specs/TestSpec/generated/Swift/Sources/Models/SingleAnimal.swift +++ b/Specs/TestSpec/generated/Swift/Sources/Models/SingleAnimal.swift @@ -13,10 +13,6 @@ public enum SingleAnimal: Codable, Equatable { let container = try decoder.container(keyedBy: StringCodingKey.self) let discriminator: String = try container.decode("type") switch discriminator { - case "Cat": - self = .cat(try Cat(from: decoder)) - case "Dog": - self = .dog(try Dog(from: decoder)) case "cat": self = .cat(try Cat(from: decoder)) case "dog":