back out changes of id to URI

This commit is contained in:
Ying Tang 2015-04-06 19:57:57 -07:00
parent b9001a3130
commit 3f8c3b7c04
3 changed files with 7 additions and 10 deletions

View File

@ -31,16 +31,15 @@ var modelHelper = module.exports = {
}
};
var convertTypeTo$Ref = function convertTypeTo$Ref(prop, modelUri){
var convertTypeTo$Ref = function convertTypeTo$Ref(prop){
if (prop.type && TYPES_PRIMITIVE.indexOf(prop.type) === -1 ){
prop.$ref = modelUri + '/definitions/' + prop.type;
prop.$ref = prop.type;
delete prop.type;
}
};
var def = modelClass.definition;
var name = def.name;
var modelUri = 'https://strongloop.com/loopback/' + name + '#';
var out = definitions || {};
if (out[name]) {
// The model is already included
@ -82,7 +81,7 @@ var modelHelper = module.exports = {
processType(modelClass.app, prop.type, referencedModels);
if (prop.items) {
processType(modelClass.app, prop.items.type, referencedModels);
convertTypeTo$Ref(prop.items, modelUri);
convertTypeTo$Ref(prop.items);
}
// Required props sit in a per-model array.
@ -93,7 +92,7 @@ var modelHelper = module.exports = {
// Change mismatched keys.
prop = translateDataTypeKeys(prop);
convertTypeTo$Ref(prop, modelUri);
convertTypeTo$Ref(prop);
delete prop.required;
delete prop.id;
@ -122,8 +121,7 @@ var modelHelper = module.exports = {
});
out[name] = {
id: modelUri,
$schema: 'http://json-schema.org/draft-04/schema#',
id: name,
properties: properties,
required: required
};

View File

@ -15,7 +15,6 @@ describe('model-helper', function() {
buf: Buffer // {type: 'string', format: 'byte'}
});
var props = def.properties;
console.log(props.str);
expect(props.str).to.eql({ type: 'string' });
expect(props.num).to.eql({ type: 'number', format: 'double' });
expect(props.date).eql({ type: 'string', format: 'date' });
@ -119,7 +118,7 @@ describe('model-helper', function() {
address: Address
});
var prop = def.properties.address;
expect(prop).to.eql({ $ref: 'https://strongloop.com/loopback/testModel#/definitions/Address' });
expect(prop).to.eql({ $ref: 'Address' });
});
});

View File

@ -91,7 +91,7 @@ describe('swagger definition', function() {
getReq.end(function(err, res) {
if (err) return done(err);
var data = res.body.models.product;
expect(data.id).to.equal('https://strongloop.com/loopback/product#');
expect(data.id).to.equal('product');
expect(data.required.sort()).to.eql(['aNum', 'foo'].sort());
expect(data.properties.foo.type).to.equal('string');
expect(data.properties.bar.type).to.equal('string');