* @brief Lower SchemaProp into the JSON object emitted under "properties". */
| 138 | * @brief Lower SchemaProp into the JSON object emitted under "properties". |
| 139 | */ |
| 140 | [[nodiscard]] inline QJsonObject schemaPropToJson(const SchemaProp& p) |
| 141 | { |
| 142 | QJsonObject prop; |
| 143 | |
| 144 | if (p.type.contains(QLatin1Char('|'))) { |
| 145 | QJsonArray types; |
| 146 | for (const auto& part : p.type.split(QLatin1Char('|'), Qt::SkipEmptyParts)) |
| 147 | types.append(part.trimmed()); |
| 148 | |
| 149 | prop.insert(QStringLiteral("type"), types); |
| 150 | } else { |
| 151 | prop.insert(QStringLiteral("type"), p.type); |
| 152 | } |
| 153 | |
| 154 | prop.insert(QStringLiteral("description"), p.description); |
| 155 | if (p.binary) |
| 156 | prop.insert(QStringLiteral("binary"), true); |
| 157 | |
| 158 | if (!p.enumValues.isEmpty()) |
| 159 | prop.insert(QStringLiteral("enum"), p.enumValues); |
| 160 | |
| 161 | if (!p.minimum.isUndefined() && !p.minimum.isNull()) |
| 162 | prop.insert(QStringLiteral("minimum"), p.minimum); |
| 163 | |
| 164 | if (!p.maximum.isUndefined() && !p.maximum.isNull()) |
| 165 | prop.insert(QStringLiteral("maximum"), p.maximum); |
| 166 | |
| 167 | if (!p.defaultValue.isUndefined() && !p.defaultValue.isNull()) |
| 168 | prop.insert(QStringLiteral("default"), p.defaultValue); |
| 169 | |
| 170 | if (p.type == QStringLiteral("array")) { |
| 171 | if (!p.itemsSchema.isEmpty()) { |
| 172 | prop.insert(QStringLiteral("items"), p.itemsSchema); |
| 173 | } else { |
| 174 | QJsonObject items; |
| 175 | items.insert(QStringLiteral("type"), |
| 176 | p.itemsType.isEmpty() ? QStringLiteral("string") : p.itemsType); |
| 177 | prop.insert(QStringLiteral("items"), items); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | return prop; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * @brief Build a JSON-Schema object from a flat list of properties. |
no test coverage detected