[generate] support extending the rest-api specs via merge+concat
This commit is contained in:
@ -24,6 +24,7 @@ module.exports = function (branch, done) {
|
|||||||
var version = Version.fromBranch(branch);
|
var version = Version.fromBranch(branch);
|
||||||
var overrides = version.mergeOpts(require('./overrides'), {
|
var overrides = version.mergeOpts(require('./overrides'), {
|
||||||
aliases: {},
|
aliases: {},
|
||||||
|
mergeConcatParams: {},
|
||||||
paramAsBody: {},
|
paramAsBody: {},
|
||||||
clientActionModifier: false
|
clientActionModifier: false
|
||||||
});
|
});
|
||||||
@ -195,13 +196,23 @@ module.exports = function (branch, done) {
|
|||||||
def.url.params = _.transform(def.url.params, transformParamKeys, {});
|
def.url.params = _.transform(def.url.params, transformParamKeys, {});
|
||||||
def.url.parts = _.transform(def.url.parts, transformParamKeys, {});
|
def.url.parts = _.transform(def.url.parts, transformParamKeys, {});
|
||||||
|
|
||||||
_.values(def.url.params).concat(_.values(def.url.parts)).forEach(param => {
|
var allParams = _.extend({}, def.url.params, def.url.parts);
|
||||||
if (param.options && param.options.some(opt => typeof opt !== 'string')) {
|
_.forOwn(allParams, (paramSpec, paramName) => {
|
||||||
throw new Error(`${def.name} has options that are not strings...`)
|
const toMerge = _.get(overrides, ['mergeConcatParams', name, paramName])
|
||||||
|
if (toMerge) {
|
||||||
|
_.mergeWith(paramSpec, toMerge, (dest, src) => {
|
||||||
|
if (_.isArray(dest) && _.isArray(src)) {
|
||||||
|
return dest.concat(src)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (paramSpec.options) {
|
||||||
|
const invalidOpts = paramSpec.options.some(opt => typeof opt !== 'string')
|
||||||
|
if (invalidOpts) throw new Error(`${name} has options that are not strings...`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
var allParams = _.extend({}, def.url.params, def.url.parts);
|
|
||||||
var spec = {
|
var spec = {
|
||||||
name: name,
|
name: name,
|
||||||
methods: _.map(def.methods, function (m) { return m.toUpperCase(); }),
|
methods: _.map(def.methods, function (m) { return m.toUpperCase(); }),
|
||||||
|
|||||||
Reference in New Issue
Block a user