(propName, propDef, requiredSet)
| 83 | |
| 84 | // Extract property metadata from a schema property object. |
| 85 | function extractPropertyInfo(propName, propDef, requiredSet) { |
| 86 | const info = { |
| 87 | name: propName, |
| 88 | type: "object", |
| 89 | }; |
| 90 | |
| 91 | if (requiredSet.has(propName)) { |
| 92 | info.required = true; |
| 93 | } |
| 94 | |
| 95 | if (!propDef) { |
| 96 | return info; |
| 97 | } |
| 98 | |
| 99 | if (Array.isArray(propDef.oneOf)) { |
| 100 | const nonNullBranches = propDef.oneOf.filter( |
| 101 | (branch) => branch && branch.type !== "null" |
| 102 | ); |
| 103 | if (nonNullBranches.length === 1) { |
| 104 | const unionDef = { ...nonNullBranches[0] }; |
| 105 | if (propDef.description && !unionDef.description) { |
| 106 | unionDef.description = propDef.description; |
| 107 | } |
| 108 | return extractPropertyInfo(propName, unionDef, requiredSet); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | if (propDef.$ref) { |
| 113 | info.type = refName(propDef.$ref); |
| 114 | if (propDef.description) info.description = propDef.description; |
| 115 | return info; |
| 116 | } |
| 117 | |
| 118 | const rawType = Array.isArray(propDef.type) |
| 119 | ? propDef.type.find((t) => t !== "null") |
| 120 | : propDef.type; |
| 121 | if (rawType) { |
| 122 | info.type = rawType; |
| 123 | } |
| 124 | if (propDef.format) { |
| 125 | info.format = propDef.format; |
| 126 | } |
| 127 | if (propDef.description) { |
| 128 | info.description = propDef.description; |
| 129 | } |
| 130 | if (info.type === "array" && propDef.items) { |
| 131 | info.items = extractPropertyInfo("item", propDef.items, new Set()); |
| 132 | info.type = `array<${info.items.type}>`; |
| 133 | } |
| 134 | if ( |
| 135 | info.type === "object" && |
| 136 | propDef.additionalProperties && |
| 137 | typeof propDef.additionalProperties === "object" |
| 138 | ) { |
| 139 | info.additionalProperties = extractPropertyInfo( |
| 140 | "value", |
| 141 | propDef.additionalProperties, |
| 142 | new Set() |
no test coverage detected