@@ -296,9 +296,24 @@ module SwaggerVisitors =
296
296
/// Returns the specified property when the object contains it.
297
297
/// Note: if the example object does not contain the property,
298
298
let extractPropertyFromObject propertyName ( objectType : NJsonSchema.JsonObjectType )
299
- ( exampleObj : JToken option ) =
299
+ ( exampleObj : JToken option )
300
+ ( parents : NJsonSchema.JsonSchema list option ) =
300
301
if ( String.IsNullOrWhiteSpace propertyName && objectType <> NJsonSchema.JsonObjectType.Array) then
301
- failwith ( sprintf " non-array should always have a property name. Property type: %A " objectType)
302
+ let message = sprintf " non-array should always have a property name. Property type: %A " objectType
303
+ let propertyInfo =
304
+ let parentPropertyNames =
305
+ match parents with
306
+ | None -> " "
307
+ | Some parents ->
308
+ parents
309
+ |> Seq.map ( fun p -> match p with
310
+ | :? NJsonSchema.JsonSchemaProperty as jp ->
311
+ jp.Name
312
+ | _ -> " " )
313
+ |> Seq.filter ( fun x -> not ( String.IsNullOrEmpty x))
314
+ |> String.concat " ."
315
+ sprintf " Property name: %A , parent properties: %s " propertyName parentPropertyNames
316
+ failwith ( sprintf " %s %s " message propertyInfo)
302
317
303
318
let pv , includeProperty =
304
319
match exampleObj with
@@ -327,7 +342,7 @@ module SwaggerVisitors =
327
342
pv, includeProperty
328
343
329
344
let extractPropertyFromArray ( exampleObj : JToken option ) =
330
- extractPropertyFromObject " " NJsonSchema.JsonObjectType.Array exampleObj
345
+ extractPropertyFromObject " " NJsonSchema.JsonObjectType.Array exampleObj None
331
346
332
347
let formatJTokenProperty primitiveType ( v : JToken ) =
333
348
// Use Formatting.None to avoid unintended string formatting, for example
@@ -616,7 +631,7 @@ module SwaggerVisitors =
616
631
|> Seq.choose ( fun item ->
617
632
let name = item.Key
618
633
// Just extract the property as a string.
619
- let exValue , includeProperty = GenerateGrammarElements.extractPropertyFromObject name NJsonSchema.JsonObjectType.String exampleValue
634
+ let exValue , includeProperty = GenerateGrammarElements.extractPropertyFromObject name NJsonSchema.JsonObjectType.String exampleValue ( Some parents )
620
635
if not includeProperty then None
621
636
else
622
637
Some ( processProperty ( name, item.Value)
0 commit comments