@@ -114,7 +114,27 @@ public protocol CustomCoder: Sendable {
114
114
/// - Returns: A value of the requested type.
115
115
/// - Throws: An error if decoding fails.
116
116
func customDecode< T: Decodable > ( _ type: T . Type , from data: Data ) throws -> T
117
+ }
118
+
119
+ /// The options that control the encoded JSON data.
120
+ public struct JSONEncodingOptions : OptionSet , Sendable {
121
+
122
+ /// The format's default value.
123
+ public let rawValue : UInt
124
+
125
+ /// Creates a JSONEncodingOptions value with the given raw value.
126
+ public init ( rawValue: UInt ) { self . rawValue = rawValue }
117
127
128
+ /// Include newlines and indentation to make the output more human-readable.
129
+ public static let prettyPrinted : JSONEncodingOptions = . init( rawValue: 1 << 0 )
130
+
131
+ /// Serialize JSON objects with field keys sorted in lexicographic order.
132
+ public static let sortedKeys : JSONEncodingOptions = . init( rawValue: 1 << 1 )
133
+
134
+ /// Omit escaping forward slashes with backslashes.
135
+ ///
136
+ /// Important: Only use this option when the output is not embedded in HTML/XML.
137
+ public static let withoutEscapingSlashes : JSONEncodingOptions = . init( rawValue: 1 << 2 )
118
138
}
119
139
120
140
/// A set of configuration values used by the generated client and server types.
@@ -123,6 +143,9 @@ public struct Configuration: Sendable {
123
143
/// The transcoder used when converting between date and string values.
124
144
public var dateTranscoder : any DateTranscoder
125
145
146
+ /// The options for the underlying JSON encoder.
147
+ public var jsonEncodingOptions : JSONEncodingOptions
148
+
126
149
/// The generator to use when creating mutlipart bodies.
127
150
public var multipartBoundaryGenerator : any MultipartBoundaryGenerator
128
151
@@ -134,14 +157,17 @@ public struct Configuration: Sendable {
134
157
/// - Parameters:
135
158
/// - dateTranscoder: The transcoder to use when converting between date
136
159
/// and string values.
160
+ /// - jsonEncodingOptions: The options for the underlying JSON encoder.
137
161
/// - multipartBoundaryGenerator: The generator to use when creating mutlipart bodies.
138
162
/// - xmlCoder: Custom XML coder for encoding and decoding xml bodies. Only required when using XML body payloads.
139
163
public init (
140
164
dateTranscoder: any DateTranscoder = . iso8601,
165
+ jsonEncodingOptions: JSONEncodingOptions = [ . sortedKeys, . prettyPrinted] ,
141
166
multipartBoundaryGenerator: any MultipartBoundaryGenerator = . random,
142
167
xmlCoder: ( any CustomCoder ) ? = nil
143
168
) {
144
169
self . dateTranscoder = dateTranscoder
170
+ self . jsonEncodingOptions = jsonEncodingOptions
145
171
self . multipartBoundaryGenerator = multipartBoundaryGenerator
146
172
self . xmlCoder = xmlCoder
147
173
}
0 commit comments