* Copy pluginLocations schema extensions from the extension plugins to the appropriate model schemas * @returns {Schemas} * @example * courseModelSchema.properties._assessment * articleModelSchema.properties._trickle * blockModelSchema.properties._trickle
()
| 131 | * blockModelSchema.properties._trickle |
| 132 | */ |
| 133 | generateModelExtensions() { |
| 134 | const extensionSchemas = this.schemas.filter(schema => schema instanceof ExtensionSchema); |
| 135 | extensionSchemas.forEach(schema => { |
| 136 | const extensionParts = schema.getModelExtensionParts(); |
| 137 | if (!extensionParts) { |
| 138 | return; |
| 139 | } |
| 140 | for (const modelName in extensionParts) { |
| 141 | const extensionPart = extensionParts[modelName]; |
| 142 | /** |
| 143 | * Check if the sub-schema part has any defined properties. |
| 144 | * A lot of extension schemas have empty objects with no properties. |
| 145 | */ |
| 146 | if (!extensionPart.properties) { |
| 147 | continue; |
| 148 | } |
| 149 | const modelSchema = this.getModelSchemaByName(modelName); |
| 150 | if (!modelSchema) { |
| 151 | const err = new Error(`Cannot add extensions to model which doesn't exits ${modelName}`); |
| 152 | err.number = 10012; |
| 153 | throw err; |
| 154 | } |
| 155 | /** |
| 156 | * Notice that the targetAttribute is not used here, we allow the extension schema |
| 157 | * to define its own _[targetAttribute] to extend any core model. |
| 158 | */ |
| 159 | modelSchema.json.properties = _.merge({}, modelSchema.json.properties, extensionPart.properties); |
| 160 | } |
| 161 | }); |
| 162 | return this; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * @param {string} schemaName |
no test coverage detected