You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// iscConfig.pkl
amends "ApplicationConfig.pkl"
config {
["dev"] = "Imaginary Service Company (ISC) configuration"
}
The swift generated type is
// Code generated from Pkl module `ApplicationConfig`. DO NOT EDIT.
import PklSwift
public enum ApplicationConfig {}
extension ApplicationConfig {
public enum Environment: String, CaseIterable, Decodable, Hashable {
case dev = "dev"
case prod = "prod"
case qa = "qa"
}
public struct Module: PklRegisteredType, Decodable, Hashable {
public static let registeredIdentifier: String = "ApplicationConfig"
public var config: [Environment: String]
public init(config: [Environment: String]) {
self.config = config
}
}
/// Load the Pkl module at the given source and evaluate it into `ApplicationConfig.Module`.
///
/// - Parameter source: The source of the Pkl module.
public static func loadFrom(source: ModuleSource) async throws -> ApplicationConfig.Module {
try await PklSwift.withEvaluator { evaluator in
try await loadFrom(evaluator: evaluator, source: source)
}
}
/// Load the Pkl module at the given source and evaluate it with the given evaluator into
/// `ApplicationConfig.Module`.
///
/// - Parameter evaluator: The evaluator to use for evaluation.
/// - Parameter source: The module to evaluate.
public static func loadFrom(
evaluator: PklSwift.Evaluator,
source: PklSwift.ModuleSource
) async throws -> ApplicationConfig.Module {
try await evaluator.evaluateModule(source: source, as: Module.self)
}
}
Now if we try to parse this in Swift via
import PklSwift
let filepath = ...
let appConfig = try await ApplicationConfig.loadFrom(source: .path(filepath))
we get the error:
Error: dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected either list, listing, or set, but got mapping", underlyingError: nil))
The exception seems to be thrown from _PklDecoder in PklUnkeyedDecodingContainer.swift.
I’m using Pkl 0.27.2 and pkl-gen-swift 0.4.1
Thank you in advance for having a look at this!
The text was updated successfully, but these errors were encountered:
It is currently not possible to parse a Pkl module in Swift which has a Mapping property with enum as keys. Example: consider the following Pkl module
The swift generated type is
Now if we try to parse this in Swift via
we get the error:
Error: dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected either list, listing, or set, but got mapping", underlyingError: nil))
The exception seems to be thrown from
_PklDecoder
inPklUnkeyedDecodingContainer.swift
.I’m using Pkl 0.27.2 and pkl-gen-swift 0.4.1
Thank you in advance for having a look at this!
The text was updated successfully, but these errors were encountered: