@@ -43,14 +43,16 @@ final class SchemaTests: XCTestCase {
4343
4444 func testEncodeSchema_string_allOptions( ) throws {
4545 let description = " Timestamp of the event. "
46+ let title = " Event Timestamp "
4647 let format = Schema . StringFormat. custom ( " date-time " )
47- let schema = Schema . string ( description: description, nullable: true , format: format)
48+ let schema = Schema . string ( description: description, title : title , nullable: true , format: format)
4849
4950 let jsonData = try encoder. encode ( schema)
5051
5152 let json = try XCTUnwrap ( String ( data: jsonData, encoding: . utf8) )
5253 XCTAssertEqual ( json, """
5354 {
55+ " title " : " \( title) " ,
5456 " description " : " \( description) " ,
5557 " format " : " date-time " ,
5658 " nullable " : true,
@@ -85,13 +87,15 @@ final class SchemaTests: XCTestCase {
8587 func testEncodeSchema_enumeration_allOptions( ) throws {
8688 let values = [ " NORTH " , " SOUTH " , " EAST " , " WEST " ]
8789 let description = " Compass directions. "
88- let schema = Schema . enumeration ( values: values, description: description, nullable: true )
90+ let title = " Directions "
91+ let schema = Schema . enumeration ( values: values, description: description, title: title, nullable: true )
8992
9093 let jsonData = try encoder. encode ( schema)
9194
9295 let json = try XCTUnwrap ( String ( data: jsonData, encoding: . utf8) )
9396 XCTAssertEqual ( json, """
9497 {
98+ " title " : " \( title) " ,
9599 " description " : " \( description) " ,
96100 " enum " : [
97101 " NORTH " ,
@@ -125,10 +129,12 @@ final class SchemaTests: XCTestCase {
125129
126130 func testEncodeSchema_float_allOptions( ) throws {
127131 let description = " Temperature in Celsius. "
132+ let title = " Temperature (°C) "
128133 let minimum : Float = - 40.25
129134 let maximum : Float = 50.5
130135 let schema = Schema . float (
131136 description: description,
137+ title: title,
132138 nullable: true ,
133139 minimum: minimum,
134140 maximum: maximum
@@ -139,6 +145,7 @@ final class SchemaTests: XCTestCase {
139145 let json = try XCTUnwrap ( String ( data: jsonData, encoding: . utf8) )
140146 XCTAssertEqual ( json, """
141147 {
148+ " title " : " \( title) " ,
142149 " description " : " \( description) " ,
143150 " format " : " float " ,
144151 " maximum " : \( maximum) ,
@@ -167,10 +174,12 @@ final class SchemaTests: XCTestCase {
167174
168175 func testEncodeSchema_double_allOptions( ) throws {
169176 let description = " Account balance. "
177+ let title = " Balance "
170178 let minimum = 0.01
171179 let maximum = 1_000_000.99
172180 let schema = Schema . double (
173181 description: description,
182+ title: title,
174183 nullable: true ,
175184 minimum: minimum,
176185 maximum: maximum
@@ -181,6 +190,7 @@ final class SchemaTests: XCTestCase {
181190 let json = try XCTUnwrap ( String ( data: jsonData, encoding: . utf8) )
182191 XCTAssertEqual ( json, """
183192 {
193+ " title " : " \( title) " ,
184194 " description " : " \( description) " ,
185195 " maximum " : \( maximum) ,
186196 " minimum " : \( minimum) ,
@@ -208,11 +218,13 @@ final class SchemaTests: XCTestCase {
208218
209219 func testEncodeSchema_integer_allOptions( ) throws {
210220 let description = " User age. "
221+ let title = " Age "
211222 let minimum = 0
212223 let maximum = 120
213224 let format = Schema . IntegerFormat. int32
214225 let schema = Schema . integer (
215226 description: description,
227+ title: title,
216228 nullable: true ,
217229 format: format,
218230 minimum: minimum,
@@ -224,6 +236,7 @@ final class SchemaTests: XCTestCase {
224236 let json = try XCTUnwrap ( String ( data: jsonData, encoding: . utf8) )
225237 XCTAssertEqual ( json, """
226238 {
239+ " title " : " \( title) " ,
227240 " description " : " \( description) " ,
228241 " format " : " int32 " ,
229242 " maximum " : \( maximum) ,
@@ -252,13 +265,15 @@ final class SchemaTests: XCTestCase {
252265
253266 func testEncodeSchema_boolean_allOptions( ) throws {
254267 let description = " Is the user an administrator? "
255- let schema = Schema . boolean ( description: description, nullable: true )
268+ let title = " Administrator Check "
269+ let schema = Schema . boolean ( description: description, title: title, nullable: true )
256270
257271 let jsonData = try encoder. encode ( schema)
258272
259273 let json = try XCTUnwrap ( String ( data: jsonData, encoding: . utf8) )
260274 XCTAssertEqual ( json, """
261275 {
276+ " title " : " \( title) " ,
262277 " description " : " \( description) " ,
263278 " nullable " : true,
264279 " type " : " BOOLEAN "
@@ -290,11 +305,13 @@ final class SchemaTests: XCTestCase {
290305 func testEncodeSchema_array_allOptions( ) throws {
291306 let itemsSchema = Schema . integer ( format: . int64)
292307 let description = " List of product IDs. "
308+ let title = " Product IDs "
293309 let minItems = 1
294310 let maxItems = 10
295311 let schema = Schema . array (
296312 items: itemsSchema,
297313 description: description,
314+ title: title,
298315 nullable: true ,
299316 minItems: minItems,
300317 maxItems: maxItems
@@ -305,6 +322,7 @@ final class SchemaTests: XCTestCase {
305322 let json = try XCTUnwrap ( String ( data: jsonData, encoding: . utf8) )
306323 XCTAssertEqual ( json, """
307324 {
325+ " title " : " \( title) " ,
308326 " description " : " \( description) " ,
309327 " items " : {
310328 " format " : " int64 " ,
0 commit comments