diff --git a/spec/schemas.spec.js b/spec/schemas.spec.js index e2d1955c08..568dd2b866 100644 --- a/spec/schemas.spec.js +++ b/spec/schemas.spec.js @@ -326,6 +326,35 @@ describe('schemas', () => { }); }); + it('responds with all fields when getting incomplete schema', done => { + config.database.schemaCollection().then((schema) => { + return schema.addSchema('_User'); + }).then(() => { + request.get({ + url: 'http://localhost:8378/1/schemas/_User', + headers: masterKeyHeaders, + json: true + }, (error, response, body) => { + expect(body).toEqual({ + className: '_User', + fields: { + objectId: {type: 'String'}, + updatedAt: {type: 'Date'}, + createdAt: {type: 'Date'}, + username: {type: 'String'}, + password: {type: 'String'}, + authData: {type: 'Object'}, + email: {type: 'String'}, + emailVerified: {type: 'Boolean'}, + ACL: {type: 'ACL'} + }, + classLevelPermissions: defaultClassLevelPermissions + }); + done(); + }); + }) + }); + it('lets you specify class name in both places', done => { request.post({ url: 'http://localhost:8378/1/schemas/NewClass', diff --git a/src/Routers/SchemasRouter.js b/src/Routers/SchemasRouter.js index 3babd66828..23ad4b56f8 100644 --- a/src/Routers/SchemasRouter.js +++ b/src/Routers/SchemasRouter.js @@ -14,9 +14,20 @@ function classNameMismatchResponse(bodyClass, pathClass) { ); } +function injectDefaultSchema(schema) { + let defaultSchema = Schema.defaultColumns[schema.className]; + if (defaultSchema) { + Object.keys(defaultSchema).forEach((key) => { + schema.fields[key] = defaultSchema[key]; + }); + } + return schema; +} + function getAllSchemas(req) { return req.config.database.schemaCollection() .then(collection => collection.getAllSchemas()) + .then(schemas => schemas.map(injectDefaultSchema)) .then(schemas => ({ response: { results: schemas } })); } @@ -24,6 +35,7 @@ function getOneSchema(req) { const className = req.params.className; return req.config.database.schemaCollection() .then(collection => collection.findSchema(className)) + .then(injectDefaultSchema) .then(schema => ({ response: schema })) .catch(error => { if (error === undefined) { diff --git a/src/Schema.js b/src/Schema.js index 8311ef482e..f2f188cb57 100644 --- a/src/Schema.js +++ b/src/Schema.js @@ -848,4 +848,5 @@ export { schemaAPITypeToMongoFieldType, buildMergedSchemaObject, systemClasses, + defaultColumns, };