* Returns true when a TimeSpan-typed property needs a [JsonConverter] attribute. * * NOTE: The runtime schema generally uses `format: "duration"` on numeric (integer/number) * fields to mean "a duration value expressed in milliseconds". This differs from the JSON * Schema spec, where `format: "d
(schema: JSONSchema7)
| 466 | * 8601 strings. Seconds-suffixed fields stay numeric because their wire value is seconds. |
| 467 | */ |
| 468 | function isDurationProperty(schema: JSONSchema7): boolean { |
| 469 | const nullableInner = getNullableInner(schema); |
| 470 | if (nullableInner) { |
| 471 | return isDurationProperty(nullableInner); |
| 472 | } |
| 473 | |
| 474 | if (schema.format === "duration") { |
| 475 | const t = schema.type; |
| 476 | if (t === "number" || t === "integer") return true; |
| 477 | if (Array.isArray(t)) { |
| 478 | const nonNull = (t as string[]).filter((x) => x !== "null"); |
| 479 | if (nonNull.length === 1 && (nonNull[0] === "number" || nonNull[0] === "integer")) return true; |
| 480 | } |
| 481 | } |
| 482 | return false; |
| 483 | } |
| 484 | |
| 485 | function isMillisecondsDurationProperty(propName: string | undefined, schema: JSONSchema7): boolean { |
| 486 | return isDurationProperty(schema) && !isSecondsDurationPropertyName(propName); |
no test coverage detected
searching dependent graphs…