lib/common.js
function addModel(model, inputOptions) {
    var options = {
        schemaKey: schemaIds.schema,
        object: model,
        targetObject: state.common.models,
        displayName: 'Model',
        deleteNameFromCommon: true
    };
    applyDefaults(options, inputOptions);
    ensureObjectExists(options);
    cloneObject(options);
    delete options.object.$schema;
    delete options.object.$id;
    var definitions = options.object.definitions;
    delete options.object.definitions;
    applyValidation(options);
    ensureHasName(options);
    ensureNotAlreadyAdded(options);
    setObjectOnTarget(options);
    applyNameDeletion(options);
    if (!definitions) {
        return;
    }
    Object.keys(definitions).forEach(function (key) {
        var definition = _.cloneDeep(definitions[key]);
        definition.name = key;
        addModel(definition, inputOptions);
    });
}
function addModel(model, inputOptions) {
    var options = {
        schemaKey: schemaIds.schema,
        object: model,
        targetObject: state.common.models,
        displayName: 'Model',
        deleteNameFromCommon: true
    };
    applyDefaults(options, inputOptions);
    ensureObjectExists(options);
    cloneObject(options);
    delete options.object.$schema;
    delete options.object.$id;
    var definitions = options.object.definitions;
    delete options.object.definitions;
    applyValidation(options);
    ensureHasName(options);
    ensureNotAlreadyAdded(options);
    setObjectOnTarget(options);
    applyNameDeletion(options);
    if (!definitions) {
        return;
    }
    Object.keys(definitions).forEach(function (key) {
        var definition = _.cloneDeep(definitions[key]);
        definition.name = key;
        addModel(definition, inputOptions);
    });
}
function addModel ( model , inputOptions ) { var options = { schemaKey : schemaIds . schema , object : model , targetObject : state . common . models , displayName : 'Model' , deleteNameFromCommon : true } ; applyDefaults ( options , inputOptions ) ; ensureObjectExists ( options ) ; cloneObject ( options ) ; delete options . object . $schema ; delete options . object . $id ; var definitions = options . object . definitions ; delete options . object . definitions ; applyValidation ( options ) ; ensureHasName ( options ) ; ensureNotAlreadyAdded ( options ) ; setObjectOnTarget ( options ) ; applyNameDeletion ( options ) ; if ( ! definitions ) { return ; } Object . keys ( definitions ) . forEach ( function ( key ) { var definition = _ . cloneDeep ( definitions [ key ] ) ; definition . name = key ; addModel ( definition , inputOptions ) ; } ) ; }
Adds a common model for later use.
@param {object} model The schema for the model object to add. Should be a valid [Schema](http://swagger.io/specification/#schemaObject) object.
@param {AddCommonItemOptions} [inputOptions] - Options to apply when adding the provided item.
@returns {void}
@example
var swagger = require('swagger-spec-express');
swagger.common.addModel({
"name": "serverError",
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
});
//...
router.get('/', function (req, res) {
//...
}).describe({
//...
responses: {
"500": {
//...
model: "serverError"
}
}
//...
});
Adds a common model for later use .