(propSchema: JSONSchema7, ctx: PyCodegenCtx)
| 1092 | } |
| 1093 | |
| 1094 | function isPyDurationProperty(propSchema: JSONSchema7, ctx: PyCodegenCtx): boolean { |
| 1095 | if (propSchema.$ref && typeof propSchema.$ref === "string") { |
| 1096 | const resolved = resolveSchema(propSchema, ctx.definitions); |
| 1097 | if (resolved && resolved !== propSchema) { |
| 1098 | return isPyDurationProperty(resolved, ctx); |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | if (propSchema.allOf && propSchema.allOf.length === 1 && typeof propSchema.allOf[0] === "object") { |
| 1103 | return isPyDurationProperty(propSchema.allOf[0] as JSONSchema7, ctx); |
| 1104 | } |
| 1105 | |
| 1106 | if (propSchema.anyOf) { |
| 1107 | const variants = (propSchema.anyOf as JSONSchema7[]) |
| 1108 | .filter((item) => typeof item === "object") |
| 1109 | .map( |
| 1110 | (item) => |
| 1111 | resolveSchema(item as JSONSchema7, ctx.definitions) ?? |
| 1112 | (item as JSONSchema7) |
| 1113 | ); |
| 1114 | const nonNull = variants.filter((item) => !isPyNullLikeSchema(item)); |
| 1115 | return nonNull.length === 1 && isPyDurationProperty(nonNull[0], ctx); |
| 1116 | } |
| 1117 | |
| 1118 | if (propSchema.format !== "duration") { |
| 1119 | return false; |
| 1120 | } |
| 1121 | |
| 1122 | const type = propSchema.type; |
| 1123 | if (type === "number" || type === "integer") { |
| 1124 | return true; |
| 1125 | } |
| 1126 | if (Array.isArray(type)) { |
| 1127 | const nonNullTypes = type.filter((value) => value !== "null"); |
| 1128 | return nonNullTypes.length === 1 && (nonNullTypes[0] === "number" || nonNullTypes[0] === "integer"); |
| 1129 | } |
| 1130 | |
| 1131 | return false; |
| 1132 | } |
| 1133 | |
| 1134 | function toPyFieldName(propName: string, propSchema: JSONSchema7, ctx: PyCodegenCtx): string { |
| 1135 | return toSnakeCase(isPyDurationProperty(propSchema, ctx) ? stripDurationMillisecondsSuffix(propName) : propName); |
no test coverage detected
searching dependent graphs…